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.
Requests are routed exclusively to Gemini models, with persistent conversations managed by the 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
Select one of the current Gemini models below and pass its exact ID in the model parameter.
gemini-3.5-flash-lite
The fastest model for short answers and lightweight tasks.
gemini-3.6-flash
The balanced Gemini model for comprehensive everyday assistance.
gemini-3.1-pro
Advanced mathematics, programming, and complex reasoning.
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
import requests
response = requests.post(
"https://trienkhai.io.vn/v1/chat/completions",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"model": "gemini-3.1-pro",
"messages": [{"role": "user", "content": "Hello!"}],
},
timeout=500,
)
response.raise_for_status()
print(response.json()["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
}
}
Conversation API
Use conversations when you want Gemini to continue the same underlying chat instead of creating a fresh Gemini chat for every request.
/v1/chats
Create an empty conversation and receive a conversation_id.
/v1/chats
List conversations owned by the current API key.
/v1/chats/{conversation_id}
Inspect a conversation and its stored Gemini metadata.
/v1/chats/{conversation_id}
Delete gateway metadata for a conversation.
Recommended Flow
# First request: no conversation_id, gateway creates a new Gemini chat.
curl https://trienkhai.io.vn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gemini-3.1-pro",
"messages": [
{"role": "user", "content": "My name is Hung."}
]
}'
# Use conversation_id from the first response to continue the same Gemini chat.
curl https://trienkhai.io.vn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gemini-3.1-pro",
"conversation_id": "conv_xxx",
"messages": [
{"role": "user", "content": "What is my name?"}
]
}'
Conversation Response Fields
{
"id": "chatcmpl-gemini",
"object": "chat.completion",
"model": "gemini-3.1-pro",
"conversation_id": "conv_xxx",
"gemini_metadata": ["gemini_chat_id", "reply_id", "candidate_id"],
"choices": [
{
"message": {
"role": "assistant",
"content": "Your name is Hung."
}
}
]
}
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"
}