Gemini 3.1 Pro
Google Gemini 3.1 Pro 多模态模型,通过 OpenAI 兼容 /v1/chat/completions 接口提供。支持文本、图片、视频、音频、PDF 输入,内置 Google 搜索增强和流式输出。
模型
| 模型名称 | 上下文窗口 | 推理 |
|---|---|---|
gemini-3.1-pro | 100 万 tokens | 是(reasoning_effort 控制) |
定价
按 token 计费:
| 类型 | 积分 / 百万 tokens | 价格 / 百万 tokens |
|---|---|---|
| 输入 (Input) | 160 credits | $0.80 |
| 输出 (Output) | 960 credits | $4.80 |
接口地址
POST https://api.aivideoapi.ai/v1/chat/completions
兼容 OpenAI Chat Completions 协议。可直接使用 openai SDK,将 baseURL 指向 https://api.aivideoapi.ai/v1。
创建对话
curl -X POST https://api.aivideoapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro",
"messages": [
{ "role": "user", "content": "你好,介绍一下自己" }
]
}'
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 必须为 gemini-3.1-pro |
messages | array | 是 | 对话消息 |
stream | boolean | 否 | 是否流式输出(默认 true) |
tools | array | 否 | 工具定义(仅支持 googleSearch) |
include_thoughts | boolean | 否 | 是否包含思考(默认 true) |
reasoning_effort | string | 否 | low 或 high(默认 high) |
多模态消息
所有媒体类型(图片/视频/音频/PDF)都使用同一 image_url 结构:
{
"role": "user",
"content": [
{ "type": "text", "text": "这张图里有什么?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
]
}
响应
{
"id": "chatcmpl-20260417001546375193862M1p62g7j",
"object": "chat.completion",
"created": 1776356269,
"model": "gemini-3.1-pro-preview",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "明天(2026年4月17日)上海的天气预报情况如下:\n\n* **天气状况**:以**多云到阴天**为主...\n* **气温**:最低气温 13℃ 至 15℃,最高气温 21℃ 左右..."
}
}
],
"usage": {
"prompt_tokens": 194,
"completion_tokens": 229,
"total_tokens": 880,
"completion_tokens_details": {
"reasoning_tokens": 457,
"audio_tokens": 0,
"text_tokens": 0
}
},
"credits_consumed": 0.25
}
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 对话补全唯一 ID |
object | string | 固定为 chat.completion |
created | int | 创建时间 Unix 时间戳 |
model | string | 上游实际响应模型版本(可能带 -preview 等后缀) |
choices[].message.content | string | 模型回复文本 |
choices[].finish_reason | string | stop / length / tool_calls 等 |
usage.prompt_tokens | int | 输入 token 数 |
usage.completion_tokens | int | 输出文本 token 数 |
usage.completion_tokens_details.reasoning_tokens | int | 思考 token 数(开启思考时) |
usage.total_tokens | int | 总 token 数(含思考) |
credits_consumed | number | 本次实际扣费积分(按本平台单价计算,与上游内部值无关) |
计费说明:
credits_consumed = prompt_tokens × 160/1M + completion_tokens × 960/1M。reasoning_tokens不计入计费,仅作审计用途记录在响应、output.usage.reasoning_tokens和pricing_detail中。
示例
Google 搜索增强
curl -X POST https://api.aivideoapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro",
"messages": [
{ "role": "user", "content": "上海明天的天气预报" }
],
"tools": [{ "type": "function", "function": { "name": "googleSearch" } }]
}'
低推理强度
curl -X POST https://api.aivideoapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro",
"messages": [
{ "role": "user", "content": "100 的平方根是多少?" }
],
"reasoning_effort": "low"
}'
常见错误码
请求失败时,API 返回 JSON 格式的错误响应:
{
"error": {
"code": "insufficient_credits",
"message": "Your credit balance is too low. Please top up.",
"type": "billing_error"
}
}
错误码一览
| HTTP 状态码 | 错误码 | 类型 | 说明 |
|---|---|---|---|
| 400 | invalid_request | invalid_request_error | 缺少必填参数或参数无效 |
| 401 | invalid_api_key | authentication_error | API Key 无效、已禁用或已删除 |
| 402 | insufficient_credits | billing_error | 积分余额不足,请充值 |
| 403 | ip_not_allowed | permission_error | 请求 IP 不在 Key 的白名单中 |
| 404 | model_not_found | invalid_request_error | 模型不存在或已停用 |
| 404 | task_not_found | invalid_request_error | 任务 ID 不存在 |
| 429 | rate_limit_exceeded | rate_limit_error | 请求过于频繁,请降低频率 |
| 429 | spend_limit_exceeded | billing_error | 达到 Key 的消费限额(每小时/每天/总量) |
| 500 | internal_error | api_error | 服务器内部错误 |
| 503 | upstream_error | upstream_error | 上游 AI 服务返回错误 |
常见场景
invalid_request (400)
缺少必填字段或参数格式错误时返回。
{
"error": {
"code": "invalid_request",
"message": "'model' is required.",
"type": "invalid_request_error"
}
}
insufficient_credits (402)
积分不足。可通过 GET /v1/credits 查询余额,前往 Dashboard > Billing 充值。
invalid_api_key (401)
可能原因:
- Key 不以
sk-开头 - Key 已被禁用或删除
- 用户账户已被封禁
upstream_error (503)
上游 AI 服务返回错误,可能原因:
- 输入内容包含敏感或违规信息
- 上游服务暂时不可用
- 请求参数不被上游支持
因上游错误导致任务失败时,预扣积分会自动退还。