正在加载文档
最近更新时间: 2026-09-17 15:11:35
本文档描述了聊天补全接口的请求参数,该接口用于生成对话模型的响应。支持多种模型配置和生成控制参数。
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | - | 指定使用的模型名称。例如:"moonshotai/kimi-k2.6" 等 |
messages | array | 是 | - | 对话消息数组,包含对话历史记录 |
stream | boolean | 否 | false | 是否启用流式响应 |
messages 数组中的每个元素应包含:
role: 消息角色,可选值:"system", "user", "assistant", "tool"content: 消息内容,可以是字符串或复杂内容对象name (可选): 参与者名称tool_calls (可选): 工具调用信息tool_call_id (可选): 工具调用ID(仅当role为"tool"时)| 参数名 | 类型 | 必填 | 默认值 | 范围/示例 | 说明 |
|---|---|---|---|---|---|
max_tokens | integer | 否 | 模型默认值 | ≥1 | 生成的最大令牌数 |
temperature | float32 | 否 | 1.0 | [0.0, 2.0] | 采样温度。值越高输出越随机,值越低输出越确定 |
top_p | float32 | 否 | 1.0 | [0.0, 1.0] | 核采样参数。仅考虑累计概率达到此值的令牌 |
top_k | integer | 否 | - | ≥1 | 仅从概率最高的k个令牌中采样 |
presence_penalty | float32 | 否 | 0.0 | [-2.0, 2.0] | 存在惩罚。正值惩罚已出现的令牌,鼓励新内容 |
frequency_penalty | float32 | 否 | 0.0 | [-2.0, 2.0] | 频率惩罚。正值惩罚频繁出现的令牌。个别模型不支持或范围不同 |
repetition_penalty | float32 | 否 | 1.0 | [0.0, 2.0] | 重复惩罚。>1.0时减少重复内容。个别模型不支持或范围不同 |
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
thinking | ThinkType | 否 | 思维链配置,控制模型的推理过程显示,"thinking": {"type":"enabled", "budget_tokens":160}不同kimi版本会有差异 |
reasoning_effort | string | 否 | 推理强度控制,如:"low", "medium", "high",在大部分模型上,这两个思考参数都可以使用 |
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
tools | FunctionTools | 否 | 可供模型调用的工具定义列表 |
tool_choice | interface{} | 否 | 工具调用策略。 可选值: - "none": 不调用工具- "auto": 由模型决定- "required": 必须调用工具- 对象: 指定具体工具 |
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
image_config | ImageConfig | 否 | 图像输入配置,用于多模态模型处理图像 |
response_format | ResponseFormat | 否 | 响应格式控制,如:{"type": "json_object"} 或 {"type": "text"} |
{
"model": "moonshotai/kimi-k2.6",
"messages": [
{"role": "system", "content": "你是一个有帮助的助手"},
{"role": "user", "content": "你好,今天天气怎么样?"}
],
"temperature": 0.7,
"max_tokens": 500
}{
"model": "moonshotai/kimi-k2.6",
"messages": [
{"role": "user", "content": "查询北京的天气"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}{
"model": "moonshotai/kimi-k2.6",
"messages": [
{"role": "user", "content": "写一首关于春天的诗"}
],
"stream": true,
"temperature": 0.8
}{
"model": "moonshotai/kimi-k2.6",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "描述这张图片"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}
],
"max_tokens": 300
}温度设置:
惩罚参数:
repetition_penalty 为 1.1-1.2presence_penalty 为 0.1-0.5长度控制:
max_tokens 设置为 500-1000工具调用:
tool_choice: "auto" 让模型自主决定tool_choice: "required"常见错误码:
400: 参数验证失败401: 认证失败429: 速率限制500: 服务器内部错误建议实现重试逻辑和适当的错误处理机制。
这篇文档有帮助吗?
正在加载反馈服务…