Gemini 2.5 Pro
Google Gemini 2.5 Pro 对话补全模型。支持文本、图片、视频、音频和文档输入,内置推理思考(thinking)、函数调用、Google 搜索增强和结构化 JSON 输出。
模型
| 模型名称 | 上下文窗口 | 推理 |
|---|---|---|
gemini-2.5-pro | 100 万 tokens | 是(默认开启思考) |
定价
按 token 计费:
| 类型 | 积分 / 百万 tokens | 价格 / 百万 tokens |
|---|---|---|
| 输入 (Input) | 57 credits | $0.285 |
| 输出 (Output) | 450 credits | $2.25 |
创建对话
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-2.5-pro",
"messages": [
{
"role": "user",
"content": "用简单的语言解释量子计算"
}
]
}'
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 必须为 gemini-2.5-pro |
messages | array | 是 | 对话消息,详见 Messages |
stream | boolean | 否 | 是否流式输出(默认 true) |
tools | array | 否 | 函数定义,用于工具调用 |
include_thoughts | boolean | 否 | 包含推理思考过程(默认 true) |
reasoning_effort | string | 否 | low 或 high(默认 high) |
response_format | object | 否 | JSON Schema,用于结构化输出 |
注意:
tools和response_format不能同时使用。Google 搜索和函数调用也不能同时使用。
Messages
每条消息包含 role 和 content:
| 角色 | 说明 |
|---|---|
system | 系统指令 |
developer | 开发者指令 |
user | 用户输入(文本、图片等) |
assistant | 模型回复 |
tool | 工具调用结果 |
文本消息
{
"role": "user",
"content": "生命的意义是什么?"
}
图片消息
{
"role": "user",
"content": [
{ "type": "text", "text": "这张图片里是什么?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
]
}
图片、视频、音频和文档都使用相同的
image_url格式。
响应(非流式)
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677652288,
"model": "gemini-2.5-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "量子计算使用量子比特(qubit)..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 86,
"total_tokens": 98
}
}
响应(流式)
当 stream: true 时,响应为 SSE 事件流:
data: {"id":"chatcmpl-abc123","choices":[{"delta":{"role":"assistant","content":"量子"},"index":0}]}
data: {"id":"chatcmpl-abc123","choices":[{"delta":{"content":"计算"},"index":0}]}
data: {"id":"chatcmpl-abc123","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":86,"total_tokens":98}}
data: [DONE]
示例
多模态(图片输入)
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-2.5-pro",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "详细描述这张图片" },
{ "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
]
}
]
}'
函数调用
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-2.5-pro",
"messages": [
{ "role": "user", "content": "东京今天天气怎么样?" }
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的当前天气",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string", "description": "城市名称" }
},
"required": ["location"]
}
}
}
]
}'
结构化输出(JSON Schema)
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-2.5-pro",
"messages": [
{ "role": "user", "content": "列出 3 位著名科学家" }
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "scientists",
"schema": {
"type": "object",
"properties": {
"scientists": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"field": { "type": "string" }
}
}
}
}
}
}
}
}'
低推理强度
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-2.5-pro",
"messages": [
{ "role": "user", "content": "2+2 等于几?" }
],
"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 服务返回错误,可能原因:
- 输入内容包含敏感或违规信息
- 上游服务暂时不可用
- 请求参数不被上游支持
因上游错误导致任务失败时,预扣积分会自动退还。