gemini-3.1-pro-preview

gemini-3.1-pro-preview
文本GoogleGemini 3.1 Pro默认规格
谷歌最强推理模型

鉴权与连接

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
字段类型必填
contentsarrayY
contents[]objectY
contents[].rolestringY
contents[].partsarrayY
contents[].parts[]objectY
contents[].parts[].textstringY
toolsarrayY
tools[]objectY
tools[].functionobjectY
tools[].function.namestringY
tools[].typestringY
// RESPONSE SCHEMA
字段类型必填
output.textstringN

代码示例

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
字段类型必填
messagesarrayY
streambooleanN
reasoning_effortstringN
toolsarrayN
// RESPONSE SCHEMA
字段类型必填
output.textstringN

代码示例

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"
    }
  ]
}'