Gemini Chat
Google Gemini models support both OpenAI-compatible format and Gemini native format.
Method 1: OpenAI-Compatible Format (recommended)
Endpoint
POST $URL/v1/chat/completionsSupported Models
| Model | Positioning |
|---|---|
gemini-3.5-flash | Latest high-speed version |
gemini-3.1-pro | 3.1 flagship |
gemini-3.1-flash-lite | 3.1 lightweight version |
gemini-3-pro-preview | 3.0 Pro preview |
gemini-3-flash-preview | 3.0 lightweight preview |
gemini-2.5-pro / gemini-2.5-flash | 2.5 stable versions |
gemini-2.5-pro-preview-tts | Supports voice output |
More versions (gemini-pro-latest / gemini-flash-latest aliases, etc.) are available in the "Model Hub" section of the console.
Request Example
bash
curl $URL/v1/chat/completions \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro",
"messages": [
{"role": "user", "content": "Explain why GPS satellites need clock calibration using relativity"}
]
}'python
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="$URL/v1")
resp = client.chat.completions.create(
model="gemini-2.5-pro",
messages=[{"role": "user", "content": "Explain why GPS satellites need clock calibration using relativity"}],
)
print(resp.choices[0].message.content)ts
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: process.env.YOUR_API_KEY,
baseURL: '$URL/v1',
})
const resp = await client.chat.completions.create({
model: 'gemini-2.5-pro',
messages: [{ role: 'user', content: 'Explain why GPS satellites need clock calibration using relativity' }],
})
console.log(resp.choices[0].message.content)Method 2: Gemini Native Format
If you need the Gemini SDK or native endpoint, call:
POST $URL/v1/models/{model}:generateContentRequest Body (Gemini Native)
json
{
"contents": [
{
"role": "user",
"parts": [{ "text": "Explain the theory of relativity in simple terms." }]
}
],
"systemInstruction": {
"parts": [{ "text": "You are a helpful physics tutor." }]
},
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 1024
}
}cURL Example
bash
curl $URL/v1/models/gemini-2.5-pro:generateContent \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Explain the theory of relativity in simple terms."}]
}
]
}'Recommendation
| Scenario | Recommended Method |
|---|---|
| Existing OpenAI SDK code | Method 1, just change the model |
| Need Gemini-specific features (grounding, native function calling syntax) | Method 2 |
| Multi-model unified management | Method 1 |
