跳转到主要内容
POST
/
gemini-3-pro
/
v1
/
chat
/
completions
聊天完成
curl --request POST \
  --url https://api.kie.ai/gemini-3-pro/v1/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "这张图片里有什么?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://file.aiquickdraw.com/custom-page/akr/section-images/1759055072437dqlsclj2.png"
          }
        }
      ]
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "googleSearch"
      }
    }
  ],
  "stream": true,
  "include_thoughts": true,
  "reasoning_effort": "high",
  "response_format": {
    "type": "object",
    "properties": {
      "response": {
        "type": "string"
      }
    }
  }
}
'
{
  "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
  "object": "chat.completion",
  "created": 1741569952,
  "model": "gemini-3-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "hello,can i help you?",
        "refusal": null,
        "annotations": []
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "service_tier": "default"
}

流式响应支持

当请求中设置 stream: true 时,API 将以服务器发送事件(SSE)的形式返回响应,Content-Type 为 text/event-stream。这允许渐进式响应交付,消息增量会在生成时逐步发送。每个事件包含部分消息内容,使您能够在应用程序中实时显示响应。 流式响应格式:
  • Content-Type: text/event-stream
  • 每个事件行以 data: 开头,后跟 JSON
  • 事件包含增量消息增量
  • 最终事件通过 finish_reason 指示完成

多模态

支持文本和图像输入

实时搜索

启用 Google 搜索增强

流式传输

支持服务器发送事件

灵活角色

支持多种消息角色

Tools 参数

tools 参数是一个可选数组,允许您定义模型可以调用的函数。数组可以包含多个对象。使用函数调用时,可以在数组中定义多个函数。
Google 搜索和函数调用是互斥的:不能在同一个请求中同时使用 Google 搜索和函数调用。请根据您的需求选择其中一种。
使用此格式启用 Google 搜索增强:
{
  "type": "function",
  "function": {
    "name": "googleSearch"
  }
}
这将通过 Google 搜索启用实时信息检索。
定义带有参数的自定义函数。可以在 tools 数组中定义多个函数:
[
  {
    "type": "function",
    "function": {
      "name": "get_current_weather",
      "description": "获取给定位置的当前天气",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "城市和州,例如:San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location"]
      }
    }
  },
  {
    "type": "function",
    "function": {
      "name": "get_stock_price",
      "description": "获取指定股票代码的当前股价",
      "parameters": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "股票代码,例如:AAPL"
          }
        },
        "required": ["symbol"]
      }
    }
  }
]

函数声明要求

在提示中实现函数调用时,您需要创建一个 tools 数组,其中包含一个或多个函数声明。您可以使用 JSON(具体来说是 OpenAPI 架构格式的选定子集)来定义函数。单个函数声明可以包含以下参数:
  • name(字符串,必需):函数的唯一名称(例如,get_weather_forecastsend_email)。使用不含空格或特殊字符的描述性名称(使用下划线或驼峰式命名法)。
  • description(字符串,可选但推荐):对函数用途和功能的清晰而详尽的说明。这对于模型了解何时使用函数至关重要。请具体说明,并在必要时提供示例(例如,“根据位置查找影院,还可以选择查找目前正在影院上映的电影。”)。
  • parameters(对象,必需):定义函数预期的输入参数。包含:
    • type(字符串):指定总体数据类型,必须为 "object"
    • properties(对象):列出各个参数,每个参数都具有以下属性:
      • type(字符串):参数的数据类型,例如 stringintegerbooleanarray
      • description(字符串):对参数的用途和格式的说明。提供示例和限制条件(例如,“城市和州,例如’加利福尼亚州旧金山’或邮政编码(例如’95616’)。”)。
      • enum(数组,可选):如果参数值来自固定集,请使用 enum 列出允许的值,而不是仅在说明中描述它们。这有助于提高准确性(例如,"enum": ["daylight", "cool", "warm"])。
    • required(数组):一个字符串数组,列出了函数运行所必需的参数名称。

Response Format 参数

