Kimi K3.1 Pro · prompting-guide
Kimi K3.1 Pro 的 Partial Mode 要在消息末尾追加 role="assistant"、partial=True 的消息,把希望保留的文本放入 content;API 返回的内容不含这段前缀,客户端必须手动拼回。
Kimi K3.1 Pro 的 Partial Mode 要在消息末尾追加 role="assistant"、partial=True 的消息,把希望保留的文本放入 content;API 返回的内容不含这段前缀,客户端必须手动拼回。
适合的任务:固定回复开场、从已输出前缀继续生成、续写因 finish_reason="length" 截断的内容,以及保持角色口吻。
不适合的任务:把 Partial Mode 当作通用 JSON 校验器,或在未确认前缀合法性的情况下强行拼接结构化输出。
适用的模型版本:本页当前示例默认使用 kimi-k3.1-pro;其他模型(例如 kimi-k3.1-pro-highspeed)需要替换 model 并重新核对参数。
适用的客户端、Agent 或 API:Kimi API Chat Completions,以及能保留 assistant 原始字段的 OpenAI 兼容客户端。
推荐的推理档位和参数:K3.1 Pro 使用顶层 reasoning_effort,可选 low、high、max,默认 max;续写时还要保留上一轮的 reasoning_content。
下面保留原文的 Python 示例。partial=True 必须位于消息列表最后一条 assistant 消息中:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MOONSHOT_API_KEY"], # Set the MOONSHOT_API_KEY environment variable before running this example
base_url = "https://api.moonshot.ai/v1",
)
completion = client.chat.completions.create(
model = "kimi-k3.1-pro",
messages = [
{"role": "system", "content": "You are Kimi, an AI assistant provided by Moonshot AI. You are proficient in Chinese and English conversations. You provide users with safe, helpful, and accurate answers. You also reject any questions involving terrorism, racism, or explicit content. Moonshot AI is a proper noun and should not be translated."},
{"role": "user", "content": "Hello?"},
{
"partial": True, # <-- The partial parameter is used to enable Partial Mode
"role": "assistant", # <-- We add a message with role=assistant after the user's question
"content": "Dear customer, hello,", # <-- The content is "fed" to the Kimi large language model, prompting it to continue from this sentence
},
]
)
# Since the Kimi large language model continues from the "fed" sentence, we need to manually concatenate the "fed" sentence with the generated response
print("Dear customer, hello," + completion.choices[0].message.content)输出处理规则可以写成公式:
完整回复 = assistant_partial.content + completion.choices[0].message.contentAPI 只返回前缀之后的新内容;如果客户端直接展示 message.content,固定的开场文本会丢失。
当第一次请求返回 finish_reason == "length" 时,取出已经生成的 content 作为 prefix,并把同一轮返回的 reasoning_content 一并带回:
if completion.choices[0].finish_reason == "length":
prefix = completion.choices[0].message.content
reasoning_content = completion.choices[0].message.reasoning_content
continuation = client.chat.completions.create(
model="kimi-k3.1-pro",
messages=[
{"role": "user", "content": "Please recite the complete Chu Shi Biao."},
{
"role": "assistant",
"content": prefix,
"partial": True,
"reasoning_content": reasoning_content,
},
],
max_tokens=86400,
)
full_text = prefix + continuation.choices[0].message.content这是同一份输出的续写,不是重新发起一个没有上下文的请求。续写请求应保持原用户消息和已输出前缀对应;如果前缀来自另一条请求,不要把它拼入当前会话。
确认请求模型为 kimi-k3.1-pro,并使用 Kimi API Chat Completions。
在 messages 末尾追加 assistant 消息,设置 partial=True;把要强制出现的文本放进 content。
收到响应后,按“前缀 + 新内容”拼接,再交给用户或下游解析器。
若 finish_reason 为 length,检查 message.content 是否已有有效前缀,再用 Partial Mode 续写。
思考模式续写时同时回传原响应的 reasoning_content;不能只回传最终内容。
为截断续写设置足够大的 max_tokens,避免预算先耗尽在 thinking 阶段。
需要角色口吻时,可在 partial assistant 消息中加入 name;该字段也属于输出前缀的一部分。
长对话中角色开始偏离时,按原文方法重新加入 system 角色设定,再追加带 name 的 partial assistant 消息。
官方页面说明 Partial Mode 会让模型从给定文本继续生成,而不是从头回复。
官方最小示例使用 model="kimi-k3.1-pro",在用户消息后追加 partial=True、role="assistant" 和 content="Dear customer, hello,"。
官方明确要求客户端把“送入”的前缀与 API 生成内容手动连接,形成完整回复。
官方截断示例以 finish_reason == "length" 为触发条件,将 message.content 作为 prefix;续写消息保留 partial=True。
页面特别说明 thinking 会先消耗 max_tokens;若截断发生在 thinking 阶段,content 可能为空,续写会因没有前缀而从头开始。
页面写明思考模式续写要把之前返回的 reasoning_content 与前缀一起传回,并用更大的 max_tokens 确保进入 content 阶段。
官方角色示例把 name="Kelsier" 放在 partial assistant 消息中,并说明 name 是输出前缀的一部分;长对话可重新插入 system 设定来强化角色。
页面说明本页示例默认使用最新的 kimi-k3.1-pro;若改用其他模型,需要替换模型字段并调整参数。
页面 JSON-LD 的 dateModified 为 2026-10-23T20:06:32.132Z;页面没有发布日期字段,因此发布日期记为“未注明”。
页面将 JSON Mode 列为单独的指南入口,但没有规定 Partial Mode 与 JSON Mode 的组合行为、合法前缀格式或校验保证。
本稿只核对官方文档代码和说明,没有使用 API Key 发起本地请求;代码块是配置示例,不是本地实测结果。
partial=True 是 assistant 消息字段,不是写进 system prompt 或用户提示词中的自然语言指令。
reasoning_effort 是 K3.1 Pro 请求顶层字段;不要把它改写成旧模型的 thinking 配置,也不要把 reasoning_content 当成用户可见答案。
若小 max_tokens 使截断发生在 thinking 阶段,返回的 content 为空,Partial Mode 没有可续写的文本;应增大预算后重新请求。
name 能帮助固定角色身份,但不能替代 system 角色设定,也不保证长对话永远不偏离。
本页没有给出 Partial Mode 与 JSON Mode 的兼容规则。需要 JSON 输出时,应另查 JSON Mode 文档并验证前缀能否构成合法 JSON;不能从本页推断“续写后一定是可解析 JSON”。
页面只把 kimi-k3.1-pro 作为默认示例;kimi-k3.1-pro-highspeed 或其他旧模型的字段、默认值和推理行为不能直接外推。
本文没有实测成功率、延迟、token 消耗或不同 max_tokens 值的效果。
打开官方 Partial Mode 页面,确认标题为 Use Kimi API's Partial Mode,并核对页面中默认模型为 kimi-k3.1-pro。
对照“Make the model continue from a given prefix”代码块,检查 assistant 消息的 role、partial 和 content 字段位置。
对照“Complete output truncated by max_tokens”代码块,检查 finish_reason、prefix、reasoning_content 和第二次请求的 max_tokens。
若验证角色一致性,检查 name 是否位于 partial assistant 消息中,并观察客户端是否拼回前缀。
使用真实 API Key 前,先在测试环境记录请求体和返回字段;本稿未提交真实请求,因此没有本地调用结论。
Kimi API Platform 官方文档 · 原文日期: 未公开 · 编辑日期: 2026-10-24
阅读原始来源Kimi K3.1 Pro
请在上方所列环境中运行本指南。下载不会自动传入模板,也不代表账户已开放该模型。