解决小米 MiMo API 强制要求回传 reasoning_content 字段导致 Trae、Cursor 等客户端出现 400 Param Incorrect 报错的轻量级代理中间件。
2026年5月12日,小米 MiMo API 开放平台发布协议变更:在 Agent 类产品的多轮会话中,如果开启思考模式(Thinking Mode)且历史消息包含工具调用(tool_calls),assistant 消息必须完整回传 reasoning_content 字段,否则 API 返回 400 错误。
HTTP/1.1 400 Bad Request
{
"error": {
"message": "Param Incorrect",
"param": "The reasoning_content in the thinking mode must be passed back to the API.",
"code": "400"
}
}
受影响的客户端包括:Trae、Cursor、GitHub Copilot CLI、Roo Code、Codex、Zed、AutoGen 等。
本代理作为 Trae 与 MiMo API 之间的中间层:
Trae → MiMo Reasoning Proxy → MiMo API
↓ 拦截响应,缓存 reasoning_content
↓ 下次请求自动注入回 assistant 消息
核心逻辑:
- 拦截响应:从 MiMo 返回的 assistant 消息中提取
reasoning_content,按content + tool_calls哈希缓存 - 注入请求:当 Trae 发送后续请求时,为缺少
reasoning_content的 assistant 消息自动注入缓存值 - 降级处理:如果缓存未命中(如代理启动前的旧对话),自动剥离
tool_calls避免 400
pip install fastapi uvicorn httpxpython mimo_proxy.py默认监听 0.0.0.0:8899,上游指向 Token Plan API。
- 打开 Trae → 设置 → Models → 你的 MiMo 自定义模型
- 将 Custom Request URL 改为:
http://127.0.0.1:8899/v1/chat/completions
⚠️ 常见错误:
- ❌
http://0.0.0.0:8899/v1—0.0.0.0是监听地址,不能用来访问- ❌
https://127.0.0.1:8899/v1— https错误的,应写http- ✅
http://127.0.0.1:8899/v1— 非完整路径- ✅
http://127.0.0.1:8899/v1/chat/completions— 正确格式 如果代理部署在其他机器上,将127.0.0.1替换为该机器的 IP 地址。
编辑 mimo_proxy.py 顶部的常量:
| 参数 | 默认值 | 说明 |
|---|---|---|
MIMO_API_BASE |
https://token-plan-cn.xiaomimimo.com/v1 |
MiMo API 地址(Token Plan) |
LISTEN_HOST |
0.0.0.0 |
监听地址 |
LISTEN_PORT |
8899 |
监听端口 |
CACHE_MAX_SIZE |
2000 |
最大缓存条目数 |
CACHE_TTL |
7200 |
缓存过期时间(秒) |
如果使用按量付费 API,将 MIMO_API_BASE 改为:
https://api.xiaomimimo.com/v1
# 创建服务文件
cat > /etc/systemd/system/mimo-proxy.service << 'EOF'
[Unit]
Description=MiMo Reasoning Content Proxy
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/mimo-proxy
ExecStart=/usr/bin/python3 /opt/mimo-proxy/mimo_proxy.py
Restart=always
RestartSec=3
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
EOF
# 启动
systemctl daemon-reload
systemctl enable --now mimo-proxy
# 查看日志
journalctl -u mimo-proxy -f| 端点 | 方法 | 说明 |
|---|---|---|
/ |
GET | 状态页(含缓存大小) |
/health |
GET | 健康检查 |
/v1/models |
GET | 代理 MiMo 模型列表 |
/v1/chat/completions |
POST | 代理聊天补全(支持流式) |
/chat/completions |
POST | 同上(兼容路径) |
┌─────────┐ POST /v1/chat/completions ┌──────────┐
│ Trae │ ──────────────────────────────────→│ Proxy │
│ │ │ │
│ │ 1. 检查 assistant 消息 │ │
│ │ 有 tool_calls 但无 │ │
│ │ reasoning_content? │ │
│ │ │ │
│ │ 2a. 有缓存 → 注入 │ │
│ │ 2b. 无缓存 → 剥离 tool_calls │ │
│ │ │ │
│ │ ─────────────────────────────→ │ MiMo │
│ │ │ API │
│ │ 3. 缓存响应中的 reasoning_content │ │
│ │ ←───────────────────────────────── │ │
│ │ │ │
└─────────┘ └──────────┘
- 缓存基于内存,重启后丢失(新对话会自动重建)
- 降级处理(剥离 tool_calls)会导致模型丢失工具调用的上下文
- 仅支持 OpenAI 兼容的
/v1/chat/completions端点
我在用 MiMo 开放平台体验 小米顶尖模型 MiMo V2.5等 ,通过我的邀请码注册为新用户,即得 ¥10 API 体验金。邀请码:B8DMC5。注册:https://platform.xiaomimimo.com?ref=B8DMC5(注册后点控制台左下方入口填入,体验金40天有效)
MIT