Gemini Native API
This platform provides a chat and text-generation endpoint compatible with the Gemini GenerateContent API.
This document is intended for client-side integrators and focuses on the public request path, authentication method, request parameters, and example payloads. Field names and JSON structure are kept as close as possible to the native Gemini GenerateContent API.
Overview:
- Endpoints:
POST /v1beta/models/{model}:generateContentPOST /v1beta/models/{model}:streamGenerateContent
- Capability type: chat / text generation
- Response modes:
generateContent: standard JSON responsestreamGenerateContent:text/event-streamSSE response
- Protocol style: the request body follows the native
GenerateContentRequeststructure and does not wrap content in an extrainputfield
1. API Overview
- HTTP method:
POST - Request paths:
/v1beta/models/{model}:generateContent/v1beta/models/{model}:streamGenerateContent
- Content-Type:
application/json - Response type:
- Non-streaming:
application/json - Streaming:
text/event-stream
- Non-streaming:
2. Authentication and Headers
Example headers:
x-goog-api-key: YOUR_REACH_API_KEY
Content-Type: application/jsonAt least one of Authorization or x-goog-api-key must be provided. We recommend x-goog-api-key to stay aligned with the native Gemini protocol.
Header details:
| Header | Required | Description |
|---|---|---|
Authorization | No | Platform API key in the format Bearer sk-xxxxxx |
x-goog-api-key | No | You can also pass the platform API key directly in this header for Gemini-compatible authentication |
Content-Type | Yes | Must be application/json |
3. Request Body
The request body follows the native GenerateContentRequest object structure:
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Please introduce yourself in one sentence."
}
]
}
],
"generationConfig": {
"temperature": 0.2
}
}3.1 Top-Level Parameters
| Field | Type | Required | Description |
|---|---|---|---|
contents | array<object> | Yes | Conversation content list, at least one item |
tools | array<object> | No | Tool or function declarations |
toolConfig | object | No | Tool calling strategy configuration |
safetySettings | array<object> | No | Safety policy overrides |
systemInstruction | object | No | System instruction |
generationConfig | object | No | Generation parameters such as temperature, topP, topK, and maxOutputTokens |
cachedContent | string | No | Resource name for reused cached content |
3.2 Common contents.parts Patterns
Text input example:
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Write a short product introduction within 50 words."
}
]
}
]
}Multi-part input example:
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Please describe this image."
},
{
"fileData": {
"mimeType": "image/png",
"fileUri": "https://cdn.example.com/demo.png"
}
}
]
}
]
}4. Request Examples
4.1 Standard Non-Streaming Request
curl -X POST "https://direct.reachapi.ai/v1beta/models/YOUR_MODEL_ID:generateContent" \
-H "x-goog-api-key: YOUR_REACH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Introduce ReachAPI in one sentence."
}
]
}
],
"generationConfig": {
"temperature": 0.2
}
}'4.2 Streaming Request
curl -X POST "https://direct.reachapi.ai/v1beta/models/YOUR_MODEL_ID:streamGenerateContent?alt=sse" \
-H "x-goog-api-key: YOUR_REACH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Summarize today'\''s priorities in three lines."
}
]
}
]
}'4.3 Request with Function Declarations
curl -X POST "https://direct.reachapi.ai/v1beta/models/YOUR_MODEL_ID:generateContent" \
-H "x-goog-api-key: YOUR_REACH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Help me check the weather in Shanghai."
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_weather",
"description": "Get weather information for a city",
"parameters": {
"type": "OBJECT",
"properties": {
"city": {
"type": "STRING"
}
},
"required": ["city"]
}
}
]
}
]
}'5. Successful Response
Example non-streaming response:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "ReachAPI is a unified AI gateway."
}
],
"role": "model"
},
"finishReason": "STOP"
}
],
"modelVersion": "YOUR_MODEL_VERSION",
"responseId": "resp_xxx",
"usageMetadata": {
"promptTokenCount": 18,
"candidatesTokenCount": 22,
"totalTokenCount": 40
}
}5.1 usageMetadata
Common fields include:
| Field | Description |
|---|---|
promptTokenCount | Number of input tokens |
candidatesTokenCount | Number of candidate output tokens |
totalTokenCount | Total number of tokens |
6. Error Response
Gemini-style error example:
{
"error": {
"code": 400,
"message": "Field `contents` is required",
"status": "INVALID_ARGUMENT"
}
}Common scenarios:
contentsis missing or empty- Invalid request parameter format
- Authentication failure
7. Compatibility Notes
{model}in the path is the model ID, somodelis not passed in the request body- This document lists commonly used fields and example payloads. Actual field names and structures follow the Gemini GenerateContent API
- If you use advanced capabilities such as
tools,toolConfig, orcachedContent, confirm that the target model actually supports them - When calling
streamGenerateContent, explicitly adding?alt=sseis recommended
8. Supported Models and Reference Pricing
The following prices are summarized from the unified pricing document and apply to the Gemini text models currently listed. Pricing was checked on 2026-04-17. For detailed pricing rules, refer to gemini.md.
| Model | Input | Output | Cache read | Search grounding |
|---|---|---|---|---|
gemini-3.1-pro-preview | $2.00 / 1M (<= 200K) / $4.00 / 1M (> 200K) | $12.00 / 1M (<= 200K) / $18.00 / 1M (> 200K) | $0.20 / 1M (<= 200K) / $0.40 / 1M (> 200K) | First 5,000 prompts / month are free, then $14 / 1,000 search queries |
gemini-2.5-pro | $1.25 / 1M (<= 200K) / $2.50 / 1M (> 200K) | $10.00 / 1M (<= 200K) / $15.00 / 1M (> 200K) | $0.125 / 1M (<= 200K) / $0.25 / 1M (> 200K) | First 1,500 RPD are free, then $35 / 1,000 grounded prompts |
gemini-2.5-flash | $0.30 / 1M | $2.50 / 1M | $0.03 / 1M | First 1,500 RPD are free, then $35 / 1,000 grounded prompts |
gemini-2.5-flash-lite | $0.10 / 1M | $0.40 / 1M | $0.01 / 1M | First 1,500 RPD are free, then $35 / 1,000 grounded prompts |
Notes:
- Some Gemini models use different input token pricing tiers, with different unit prices for
<= 200Kand> 200K - The billing unit for Search grounding may vary across model generations. See the detailed pricing document for specifics
9. References
- Gemini API reference: https://ai.google.dev/api/generate-content
- Gemini text generation guide: https://ai.google.dev/gemini-api/docs/text-generation
- Unified platform pricing document:
gemini.md