Kimi 长思考模型 API 正式发布

7 min read

kimi-thinking-preview 模型是月之暗面提供的具有多模态推理能力和通用推理能力的多模态思考模型,它擅长深度推理,帮助解决更多更难的事情,当你遇到难解的代码问题、数学问题、工作问题时,都可以找 kimi-thinking-preview 模型来帮忙。

使用模型

kimi-thinking-preview 模型是目前最新的 k 系列思考模型,你可以简单地通过更换 model 来使用它:

$ curl https://api.moonshot.cn/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $MOONSHOT_API_KEY" \
    -d '{
        "model": "kimi-thinking-preview",
        "messages": [
            {"role": "user", "content": "你好"}
        ]
   }'
{
    "id": "chatcmpl-6810567267ee141b4630dccb",
    "object": "chat.completion",
    "created": 1745901170,
    "model": "kimi-thinking-preview",
    "choices":
    [
        {
            "index": 0,
            "message":
            {
                "role": "assistant",
                "content": "你好!😊 我是Kimi,很兴见到你!有什么可以帮你的吗?",
                "reasoning_content": "用户说“你好”,这是一句简单的问候语,没有包含复杂的信息或需求。我判断用户可能只是想开启一段对话,或者测试我的反应能力。这种情况下,我的目标是用友好且简洁方式回应,保持对话的轻松氛围,同时为后续可能的交流做好准备。\n\n我决定用“你好!😊 我是Kimi,很高兴见到你!有什么可以帮你的吗?”作为回复。这样既回应了用户的问候,又主动表达了愿意提供帮助的态度,同时通过添加情符号让语气更亲切自然。"
            },
            "finish_reason": "stop"
        }
    ],
    "usage":
    {
        "prompt_tokens": 8,
        "completion_tokens": 142,
        "total_tokens": 150
    }
}

或是通过 openai SDK:

import os
import openai
 
client = openai.Client(
    base_url="https://api.moonshot.cn/v1",
    api_key=os.getenv("MOONSHOT_API_KEY"),
)
 
stream = client.chat.completions.create(
    model="kimi-thinking-preview",
    messages=[
        {
            "role": "system",
            "content": "你是 Kimi。",
        },
        {
            "role": "user",
            "content": "请解释 1+1=2。"
        },
    ],
    max_tokens=1024*32,
    stream=True,
)
 
thinking = False
for chunk in stream:
    if chunk.choices:
        choice = chunk.choices[0]
        # 由于 openai SDK 并不支持输出思考过程,也没有表示思考过程内容的字段,因此我们无法直接通过 .reasoning_content 获取自定义的表示 kimi 推理过程的
        # reasoning_content 字段,只能通过 hasattr 和 getattr 来间接获取该字段。
        #
        # 我们先通过 hasattr 判断当前输出内容是否包含 reasoning_content 字段,如果包含,再通过 getattr 取出该字段并打印。
        if choice.delta and hasattr(choice.delta, "reasoning_content"):
            if not thinking:
                thinking = True
                print("=============开始思考=============")
            print(getattr(choice.delta, "reasoning_content"), end="")
        if choice.delta and choice.delta.content:
            if thinking:
                thinking = False
                print("\n=============思考结束=============")
            print(choice.delta.content, end="")
 

注意到,在使用 kimi-thinking-preview 模型时,我们的 API 响应中使用了 reasoning_content 字段作为模型思考内容的载体,对于 reasoning_content 字段:

多轮会话

使用 kimi-thinking-preview 进行多轮对话时,思考内容(或称推理过程)不需要放入请求模型的上下文中。我们通过如下例子说明如何正确使用 kimi-thinking-preview 进行多轮对话:

import os
import openai
 
client = openai.Client(
    base_url="https://api.moonshot.cn/v1",
    api_key=os.getenv("MOONSHOT_API_KEY"),
)
 
messages = [
    {
        "role": "system",
        "content": "你是 Kimi。",
    },
]
 
# 第一轮对话
messages.append({
    "role": "user",
    "content": "请解释 1+1=2。"
})
completion = client.chat.completions.create(
    model="kimi-thinking-preview",
    messages=messages,
    max_tokens=1024 * 32,
)
 
# 获取第一轮对话的结果
message = completion.choices[0].message
if hasattr(message, "reasoning_content"):
    print("=============开始第一次思考=============")
    print(getattr(message, "reasoning_content"))
    print("=============第一次思考结束=============")
print(message.content)
 
# 移除 message 中的 reasoning_content,并将 message 拼接到上下文中
if hasattr(message, "reasoning_content"):
    delattr(message, "reasoning_content")
messages.append(message)
 
# 第二轮对话
messages.append({
    "role": "user",
    "content": "我没听懂,再解释一遍。",
})
completion = client.chat.completions.create(
    model="kimi-thinking-preview",
    messages=messages,
    max_tokens=1024 * 32,
)
 
# 获取第二轮对话的结果
message = completion.choices[0].message
if hasattr(message, "reasoning_content"):
    print("=============开始第二次思考=============")
    print(getattr(message, "reasoning_content"))
    print("=============第二次思考结束=============")
print(message.content)
 

注:即使你不小心把 reasoning_content 字段放入上下文中,也不要过于担忧,reasoning_content 的内容不会计入 Tokens 消耗。

模型限制

kimi-thinking-preview 目前仍处于预览版阶段,仍有如下限制:

注:如果强行对 kimi-thinking-preview 启用以上特性,模型可能会输出预期之外的内容。

最佳实践

我们会提供一些关于使用 kimi-thinking-preview 的最佳实践建议,遵循这些最佳实践通常来说能提升模型使用体验:

了解更多:https://platform.moonshot.cn/docs/guide/use-kimi-thinking-preview-model (opens in a new tab)

2025 © Moonshot AI用户中心文档