Gemini 协议
通过 Gemini GenerateContent API 格式访问 Google Gemini 模型。
Gemini 协议以 Google Gemini API 格式暴露。它专门服务 Google Gemini 模型,因此没有供应商选择器——只需更改 Base URL 即可使用 Google GenAI SDK。安装与完整示例参见 Gemini SDK 指南。
端点
POST https://api.openmodel.ai/v1beta/models/{model}:generateContent
POST https://api.openmodel.ai/v1beta/models/{model}:streamGenerateContent:generateContent 用于一次性返回,:streamGenerateContent 用于以 Server-Sent Events 增量返回。
流式端点的返回格式
streamGenerateContent 支持两种返回格式:
| 请求方式 | 返回内容 |
|---|---|
?alt=sse | 增量 SSE 事件(text/event-stream) |
不传 alt,或使用 ?alt=json | 生成完成后一次性返回完整 JSON 数组 |
OpenModel 会保留客户端选择的格式。Google GenAI SDK 会自动处理;直接调用端点且需要实时输出时,请显式请求 alt=sse。
认证
通过 x-goog-api-key 请求头,或 key 查询参数传入 OpenModel API 密钥:
x-goog-api-key: om-your-api-key错误格式
Gemini 错误体携带 error.status 字段(如 UNAUTHENTICATED、INVALID_ARGUMENT),遵循标准 Gemini API 结构。
生成内容
授权
GoogApiKey 在请求中包含您的 API 密钥:X-Goog-Api-Key: om-your-api-key
位置: header
路径参数
用于内容生成的模型。
查询参数
API 密钥(可替代 X-Goog-Api-Key 请求头)。
请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
curl -X POST "https://example.com/v1beta/models/gemini-3.5-flash:generateContent" \ -H "Content-Type: application/json" \ -d '{ "contents": [ { "parts": [ { "text": "Explain quantum computing in simple terms." } ] } ] }'{
"candidates": [
{
"content": {
"parts": [
{
"text": "Imagine a regular computer uses bits, which are like tiny switches that can be either OFF (0) or ON (1). A quantum computer uses quantum bits, or qubits, which can be both 0 and 1 at the same time."
}
],
"role": "model"
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 8,
"candidatesTokenCount": 102,
"totalTokenCount": 110
},
"modelVersion": "gemini-3.5-flash"
}{
"error": {
"code": 0,
"message": "string",
"status": "string"
}
}{
"error": {
"code": 0,
"message": "string",
"status": "string"
}
}流式生成内容
授权
GoogApiKey 在请求中包含您的 API 密钥:X-Goog-Api-Key: om-your-api-key
位置: header
路径参数
用于内容生成的模型。
查询参数
API 密钥(可替代 X-Goog-Api-Key 请求头)。
请求体
application/json
TypeScript 类型定义
在 TypeScript 中使用 request body 类型。
响应体
application/json
application/json
application/json
curl -X POST "https://example.com/v1beta/models/gemini-3.5-flash:streamGenerateContent" \ -H "Content-Type: application/json" \ -d '{ "contents": [ { "parts": [ { "text": "Write a short story about a robot learning to paint." } ] } ] }'{
"candidates": [
{
"content": {
"parts": [
{
"text": "string"
}
],
"role": "string"
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 0,
"candidatesTokenCount": 0,
"totalTokenCount": 0
},
"modelVersion": "string"
}{
"error": {
"code": 0,
"message": "string",
"status": "string"
}
}{
"error": {
"code": 0,
"message": "string",
"status": "string"
}
}