response_format 参数是一个可选的 JSON Schema 对象,定义响应的结构。提供此参数时,模型将生成符合此架构的响应。
response_format 和函数调用是互斥的:不能在同一个请求中同时使用 response_format 和函数调用。请根据您的需求选择其中一种。
response_format 遵循 JSON Schema 规范。支持的类型包括:
  • string:文本值
  • number:浮点数
  • integer:整数
  • boolean:布尔值(true/false)
  • object:包含键值对的结构化数据
  • array:项目列表
  • null:要允许 null 值,请在类型数组中添加 "null"(例如,{"type": ["string", "null"]}

特定类型的属性

对于 object 值:
  • properties:将属性名称映射到其架构定义的对象
  • required:必需属性名称数组
  • additionalProperties:控制是否允许不在 properties 中列出的属性
对于 string 值:
  • enum:用于分类的特定可能字符串列表
  • format:指定字符串语法(例如,date-timedatetime
对于 numberinteger 值:
  • enum:特定可能数值列表
  • minimum:包含在内的最小值
  • maximum:包含在内的最大值
对于 array 值:
  • items:所有数组元素的架构定义
  • prefixItems:前 N 个项的架构列表(类似元组的结构)
  • minItems:数组中的最小项数
  • maxItems:数组中的最大项数
{
  "response_format": {
    "type": "object",
    "properties": {
      "response": {
        "type": "string"
      }
    }
  }
}
  • 清晰的描述:在架构中使用 description 字段清楚地解释每个属性的含义
  • 强类型:尽可能使用特定类型(integerstringenum
  • 提示工程:在提示中明确说明您希望模型提取或结构化的内容
  • 验证:虽然结构化输出确保 JSON 在语法上正确,但请务必在应用程序代码中验证值的语义正确性
{
  "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
  "object": "chat.completion",
  "created": 1741569952,
  "model": "gemini-3-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "hello,can i help you?",
        "refusal": null,
        "annotations": []
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "service_tier": "default"
}

授权

Authorization
string
header
必填

所有 API 都需要通过 Bearer Token 进行身份验证。

获取 API Key:

  1. 访问 API Key 管理页面 获取您的 API Key

使用方法: 添加到请求头: Authorization: Bearer YOUR_API_KEY

注意:

  • 请妥善保管您的 API Key,不要与他人分享
  • 如果您怀疑 API Key 已泄露,请立即在管理页面重置

请求体

application/json
messages
object[]
必填

消息对象数组。每个消息都有一个角色和内容。

Minimum array length: 1
stream
boolean
默认值:true

如果设置为 true,将作为服务器发送事件发送部分消息增量。默认为 true。

tools
object[]

可选,模型可以调用的工具数组。数组可以包含多个对象。支持两种格式:

  1. Google 搜索{"type": "function", "function": {"name": "googleSearch"}} - 通过 Google 搜索启用实时信息检索。
  2. 函数调用:定义自己的函数,包含 name、description 和 parameters。可以在数组中定义多个函数。函数使用 JSON(具体来说是 OpenAPI 架构格式的选定子集)来定义。

重要:Google 搜索和函数调用是互斥的 - 不能在同一个请求中同时使用两者。使用函数调用时,可以包含多个函数定义。函数调用和 response_format 也是互斥的 - 不能在同一个请求中同时使用两者。

include_thoughts
boolean
默认值:true

是否包含思考过程。如果设置为 true,思考将会被包含在响应结果中,否则将不会出现在响应结果中。默认为 true。

reasoning_effort
enum<string>
默认值:high

推理的力度。低力度响应更快,高力度响应更慢但解决更复杂的问题。默认为 "high"。

可用选项:
low,
high
response_format
object

可选的 JSON Schema 对象,定义响应的结构。提供此参数时,模型将生成符合此架构的响应。response_format 和函数调用是互斥的 - 不能在同一个请求中同时使用两者。

示例:

{
"type": "object",
"properties": {
"response": {
"type": "string"
}
}
}

响应

请求成功。当提供 response_format 时,响应将符合指定的 JSON 架构。否则,返回标准的聊天完成格式。

id
string

聊天完成的唯一标识符

示例:

"chatcmpl-123"

object
string

对象类型

示例:

"chat.completion"

created
integer<int64>

完成创建时的 Unix 时间戳

示例:

1677652288

model
string

模型名称

示例:

"gemini-3-pro"

choices
object[]

完成选项数组

usage
object