[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81033":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":16,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":17,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":9,"pushedAt":9,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":15,"starSnapshotCount":15,"syncStatus":14,"lastSyncTime":27,"discoverSource":28},81033,"mimo-proxy","Mintneko\u002Fmimo-proxy","Mintneko","MiMo Reasoning Content Proxy - Fixes reasoning_content field compatibility for MiMo API",null,"Python",30,6,29,2,0,1,3,45.14,"MIT License",false,"master",true,[],"2026-06-12 04:01:31","# MiMo Reasoning Content Proxy\n\n解决小米 MiMo API 强制要求回传 `reasoning_content` 字段导致 Trae、Cursor 等客户端出现 **400 Param Incorrect** 报错的轻量级代理中间件。\n\n## 问题背景\n\n2026年5月12日，小米 MiMo API 开放平台发布协议变更：在 Agent 类产品的多轮会话中，如果开启思考模式（Thinking Mode）且历史消息包含工具调用（tool_calls），assistant 消息必须完整回传 `reasoning_content` 字段，否则 API 返回 400 错误。\n\n```\nHTTP\u002F1.1 400 Bad Request\n{\n  \"error\": {\n    \"message\": \"Param Incorrect\",\n    \"param\": \"The reasoning_content in the thinking mode must be passed back to the API.\",\n    \"code\": \"400\"\n  }\n}\n```\n\n受影响的客户端包括：Trae、Cursor、GitHub Copilot CLI、Roo Code、Codex、Zed、AutoGen 等。\n\n## 解决方案\n\n本代理作为 Trae 与 MiMo API 之间的中间层：\n\n```\nTrae → MiMo Reasoning Proxy → MiMo API\n         ↓ 拦截响应，缓存 reasoning_content\n         ↓ 下次请求自动注入回 assistant 消息\n```\n\n核心逻辑：\n1. **拦截响应**：从 MiMo 返回的 assistant 消息中提取 `reasoning_content`，按 `content + tool_calls` 哈希缓存\n2. **注入请求**：当 Trae 发送后续请求时，为缺少 `reasoning_content` 的 assistant 消息自动注入缓存值\n3. **降级处理**：如果缓存未命中（如代理启动前的旧对话），自动剥离 `tool_calls` 避免 400\n\n## 快速开始\n\n### 安装依赖\n\n```bash\npip install fastapi uvicorn httpx\n```\n\n### 启动代理\n\n```bash\npython mimo_proxy.py\n```\n\n默认监听 `0.0.0.0:8899`，上游指向 Token Plan API。\n\n### 配置 Trae\n\n1. 打开 Trae → 设置 → Models → 你的 MiMo 自定义模型\n2. 将 **Custom Request URL** 改为：\n\n```\nhttp:\u002F\u002F127.0.0.1:8899\u002Fv1\u002Fchat\u002Fcompletions\n```\n\n> ⚠️ **常见错误：**\n> - ❌ `http:\u002F\u002F0.0.0.0:8899\u002Fv1` — `0.0.0.0` 是监听地址，不能用来访问\n> - ❌ `https:\u002F\u002F127.0.0.1:8899\u002Fv1` — https错误的，应写http\n> - ✅ `http:\u002F\u002F127.0.0.1:8899\u002Fv1` — 非完整路径\n> - ✅ `http:\u002F\u002F127.0.0.1:8899\u002Fv1\u002Fchat\u002Fcompletions` — 正确格式\n> 如果代理部署在其他机器上，将 `127.0.0.1` 替换为该机器的 IP 地址。\n\n## 配置\n\n编辑 `mimo_proxy.py` 顶部的常量：\n\n| 参数 | 默认值 | 说明 |\n|------|--------|------|\n| `MIMO_API_BASE` | `https:\u002F\u002Ftoken-plan-cn.xiaomimimo.com\u002Fv1` | MiMo API 地址（Token Plan） |\n| `LISTEN_HOST` | `0.0.0.0` | 监听地址 |\n| `LISTEN_PORT` | `8899` | 监听端口 |\n| `CACHE_MAX_SIZE` | `2000` | 最大缓存条目数 |\n| `CACHE_TTL` | `7200` | 缓存过期时间（秒） |\n\n如果使用按量付费 API，将 `MIMO_API_BASE` 改为：\n```\nhttps:\u002F\u002Fapi.xiaomimimo.com\u002Fv1\n```\n\n## Systemd 服务（可选）\n\n```bash\n# 创建服务文件\ncat > \u002Fetc\u002Fsystemd\u002Fsystem\u002Fmimo-proxy.service \u003C\u003C 'EOF'\n[Unit]\nDescription=MiMo Reasoning Content Proxy\nAfter=network.target\n\n[Service]\nType=simple\nWorkingDirectory=\u002Fopt\u002Fmimo-proxy\nExecStart=\u002Fusr\u002Fbin\u002Fpython3 \u002Fopt\u002Fmimo-proxy\u002Fmimo_proxy.py\nRestart=always\nRestartSec=3\nEnvironment=PYTHONUNBUFFERED=1\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\n# 启动\nsystemctl daemon-reload\nsystemctl enable --now mimo-proxy\n\n# 查看日志\njournalctl -u mimo-proxy -f\n```\n\n## API 端点\n\n| 端点 | 方法 | 说明 |\n|------|------|------|\n| `\u002F` | GET | 状态页（含缓存大小） |\n| `\u002Fhealth` | GET | 健康检查 |\n| `\u002Fv1\u002Fmodels` | GET | 代理 MiMo 模型列表 |\n| `\u002Fv1\u002Fchat\u002Fcompletions` | POST | 代理聊天补全（支持流式） |\n| `\u002Fchat\u002Fcompletions` | POST | 同上（兼容路径） |\n\n## 工作原理\n\n```\n┌─────────┐     POST \u002Fv1\u002Fchat\u002Fcompletions     ┌──────────┐\n│  Trae   │ ──────────────────────────────────→│  Proxy   │\n│         │                                     │          │\n│         │  1. 检查 assistant 消息              │          │\n│         │     有 tool_calls 但无               │          │\n│         │     reasoning_content?              │          │\n│         │                                     │          │\n│         │  2a. 有缓存 → 注入                   │          │\n│         │  2b. 无缓存 → 剥离 tool_calls        │          │\n│         │                                     │          │\n│         │     ─────────────────────────────→  │  MiMo    │\n│         │                                     │  API     │\n│         │  3. 缓存响应中的 reasoning_content   │          │\n│         │ ←─────────────────────────────────  │          │\n│         │                                     │          │\n└─────────┘                                     └──────────┘\n```\n\n## 已知限制\n\n- 缓存基于内存，重启后丢失（新对话会自动重建）\n- 降级处理（剥离 tool_calls）会导致模型丢失工具调用的上下文\n- 仅支持 OpenAI 兼容的 `\u002Fv1\u002Fchat\u002Fcompletions` 端点\n\n## 邀请码\n我在用 MiMo 开放平台体验 小米顶尖模型 MiMo V2.5等 ，通过我的邀请码注册为新用户，即得 ¥10 API 体验金。邀请码：B8DMC5。注册：https:\u002F\u002Fplatform.xiaomimimo.com?ref=B8DMC5（注册后点控制台左下方入口填入，体验金40天有效）\n\n\n## 相关链接\n\n- [小米 MiMo API 官方公告](https:\u002F\u002Fplatform.xiaomimimo.com\u002Fdocs\u002Fzh-CN\u002Fusage-guide\u002Fpassing-back-reasoning_content)\n- [LINUX DO 讨论帖](https:\u002F\u002Flinux.do\u002Ft\u002Ftopic\u002F2165444)\n- [Trae 论坛反馈](https:\u002F\u002Fforum.trae.cn\u002Ft\u002Ftopic\u002F17335)\n\n## License\n\nMIT\n","MiMo Reasoning Content Proxy 是一个轻量级代理中间件，用于解决小米 MiMo API 强制要求回传 `reasoning_content` 字段导致客户端如 Trae、Cursor 等出现 400 错误的问题。其核心功能包括拦截 MiMo API 的响应并缓存 `reasoning_content` 字段，在后续请求中自动注入该字段以确保兼容性，并在缓存未命中时通过剥离 `tool_calls` 来避免错误。此项目采用 Python 编写，利用 FastAPI 和 Uvicorn 实现高性能的 HTTP 服务。适用于需要与 MiMo API 进行多轮会话且开启思考模式的应用场景，特别是那些依赖于工具调用功能的 Agent 类产品。","2026-06-11 04:03:15","CREATED_QUERY"]