Skip to main content

Quickstart

Prerequisites

  1. Create a RockAPI Account or Sign in.
  2. Navigate to the API key page and create a new API Key.
  3. Python Version Requirements:
    • OpenAI: Python 3.7.1+
    • Claude: Python 3.7+ or TypeScript 4.5+
    • Gemini: Python 3.9+

SDK Installation

Choose your preferred AI service:

OpenAI

Install the OpenAI Python Library:

pip install --upgrade openai

Claude

Install the Claude Python Library:

pip install anthropic

Gemini

Install the Gemini Python Library:

pip install -q -U google-generativeai

Authentication

OpenAI

from openai import OpenAI

client = OpenAI(
api_key='$ROCKAPI_API_KEY',
base_url='https://api.rockapi.ru/openai/v1'
)

Claude

import anthropic

client = anthropic.Anthropic(
api_key='$ROCKAPI_API_KEY',
base_url='https://api.rockapi.ru/anthropic'
)

Gemini

import google.generativeai as genai
from google.api_core.client_options import ClientOptions

genai.configure(
api_key='$ROCKAPI_API_KEY',
transport='rest',
client_options=ClientOptions(api_endpoint='https://api.rockapi.ru/google-ai-studio')
)

Making Your First Request

OpenAI

from openai import OpenAI

client = OpenAI(
api_key='$ROCKAPI_API_KEY',
base_url='https://api.rockapi.ru/openai/v1'
)

response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)

print(response.choices[0].message.content)

Claude

import anthropic

client = anthropic.Anthropic(
api_key='$ROCKAPI_API_KEY',
base_url='https://api.rockapi.ru/anthropic'
)

message = client.messages.create(
model='claude-3-opus-20240229',
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude"}
]
)

print(message.content)

Gemini

import google.generativeai as genai
from google.api_core.client_options import ClientOptions

genai.configure(
api_key='$ROCKAPI_API_KEY',
transport='rest',
client_options=ClientOptions(api_endpoint='https://api.rockapi.ru/google-ai-studio')
)

model = genai.GenerativeModel('gemini-1.5-pro')
response = model.generate_content("Write a story about an AI and magic")
print(response.text)

Next Steps

OpenAI

Other Endpoints

Claude

Explore more with the Anthropic API:

For further details, visit the Anthropic API Reference.

Gemini

To learn more about working with the Gemini API, refer to the getting started tutorial for your preferred language. Explore the comprehensive guides and capabilities offered by the Gemini API.