文本生成
本平台统一文本生成 API 规范
文本生成接口兼容 OpenAI Chat Completions 和 Responses API。普通对话、单轮文本生成、JSON 输出和工具调用都推荐先使用本页字段规范。
推荐接口
对话和通用文本生成:
POST /v1/chat/completionsResponses 兼容客户端:
POST /v1/responsesChat Completions
curl https://geekapi.net/v1/chat/completions \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"messages": [
{
"role": "system",
"content": "你是一个简洁、可靠的业务助手。"
},
{
"role": "user",
"content": "用一句话介绍本平台 API。"
}
],
"temperature": 0.7
}'Chat 统一字段
| 字段 | 类型 | 说明 |
|---|---|---|
model | string | 本平台文本模型值,必填。 |
messages | array | 对话消息列表,必填。 |
role | string | 消息角色,常用 system、user、assistant、tool。 |
content | string 或数组 | 文本内容;多模态客户端可传数组,是否支持由具体模型决定。 |
temperature | number | 随机性参数,是否生效由上游模型决定。 |
top_p | number | 核采样参数,是否生效由上游模型决定。 |
max_tokens | number | 最大输出 token 数。 |
stream | boolean | 是否使用 SSE 流式响应。 |
tools | array | 工具定义,通常为 function calling。 |
tool_choice | string/object | 工具选择策略。 |
response_format | object | JSON 输出格式约束;是否支持由具体模型决定。 |
stop | string/string[] | 停止词。 |
Responses
{
"model": "gemini-3.5-flash",
"instructions": "你是一个简洁、可靠的业务助手。",
"input": "用一句话介绍本平台 API。",
"temperature": 0.7
}Responses 统一字段
| 字段 | 类型 | 说明 |
|---|---|---|
model | string | 本平台文本模型值,必填。 |
input | string/array | 用户输入,必填。 |
instructions | string | 系统级指令。 |
previous_response_id | string | 多轮 Responses 会话的上一轮响应 ID。 |
temperature | number | 随机性参数。 |
top_p | number | 核采样参数。 |
max_output_tokens | number | 最大输出 token 数。 |
stream | boolean | 是否使用 SSE 流式响应。 |
tools | array | 工具定义。 |
tool_choice | string/object | 工具选择策略。 |
流式响应
{
"model": "gemini-3.5-flash",
"messages": [
{
"role": "user",
"content": "写一段 100 字以内的产品介绍。"
}
],
"stream": true
}流式响应使用 text/event-stream,客户端按 SSE 读取 data: 片段,结束标记通常为 [DONE]。
JSON 输出
{
"model": "gemini-3.5-flash",
"messages": [
{
"role": "user",
"content": "返回一个包含 name 和 summary 的 JSON。"
}
],
"response_format": {
"type": "json_object"
}
}JSON 约束
不同上游对 JSON 模式、JSON Schema 和工具调用的支持程度不同。需要严格结构化输出时,请在提示词中同时说明字段要求,并在业务侧做 JSON 校验。
模型能力
| 模型值 | 系列 | Chat Completions | Responses | 流式输出 | 工具调用 | JSON 输出 | 调用规则 | 说明 |
|---|---|---|---|---|---|---|---|---|
| gemini-3.5-flash | Gemini | 支持 | 支持 | 支持 | 部分支持 | 部分支持 | 通过 /v1/chat/completions 或 /v1/responses 提交。 | 工具调用和 JSON 输出取决于当前渠道兼容能力,建议业务侧做结果校验。 |
| gemini-3-pro-preview | Gemini | 支持 | 支持 | 支持 | 部分支持 | 部分支持 | 通过 /v1/chat/completions 或 /v1/responses 提交。 | 预览模型能力可能随上游调整;工具调用和 JSON 输出取决于当前渠道兼容能力。 |
工具调用和 JSON 输出为兼容能力,具体支持程度取决于当前模型渠道;需要严格结构化输出时建议业务侧校验。
响应
Chat Completions 非流式响应通常包含:
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1782658000,
"model": "gemini-3.5-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "本平台 API 用统一模型值和兼容接口,把多家 AI 能力封装成稳定调用入口。"
},
"finish_reason": "stop"
}
]
}Responses 非流式响应通常包含 id、status、model 和输出内容字段。不同兼容客户端读取字段可能不同,建议优先使用 SDK 对应的解析方法。