bad_response_status_code: bad response status code 400 (request id: 202606021822...

2026年06月02日 18:24 40.41 秒 success

错误信息

18:23:01 [ws] ⇄ res ✓ sessions.list 740ms conn=8c296ffc…0c3d id=10b13937…1ac9 18:23:01 [diagnostic] lane wait exceeded: lane=session:agent:main:main waitedMs=16687 queueAhead=0 activeAhead=1 activeNow=0 queueBehind=0 18:23:04 LLM error bad_response_status_code: bad response status code 400 (request id: 20260602182249479024942s6b2drlk) 18:23:09 [ws] ⇄ res ✓ sessions.list 718ms conn=8c296ffc…0c3d id=48921db1…0a98 18:23:21 [agent/embedded] embedded run agent end: runId=f6d12a49-e58f-4e13-a6aa-f4488cce0108 isError=true model=qwen3.6-plus-cc provider=dmxapi error=LLM error bad_response_status_code: bad response status code 400 (request id: sha256:869d38e9d3c8) rawError={"error":{"type":"bad_response_status_code","message":"bad response status code 400 (request id: sha256:869d38e9d3c8)"},"type":"error"} 18:23:21 [ws] ⇄ res ✓ sessions.list 744ms conn=8c296ffc…0c3d id=a44e6006…c363 18:23:22 [ws] ⇄ res ✓ chat.history 123ms conn=8c296ffc…0c3d id=43bfbd9c…e344ser

AI 解决方案

🔍 报错分析

1. 🌐 错误翻译


原文:LLM error bad_response_status_code: bad response status code 400
译文:LLM 错误 - 错误的响应状态码: 错误的响应状态码 400

2. 🎯 原因分析


此错误表明您的应用程序在调用大语言模型(LLM)API时,从服务端收到了一个HTTP 400状态码的响应。这通常意味着发送给API的请求本身存在错误,导致服务器拒绝处理。结合日志中的 model=qwen3.6-plus-ccprovider=dmxapi,可以判断是在通过DMXAPI调用 qwen3.6-plus-cc 模型时触发的。
具体可能的原因包括:
  • 请求体(Request Body)的JSON格式错误或结构不符合API文档要求。

  • 传递了无效的参数(如错误的模型名称、不支持的参数值)。

  • 认证信息(API Key)缺失、过期或无权访问指定的模型。

  • 请求头(Headers)设置不正确,例如缺少必要的Content-Type

  • 请求的消息内容可能超出了模型的限制或包含不支持的格式。
  • 3. 💡 解决方案


    请首先检查您的代码中构造API请求的部分。以下是一个通用的、结构正确的请求示例,供您对照修改:

    # Python 示例 (使用 requests 库)
    import requests
    import json
    
    url = "https://api.dmxapi.com/v1/chat/completions" # 请替换为DMXAPI提供的准确端点
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_DMXAPI_KEY" # 替换为您的有效API Key
    }
    
    # 请求体结构,请严格对照DMXAPI或qwen3.6-plus-cc模型的文档要求
    payload = {
        "model": "qwen3.6-plus-cc", # 确保模型名称完全正确
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "你好,请介绍一下你自己。"}
        ],
        "stream": False # 根据需求设置,流式响应可能参数不同
        # 其他如 temperature, max_tokens 等参数,请参考文档添加
    }
    
    try:
        response = requests.post(url, headers=headers, json=payload)
        response.raise_for_status() # 如果状态码不是200,会抛出HTTPError
        data = response.json()
        print(data['choices'][0]['message']['content'])
    except requests.exceptions.HTTPError as e:
        print(f"请求失败,状态码: {e.response.status_code}")
        print(f"错误详情: {e.response.text}") # 打印服务端返回的完整错误信息,这是关键!
    except Exception as e:
        print(f"发生其他错误: {e}")
    

    关键修复步骤:

  • 捕获完整错误信息:像示例中一样,打印出 e.response.text。服务端通常会在400响应的Body中返回更详细的错误说明(如 "Invalid model parameter""Message content cannot be empty"),这是定位问题的直接线索。

  • 校验请求参数:仔细核对DMXAPI官方文档,确保所有参数名称、值类型、必需字段都正确。

  • 测试API连通性:使用Postman或curl等工具,用相同的Key和参数手动发送一个最简单的请求,验证接口本身是否正常。
  • 4. 🛡️ 预防措施


  • 📝 详细记录请求与响应:在代码中,特别是在测试和调试阶段,完整记录发送的请求体(去除敏感Key后)和收到的错误响应。这能极大加速问题定位。

  • 🔧 使用API调试工具:在编写代码前,先用Postman等工具成功调通API,确保获得预期的200响应,然后再将正确的请求结构迁移至代码中。

  • 💾 实现重试与降级:对于可能因瞬时网络或服务问题导致的错误,可在代码中加入带退避(backoff)的重试逻辑,提高应用的健壮性。