WARNING
⚠️ 仅支持对话调用
该模型目前仅支持对话调用,暂未适配 Agent 场景。若将其接入 Agent 使用,可能会出现请求报错或结果异常。
当请求中设置 stream: true 时,API 将以服务器发送事件(SSE)的形式返回响应,Content-Type 为 text/event-stream。这允许渐进式响应交付,消息增量会在生成时逐步发送。每个事件包含部分消息内容,使您能够在应用程序中实时显示响应。
流式响应格式:
text/event-streamdata: 开头,后跟 JSONfinish_reason 指示完成WARNING
在 messages 参数的 content 数组中,无论是图像、视频、音频还是其他文档类型,所有媒体文件都使用相同的格式结构:
type 字段始终为 "image_url"image_url 字段名称保持不变url 值,它指向相应的媒体文件地址例如:图像、视频、音频、PDF 和其他文档都使用相同的 { type: 'image_url', image_url: { url: '...' } } 结构。
tools 参数是一个可选数组,允许您定义模型可以调用的函数。数组可以包含多个对象。使用函数调用时,可以在数组中定义多个函数。
{
"type": "function",
"function": {
"name": "googleSearch"
}
}
这将通过 Google 搜索启用实时信息检索。
错误以 HTTP 200 返回,响应体为 {"code": , "msg": "<原因>"}。读取 choices/candidates 前请先判断 code(200 为成功)。
curl --location 'https://api.kie.ai/gemini-3.1-pro/v1/chat/completions' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"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"
}'{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Hello! How can I help you today?",
"role": "assistant"
}
}
],
"created": 1768283309,
"credits_consumed": 0.27,
"id": "chatcmpl-********************z6IaTP6H",
"object": "chat.completion",
"usage": {
"completion_tokens": 383,
"completion_tokens_details": {
"audio_tokens": 0,
"text_tokens": 0,
"reasoning_tokens": 374
},
"prompt_tokens": 1,
"total_tokens": 384
}
}