指南
gemini
Gemini Stream Generate Content API

Gemini 聊天接口(流式)

Endpoint: POST /v1beta/models/{model}:streamGenerateContent
Base URL: https://api.floxai.io
鉴权: x-goog-api-key: <your-api-key>


请求参数

Path 参数

参数类型必需说明
modelstring模型名称,如 gemini-2.5-flash

Body 参数

基础输入

参数类型必需说明
contentsarray对话内容数组,每项包含 roleuser / model)和 parts(消息内容)
system_instruction.partsobject系统指令,目前仅支持文本

生成设置(generationConfig

参数类型说明
temperatureinteger采样温度
topPnumber核采样概率
topKintegerTop-K 采样
maxOutputTokensinteger最大输出 token 数
stopSequencesarray[string]停止序列
responseMimeTypestring结构化输出格式,如 application/json
responseSchemaobject输出 JSON Schema,须为 OpenAPI Schema 的子集
responseModalitiesarray[string]输出模态:Text / Image / AUDIO
speechConfigobject音频输出设置

推理设置(generationConfig.thinkingConfig

参数类型说明
includeThoughtsboolean是否在响应中包含推理过程
thinkingBudgetinteger推理最大 token 数

工具(tools

参数类型说明
tools[].functionDeclarationsarray自定义函数工具
tools[].codeExecutionobject代码执行工具
tools[].googleSearchobject联网搜索工具
tool_config.functionCallingConfigobject函数调用配置

安全设置

参数类型说明
safetySettingsarray安全过滤配置,用于阻止不安全内容

请求示例

curl --location --request POST 'https://api.floxai.io/v1beta/models/gemini-2.5-flash:streamGenerateContent' \
  --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."
          }
        ]
      }
    ]
  }'