Call Google Gemini models using the standard OpenAI Chat Completions API format.
Overview
The Chat Compatible Format interface allows you to call Google Gemini models using the standard OpenAI Chat Completions API format. This makes migrating from OpenAI to Gemini much simpler.
Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Request Parameters
The Gemini model ID to use. For example: gemini-2.0-flash, gemini-2.5-pro, gemini-3-pro-preview.
A list of messages comprising the conversation. Each message contains role and content fields.
Sampling temperature between 0 and 2. Higher values make output more random, lower values make it more focused.
Maximum number of tokens to generate.
Nucleus sampling parameter.
Whether to stream responses.
Up to 4 sequences where the API will stop generating further tokens.
Request Example
curl -X POST https://api.example.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"temperature": 0.7,
"max_tokens": 1000
}'
Response Example
{
"id": "chatcmpl-gemini-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gemini-2.5-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"total_tokens": 30
}
}
Response Fields
Unique identifier for the completion.
Object type, which is chat.completion.
Unix timestamp of when the completion was created.
List of completion choices.
Usage statistics for the request.
Parameters
| Parameter | Type | Required | Default | Description |
|---|
| model | string | Yes | - | Gemini model ID |
| messages | array | Yes | - | List of messages in the conversation |
| temperature | number | No | 1 | Sampling temperature (0-2) |
| max_tokens | integer | No | - | Maximum tokens to generate |
| top_p | number | No | 1 | Nucleus sampling parameter |
| stream | boolean | No | false | Enable streaming responses |
| stop | string/array | No | null | Stop sequences |
Available Models
gemini-2.0-flash
gemini-2.5-pro
gemini-2.5-flash
gemini-3-pro-preview