鉴权与连接
- Base URL
https://backend:8000- Authorization
Authorization: Bearer YOUR_API_KEY- Content-Type
application/json- 模型名 (model)
gemini-3.1-pro-preview
接入协议
为什么选这个协议
适合原本使用 Gemini SDK 或 generateContent 接口的用户直接迁移。
接口地址
POST/v1beta/models/gemini-3.1-pro-preview:generateContent
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
// REQUEST
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hello"
}
]
}
],
"tools": [
{
"function": {
"name": "web_search"
},
"type": "function"
}
]
}// RESPONSE
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Hello from Mix API"
}
]
}
}
],
"modelVersion": "gemini-3.1-pro-preview",
"usageMetadata": {
"promptTokenCount": 8,
"candidatesTokenCount": 16,
"totalTokenCount": 24
}
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| contents | array | Y |
| contents[] | object | Y |
| contents[].role | string | Y |
| contents[].parts | array | Y |
| contents[].parts[] | object | Y |
| contents[].parts[].text | string | Y |
| tools | array | Y |
| tools[] | object | Y |
| tools[].function | object | Y |
| tools[].function.name | string | Y |
| tools[].type | string | Y |
// RESPONSE SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| output.text | string | N |
代码示例
cURLrequest.sh
curl -X POST "https://backend:8000/v1beta/models/gemini-3.1-pro-preview:generateContent" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hello"
}
]
}
],
"tools": [
{
"function": {
"name": "web_search"
},
"type": "function"
}
]
}'为什么选这个协议
适合已有 OpenAI SDK、Chat Completions 代码或统一网关接入的用户。
接口地址
POST/v1/chat/completions
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
// REQUEST
{
"model": "gemini-3.1-pro-preview",
"messages": [
{
"content": "Hello",
"role": "user"
}
],
"stream": false,
"reasoning_effort": "low",
"tools": [
{
"function": {
"name": "web_search"
},
"type": "function"
}
]
}// RESPONSE
{
"output": {
"text": "Hello"
}
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| messages | array | Y |
| stream | boolean | N |
| reasoning_effort | string | N |
| tools | array | N |
// RESPONSE SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| output.text | string | N |
代码示例
cURLrequest.sh
curl -X POST "https://backend:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gemini-3.1-pro-preview",
"messages": [
{
"content": "Hello",
"role": "user"
}
],
"stream": false,
"reasoning_effort": "low",
"tools": [
{
"function": {
"name": "web_search"
},
"type": "function"
}
]
}'