Gemini 3 Flash
Google Gemini 3 Flash 高速多模态模型。原生 Gemini 协议(非 OpenAI 兼容),支持文本、图片、音频、视频和文档输入,内置思考层级(thinkingLevel)、Google 搜索增强和函数调用。
模型
| 模型名称 | 上下文窗口 | 推理 |
|---|---|---|
gemini-3-flash | 100 万 tokens | 是(thinkingConfig) |
定价
按 token 计费:
| 类型 | 积分 / 百万 tokens | 价格 / 百万 tokens |
|---|---|---|
| 输入 (Input) | 120 credits | $0.60 |
| 输出 (Output) | 240 credits | $1.20 |
接口地址
POST https://api.aivideoapi.ai/v1/gemini/v1beta/models/gemini-3-flash:streamGenerateContent
POST https://api.aivideoapi.ai/v1/gemini/v1beta/models/gemini-3-flash:generateContent
URL 末尾决定是否流式:streamGenerateContent 为流式,generateContent 为一次性返回。
兼容 Google GenAI SDK,将 baseUrl 指向 https://api.aivideoapi.ai/v1/gemini。
创建对话
curl -X POST "https://api.aivideoapi.ai/v1/gemini/v1beta/models/gemini-3-flash:streamGenerateContent" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "role": "user", "parts": [{ "text": "北京今天天气怎么样?" }] }
]
}'
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
contents | array | 是 | 对话内容数组 |
tools | array | 否 | 工具定义,支持 googleSearch 或 functionDeclarations |
generationConfig | object | 否 | 生成配置,含 thinkingConfig |
Contents
每条消息含 role(user 或 model)和 parts 数组:
{
"role": "user",
"parts": [
{ "text": "这张图里有什么?" },
{ "inline_data": { "mime_type": "image/jpeg", "data": "<base64...>" } }
]
}
thinkingConfig
{
"generationConfig": {
"thinkingConfig": {
"includeThoughts": true,
"thinkingLevel": "high"
}
}
}
thinkingLevel:low 或 high。
响应
{
"candidates": [
{
"content": {
"role": "model",
"parts": [{ "text": "今天北京晴..." }]
},
"finishReason": "STOP"
}
],
"modelVersion": "gemini-3-flash",
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 18,
"thoughtsTokenCount": 55,
"totalTokenCount": 85
}
}
示例
启用 Google 搜索
curl -X POST "https://api.aivideoapi.ai/v1/gemini/v1beta/models/gemini-3-flash:generateContent" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "role": "user", "parts": [{ "text": "今天的科技新闻" }] }
],
"tools": [{ "googleSearch": {} }]
}'
函数调用
curl -X POST "https://api.aivideoapi.ai/v1/gemini/v1beta/models/gemini-3-flash:generateContent" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{ "role": "user", "parts": [{ "text": "查询北京天气" }] }
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_weather_forecast",
"description": "获取指定城市天气预报",
"parameters": {
"type": "OBJECT",
"properties": {
"location": { "type": "STRING", "description": "城市名" }
},
"required": ["location"]
}
}
]
}
]
}'
限制:
googleSearch与functionDeclarations不能同时启用。
常见错误码
请求失败时,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 服务返回错误,可能原因:
- 输入内容包含敏感或违规信息
- 上游服务暂时不可用
- 请求参数不被上游支持
因上游错误导致任务失败时,预扣积分会自动退还。