Gemini 聊天接口(非流式)
Endpoint: POST /v1beta/models/{model}:generateContent
Base URL: https://api.floxai.io
鉴权: x-goog-api-key: <your-api-key>
请求参数
Path 参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,如 gemini-2.5-flash |
Body 参数
基础输入
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
contents | array | 是 | 内容数组,每项包含 role(角色)和 parts(内容) |
system_instruction.parts | object | 否 | 系统提示词 |
生成设置(generationConfig)
注意:并非所有配置可同时使用,请以官方文档为准。
| 参数 | 类型 | 说明 |
|---|---|---|
temperature | integer | 采样温度 |
topP | number | 核采样概率 |
topK | integer | Top-K 采样 |
maxOutputTokens | integer | 最大输出 token 数 |
stopSequences | array[string] | 停止序列 |
responseMimeType | string | 结构化输出格式,如 application/json |
responseSchema | object | 输出 JSON Schema,须为 OpenAPI Schema 的子集 |
responseModalities | array[string] | 输出模态:Text / Image / AUDIO |
speechConfig | object | 音频输出设置 |
thinkingConfig | object | 推理设置 |
工具(tools)
| 参数 | 类型 | 说明 |
|---|---|---|
tools[].functionDeclarations | array | 自定义函数工具 |
tools[].codeExecution | object | 代码执行工具 |
tools[].googleSearch | object | 联网搜索工具 |
tool_config.functionCallingConfig | object | 函数调用配置 |
请求示例
curl --location --request POST 'https://api.floxai.io/v1beta/models/gemini-2.5-flash:generateContent' \
--header 'x-goog-api-key: <your-api-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"contents": [
{
"parts": [
{
"text": "Write a story about a magic backpack."
}
]
}
]
}'