POST
/
v1
/
chat
/
completions
Chat Compatible Format
curl --request POST \
  --url https://api.example.com/v1/chat/completions \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "temperature": 123,
  "max_tokens": 123,
  "top_p": 123,
  "stream": true,
  "stop": {}
}
'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {}
  ],
  "usage": {}
}
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

model
string
required
The Gemini model ID to use. For example: gemini-2.0-flash, gemini-2.5-pro, gemini-3-pro-preview.
messages
array
required
A list of messages comprising the conversation. Each message contains role and content fields.
temperature
number
default:"1"
Sampling temperature between 0 and 2. Higher values make output more random, lower values make it more focused.
max_tokens
integer
Maximum number of tokens to generate.
top_p
number
default:"1"
Nucleus sampling parameter.
stream
boolean
default:"false"
Whether to stream responses.
stop
string | array
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

id
string
Unique identifier for the completion.
object
string
Object type, which is chat.completion.
created
integer
Unix timestamp of when the completion was created.
model
string
The model used.
choices
array
List of completion choices.
usage
object
Usage statistics for the request.

Parameters

ParameterTypeRequiredDefaultDescription
modelstringYes-Gemini model ID
messagesarrayYes-List of messages in the conversation
temperaturenumberNo1Sampling temperature (0-2)
max_tokensintegerNo-Maximum tokens to generate
top_pnumberNo1Nucleus sampling parameter
streambooleanNofalseEnable streaming responses
stopstring/arrayNonullStop sequences

Available Models

  • gemini-2.0-flash
  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-3-pro-preview