API Reference
The Gemini SaaS API is organized around REST. Our API has predictable resource-oriented URLs, accepts form-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
Crucially, our API is 100% compatible with OpenAI's format. You can use official OpenAI SDKs to interact with our Gateway.
Authentication
The API uses API keys to authenticate requests. You can view and manage your API keys in the Admin Dashboard. Your API keys carry many privileges, so be sure to keep them secure!
Bearer Token
All API requests should include your API key in an Authorization HTTP header as follows:
Authorization: Bearer YOUR_API_KEY
Supported Models
We dynamically route your requests to the most appropriate backend model. Pass these exact strings into the model parameter.
gemini-3.5-flash
The standard, highly versatile model for general text tasks and rapid assistance.
gemini-3.1-pro
Advanced reasoning, coding, and mathematical capabilities.
gemini-3.1-flash-lite
The fastest and most lightweight model for simple extraction and quick queries.
Chat Completions
/v1/chat/completions
Creates a model response for the given chat conversation.
Request Body
ID of the model to use (e.g., gemini-3.1-pro).
A list of messages comprising the conversation so far. Each object must have a role (system, user, assistant) and content.
Whether to stream back partial progress. (Currently defaults to false/synchronous).
Example Request
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8000/v1/",
api_key="YOUR_API_KEY"
)
response = client.chat.completions.create(
model="gemini-3.1-pro",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)
Response Format
{
"id": "chatcmpl-gemini",
"object": "chat.completion",
"created": 1718291039,
"model": "gemini-3.1-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hi there! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}
Error Codes
Our API uses conventional HTTP response codes to indicate the success or failure of an API request. Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted, or you ran out of credits).
| HTTP Code | Description | Meaning / Resolution |
|---|---|---|
| 400 | Bad Request | The request was unacceptable, often due to missing a required parameter (like empty messages). |
| 401 / 403 | Unauthorized | No valid API key provided, or your API key is deactivated. Check your Authorization header. |
| 500 | Server Error | Something went wrong on our end (e.g. all backend Gemini accounts are overloaded). The system will Auto-Retry before throwing this error. |
| 503 | Service Unavailable | No active Gemini accounts are currently available in the system pool. |
Example Error Response
{
"detail": "Unauthorized"
}