Text Series
Gemini Native (Text)
Use Google Gemini native format to call API
POST
Introduction
The Gemini Native API uses Google Gemini’s request and response format, suitable for Google official clients (such asgoogle-generativeai SDK) or scenarios requiring direct use of Gemini data structures.
If using OpenAI-compatible clients (such as OpenAI SDK), please use the /v1/chat/completions endpoint.
Differences from OpenAI Format
| Feature | Gemini Native | OpenAI Compatible |
|---|---|---|
| Message Structure | contents[].parts[] | messages[].content |
| Role Names | user / model | user / assistant |
| Streaming Parameter | URL param ?alt=sse | Body param stream: true |
| System Prompt | systemInstruction | messages[0].role: "system" |
| Multimodal | Mixed parts[] array | Mixed content[] array |
API Endpoints
| Function | Method | Path |
|---|---|---|
| Text Generation (Non-streaming) | POST | /v1beta/models/{model}:generateContent |
| Text Generation (Streaming) | POST | /v1beta/models/{model}:streamGenerateContent?alt=sse |
| Single Embedding | POST | /v1beta/models/{model}:embedContent |
| Batch Embedding | POST | /v1beta/models/{model}:batchEmbedContents |
Authentication
Two authentication methods are supported:| Method | Header | Example |
|---|---|---|
| Bearer Token (Recommended) | Authorization | Bearer sk-xxxxxxxxxx |
| Google Style | x-goog-api-key | sk-xxxxxxxxxx |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
contents | array | Yes | Conversation content array |
generationConfig | object | No | Generation configuration |
safetySettings | array | No | Safety filter settings |
systemInstruction | object | No | System instruction |
tools | array | No | Tool definitions (function calling, search, etc.) |
cachedContent | string | No | Cached content name |
generationConfig Parameters
| Parameter | Type | Description |
|---|---|---|
temperature | number | Randomness (0-2) |
topP | number | Nucleus sampling (0-1) |
topK | integer | Top-K sampling |
maxOutputTokens | integer | Maximum output tokens |
stopSequences | array | Stop sequences |
candidateCount | integer | Number of candidate responses |
thinkingConfig | object | Thinking mode configuration |
Basic Examples
- cURL (Non-streaming)
- cURL (Streaming)
- Python
- Node.js
Advanced Features
- Thinking Mode
- Multimodal Input
- Function Calling
- Google Search
- Streaming
- Context Caching
- Image Generation
Thinking Mode
Gemini 2.5 Pro and Gemini 3 Pro support thinking mode, allowing the model to perform deep reasoning before answering.Gemini 2.5 Pro - UsingthinkingBudget:thinkingLevel:| Parameter | Applicable Model | Options |
|---|---|---|
thinkingBudget | Gemini 2.5 Pro | 1-24576 (token count) |
thinkingLevel | Gemini 3 Pro | LOW / MEDIUM / HIGH |
Embedding API
Single Embedding
Batch Embedding
Response Format
Error Handling
| HTTP Status | Error Type | Description |
|---|---|---|
| 400 | INVALID_ARGUMENT | Invalid request parameter |
| 401 | UNAUTHENTICATED | Invalid or missing API key |
| 403 | PERMISSION_DENIED | No access to this model |
| 404 | NOT_FOUND | Model not found |
| 429 | RESOURCE_EXHAUSTED | Rate limit exceeded |
| 500 | INTERNAL | Internal server error |
Comparison with OpenAI Format
| Feature | Gemini Native | OpenAI Compatible |
|---|---|---|
| Base URL | https://api.mixroute.ai/v1beta | https://api.mixroute.ai/v1 |
| Message Structure | contents[].parts[] | messages[].content |
| Role Names | user / model | user / assistant |
| System Prompt | systemInstruction | messages[0].role: "system" |
| Streaming Request | URL param ?alt=sse | Body param stream: true |
| Temperature Range | 0-2 | 0-2 |
| Function Calling | tools[].functionDeclarations | tools[].function |
| Search Grounding | tools[].googleSearch | Not supported |
| Thinking Mode | thinkingConfig | Not supported |