":{"type":"invalid_request_error","message":"`top_p` must be greater than or equ...

2026年03月16日 22:43 状态: processing

🚨 错误信息

错误:模型 claude-sonnet-4-6-thinking: bad response status code 400, message: `top_p` must be greater than or equal to 0.95 or unset when thinking is enabled. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking (tid: 2026031614423251034065311501733), body: {"error":{"type":"invalid_request_error","message":"`top_p` must be greater than or equal to 0.95 or unset when thinking is enabled. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking (tid: 2026031614423251034065311501733)"},"type":"error"}

🤖 AI解决方案

报错分析报告

1.错误翻译


``
原文:
top_p must be greater than or equal to 0.95 or unset when thinking is enabled.
译文:当启用思考(thinking)功能时,
top_p 参数必须大于等于 0.95 或未设置。
`

2.原因分析


  • 根本原因:调用 claude-sonnet-4-6-thinking 模型时,启用了「扩展思考」功能,但传入的 top_p 参数值小于 0.95 且未被移除。

  • 发生位置:模型请求的参数字段 top_p 配置不符合扩展思考的要求。
  • 3.解决方案


    调整
    top_p 参数为 ≥0.95 或直接移除该参数(unset):
    python

    示例:Python API调用修复(以requests为例)


    import requests

    api_url = "https://api.dmxapi.com/v1/chat/completions"
    headers = {"Authorization": "Bearer YOUR_API_KEY"}
    payload = {
    "model": "claude-sonnet-4-6-thinking",
    "messages": [{"role": "user", "content": "你的问题"}],
    "thinking": {"enabled": True}, # 启用扩展思考
    # 方案1:设置top_p≥0.95
    "top_p": 0.95,
    # 方案2(推荐):直接移除top_p参数(注释或删除该行)
    # "top_p": 0.8 # 原错误配置(需删除)
    }

    response = requests.post(api_url, headers=headers, json=payload)

    4. 预防措施


  • 调用带「扩展思考」的模型前,优先查阅官方文档(如报错中的链接),确认参数约束。

  • 参数校验脚本或IDE插件(如VS Code的REST Client)预验证请求体,避免非法值。
  • ---
    :修复后需重新发起请求,确保
    top_p` 符合要求。