要做什么
kimi-k3.1-pro 是 Moonshot AI K3.1 系列在 hiapi 上的文本模型,走 OpenAI 兼容的 POST /v1/chat/completions,不走图像、视频模型用的异步 /v1/tasks。本文给出可直接复制的 curl 与 Python 请求,并覆盖流式输出、工具调用、JSON 模式,以及这个模型会拒绝的参数。文中所有请求和响应都在 2026-10-30 对线上 API 实际跑过。
前提: 在控制台拿到 API key,请求头带 Authorization: Bearer sk-<你的key>。
先核对模型 id
GET /v1/models 里有三个 Kimi 条目,id 里的版本号是点号(3.1),不是连字符:
kimi-k3
kimi-k3.1-pro
kimi-k3.1-pro-highspeed
请原样使用 kimi-k3.1-pro。模型页的 URL 也是同一个字符串。模型页标注 100 万 Token 上下文,单次最多输出 131,072 Token。
最小可跑示例
curl
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<你的key>" \
-H "Content-Type: application/json" \
-d '{
"model": "kimi-k3.1-pro",
"reasoning_effort": "low",
"max_tokens": 2000,
"messages": [{"role": "user", "content": "Reply with exactly: pong"}]
}'
实际响应:
{
"id": "chatcmpl-202610300345155364901998268d9d609feXv2A",
"object": "chat.completion",
"model": "kimi-k3.1-pro",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "pong",
"reasoning_content": "I must respond exactly pong."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 91,
"completion_tokens": 24,
"total_tokens": 115,
"completion_tokens_details": {"reasoning_tokens": 7}
}
}
Python
import requests
resp = requests.post(
"https://api.hiapi.ai/v1/chat/completions",
headers={"Authorization": "Bearer sk-<你的key>"},
json={
"model": "kimi-k3.1-pro",
"reasoning_effort": "low", # low | high | max,默认 max
"max_tokens": 2000,
"messages": [{"role": "user", "content": "Reply with exactly: pong"}],
},
timeout=180,
)
resp.raise_for_status()
choice = resp.json()["choices"][0]
if choice["finish_reason"] == "length" and not choice["message"]["content"]:
raise RuntimeError("思考用光了 max_tokens,请调大 max_tokens")
print(choice["message"]["content"])
思考始终开启,要给足 max_tokens
模型页写明思考始终开启,reasoning_effort 可选 low、high、max,默认 max。思考 Token 按输出计费,并且占用 max_tokens 额度。下面是不传 reasoning_effort(即 max)、max_tokens: 30 的实测:
{
"choices": [{"message": {"content": "", "reasoning_content": "I need answer user asks explain LRU cache in two sentences. Should be concise exactly two sentences. Should understand LRU Least Recently Used cache"}, "finish_reason": "length"}],
"usage": {"completion_tokens": 30, "completion_tokens_details": {"reasoning_tokens": 27}}
}
30 个 Token 里有 27 个花在思考上,content 返回空字符串。遇到 finish_reason: "length" 且 content 为空,应当加大预算重试,不要当作答案处理。本文所有调用的 max_tokens 都在 2000 到 3000,简单任务可以用 reasoning_effort: "low"。
流式输出
加上 "stream": true,需要用量就再加 "stream_options": {"include_usage": true}。返回是标准 SSE chat.completion.chunk 事件。思考内容先到,走 delta.reasoning_content,回答随后走 delta.content。实测的开头几行:
data: {"object":"chat.completion.chunk","model":"kimi-k3.1-pro","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"...","choices":[{"index":0,"delta":{"reasoning_content":"I"},"finish_reason":null}]}
data: {"...","choices":[{"index":0,"delta":{"reasoning_content":" need"},"finish_reason":null}]}
流末尾先是带 finish_reason: "stop" 的块,随后是 choices 为空、只含 usage 的块,最后是 data: [DONE]。如果前端只读 delta.content,思考阶段会一片空白,看上去像卡死。把 reasoning_content 渲染成"思考中"状态即可。
工具调用
函数工具使用标准的 OpenAI tools 数组:
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<你的key>" \
-H "Content-Type: application/json" \
-d '{
"model": "kimi-k3.1-pro",
"reasoning_effort": "low",
"max_tokens": 3000,
"tools": [{"type": "function", "function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
}}],
"messages": [{"role": "user", "content": "Weather in Paris?"}]
}'
实际响应(节选):
{
"index": 0,
"message": {
"role": "assistant",
"content": "",
"tool_calls": [{"index": 0, "id": "tool_GwZKfOuTH07k9in5uVABLhR3", "type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"Paris\"}"}}],
"reasoning_content": "I'll respond to user asking weather in Paris. I have tool get_weather city. Kimi will call."
},
"finish_reason": "tool_calls"
}
第二轮:回传工具结果
模型页要求多轮对话保留完整的 assistant 消息,包括 tool_calls 和 reasoning_content。我们把第一轮的整条 assistant 消息原样追加,再加一条 role: "tool" 消息,tool_call_id 对应上面的 id:
msgs = [
{"role": "user", "content": "Weather in Paris?"},
assistant_message, # 第一轮返回的完整 message,含 tool_calls 与 reasoning_content
{"role": "tool", "tool_call_id": assistant_message["tool_calls"][0]["id"],
"content": '{"city":"Paris","temp_c":14,"sky":"cloudy"}'},
]
第二轮返回 HTTP 200,finish_reason: "stop",content 为 It’s currently **14°C and cloudy** in Paris.。
另做了一个对照:同样的第二轮请求,但把 assistant 消息里的 reasoning_content 删掉再发。这次同样返回 200 和正确回答,没有报错。这只是一次单轮、单工具的样本,不能推出"可以不回传"。模型页的要求没有变,生产代码仍应原样保留完整消息,尤其是多轮、多工具的长链路。
JSON 模式
response_format: {"type": "json_object"} 实测可用:
curl https://api.hiapi.ai/v1/chat/completions \
-H "Authorization: Bearer sk-<你的key>" \
-H "Content-Type: application/json" \
-d '{"model": "kimi-k3.1-pro", "reasoning_effort": "low", "max_tokens": 3000,
"response_format": {"type": "json_object"},
"messages": [{"role": "user", "content": "Return a JSON object with keys city and country for the capital of Japan."}]}'
message.content 恰好是 {"city":"Tokyo","country":"Japan"}。模型页还列出了结构化输出(JSON Schema),本文只测了 json_object,没有测 json_schema。
会被拒绝的参数
实测碰到两种拒绝,均为 HTTP 400、invalid_request_error:
{"error":{"code":"invalid_parameter","message":"temperature: is outside allowed values","type":"invalid_request_error"}}
{"error":{"code":"invalid_parameter","message":"reasoning_effort: is outside allowed values","type":"invalid_request_error"}}
- 传
temperature: 0.3被拒。模型页说明temperature固定为 1、top_p固定为 0.95,所以直接省略。从其他厂商 SDK 迁移代码时,如果默认带了temperature,要去掉。 - 传
reasoning_effort: "medium"被拒。只能用low、high、max。
价格与 kimi-k3、highspeed 怎么选
以下数字取自 2026-10-30 的 /api/pricing(美元 / 百万 Token),随时可能调整,请以定价页为准:
| kimi-k3 | kimi-k3.1-pro | kimi-k3.1-pro-highspeed | |
|---|---|---|---|
| 输入 | 2.32 | 2.1548 | 4.3096 |
| 输出 | 11.6 | 11.2714 | 22.5426 |
| 缓存输入 | 0.232 | 0.2156 | 0.2156 |
三个 id 走同一个端点、同样的请求格式。Reply with exactly: pong 这条提示在 kimi-k3 和 kimi-k3.1-pro(reasoning_effort: "low")上都返回了 pong,所以从 kimi-k3 迁移到 kimi-k3.1-pro 只需要改 model 一个字段。我们没有对比两者的回答质量,也没有测 kimi-k3.1-pro-highspeed 的耗时,所以不对哪一档更好下结论。
可操作的判断:kimi-k3.1-pro 的输入、输出单价都略低于 kimi-k3,模型页对它的定位是编程、Agent 工具工作流和长文档,这类负载可以优先在自己的提示词上试它。kimi-k3.1-pro-highspeed 的输入、输出单价约为 kimi-k3.1-pro 的两倍,缓存输入单价相同,只有在你实测确认延迟收益值得这个价差时才有理由选它。
相关页面
常见问题
准确的模型 id 是什么? kimi-k3.1-pro,3 和 1 之间是点号,/v1/models 里可以查到。
content 为什么是空的? 思考 Token 占用 max_tokens 额度。finish_reason 为 length 且 content 为空,说明额度在思考阶段用完了。调大 max_tokens 或降低 reasoning_effort。
能设置 temperature 吗? 不能。传 temperature: 0.3 实测返回 HTTP 400,省略即可。
要用 /v1/tasks 吗? 不用。它是文本模型,走 /v1/chat/completions。





