开源 · 本地路由桥接器 Open Source · Local Routing Bridge

作者Author@simonlin · GitHub

CCMimoLink

面向 cc switch + Codex 的 Xiaomi MiMo 本地路由桥接器。
不只是反向代理——主动协议适配,让你在 Codex 里无缝使用 MiMo。

A local routing bridge that brings Xiaomi MiMo to cc switch + Codex.
Not just a reverse proxy — an active protocol adapter for seamless MiMo integration.

1
配置 API KeyConfigure API Key — 在 cc switch 中填入 Xiaomi MiMo 的 API Key — Enter your Xiaomi MiMo API key in cc switch
2
启动 CCMimoLinkStart CCMimoLink — 自动接管 MiMo 路由,备份并改写 Codex 配置 — Automatically takes over the MiMo route, backs up and rewrites Codex config
3
Codex 请求走本地代理Codex routes through local proxy — Codex 发送 OpenAI 风格请求,CCMimoLink 完成协议翻译 — Codex sends OpenAI-style requests, CCMimoLink translates the protocol
4
转发至 MiMo 上游Forward to MiMo upstream — 自动携带 API Key,完成请求并返回结果 — Carries the API key, completes the request, and returns results

核心能力Key Capabilities

CCMimoLink 的核心价值在于主动协议适配,而不只是请求转发。

CCMimoLink's core value lies in active protocol adaptation, not just request forwarding.

协议适配

Protocol Adaptation

把 OpenAI 风格的 Responses 请求翻译成 MiMo chat-completions 格式,注入 instructions 为 system message。

Translates OpenAI-style Responses into MiMo chat-completions format, injecting instructions as system messages.

Tool 兼容层

Tool Compatibility

保留标准 function tool,规范化 tool_choice,过滤不兼容的 built-in tool 避免上游崩溃。

Preserves standard function tools, normalizes tool_choice, and filters incompatible built-in tools.

多轮续接

Multi-turn Continuation

通过有界内存保存 response-chain 状态,支持 previous_response_id,回放函数调用上下文。

Bounded in-memory state for response chains, supports previous_response_id and function-call replay.

流式保真

Streaming Fidelity

保留真实增量流式路径,读取 MiMo 上游流时发出 Responses 风格事件。

Preserves true incremental streaming, emitting Responses-style events from the MiMo upstream stream.

多模态回落

Multimodal Fallback

请求中带图片时,自动回落到 mimo-v2.5 保证兼容性。

Image-containing requests automatically fall back to mimo-v2.5 for compatibility.

动态模型切换

Dynamic Model Switch

纯文本请求可在 mimo-v2.5 与 mimo-v2.5-pro 之间通过环境变量或启动参数切换。

Switch text traffic between mimo-v2.5 and mimo-v2.5-pro via env vars or startup flags.

安全同步

Safe Sync

回写 Codex 配置前自动备份,限流与 429 退避处理,XML 兜底解析。

Auto-backup before config rewrite, throttling with 429 backoff, XML fallback parsing.

本地 Compact

Local Compact

对 compact 控制面请求提供本地处理,不把错误甩给上游。

Handles compact control-plane requests locally instead of letting them fail upstream.

🚀 快速开始Quick Start

1

在 cc switch 中配置 MiMo

Configure MiMo in cc switch

在 cc switch 中添加 Xiaomi MiMo provider 并填入 API Key。

Add a Xiaomi MiMo provider in cc switch and enter your API key.

2

编译

Build

go build -o ccmimolink .
3

仅同步配置(可选)

Sync only (optional)

只做配置同步,不启动代理服务:

Rewrite routes and refresh config without starting the proxy:

./ccmimolink --sync-only
4

启动代理

Run the proxy

./ccmimolink
默认地址:Default address: http://127.0.0.1:9876/v1
5

切换模型(可选)

Switch models (optional)

纯文本请求默认使用 mimo-v2.5,可通过以下方式切换到 mimo-v2.5-pro:

Text requests default to mimo-v2.5. Switch to mimo-v2.5-pro:

# 环境变量方式Environment variable
MIMO_MODEL="mimo-v2.5-pro" ./ccmimolink

# 启动参数方式Startup flag
./ccmimolink --v2.5-pro
图片请求不受影响,始终回落到 mimo-v2.5。 Image requests are unaffected and always fall back to mimo-v2.5.

🔌 支持的接口Supported Endpoints

POST /v1/responses 主接口,协议适配的核心入口 Primary endpoint — core protocol adaptation entry point
GET /v1/models 模型列表 Model listing
GET /health 健康检查 Health check
POST /v1/responses/compact 本地返回不支持的响应 Returns a local unsupported response
GET /v1/responses/{id} 获取历史响应 Retrieve a stored response by ID

⚙️ 配置项Configuration

所有运行时配置通过环境变量提供。

All runtime settings are provided via environment variables.

变量Variable 默认值Default 说明Description
MIMO_API_KEY empty MiMo 上游备用 API KeyFallback MiMo upstream API key
MIMO_BASE_URL https://token-plan-cn.xiaomimimo.com/v1 MiMo 上游地址MiMo upstream base URL
MIMO_MODEL mimo-v2.5 默认文本模型Default text model
MIMO_PROXY_PORT 9876 本地监听端口Local listen port
MIMO_PROXY_MAX_CONCURRENT 1 最大并发上游请求数Maximum concurrent upstream requests
MIMO_PROXY_MIN_INTERVAL_MS 1500 上游请求最小间隔(毫秒)Minimum delay between upstream requests (ms)
MIMO_PROXY_429_BACKOFF_MS 30000 收到 429 后的退避时间(毫秒)Backoff after upstream 429 (ms)
MIMO_PROXY_LOG ccmimolink.log 日志文件路径Log file path
MIMO_PROXY_SKIP_CC_SWITCH_SYNC false 跳过启动同步(开发调试用)Skip startup sync (for development)
CC_SWITCH_SETTINGS_PATH ~/.cc-switch/settings.json cc switch 配置文件路径Path to cc switch settings
CC_SWITCH_DB_PATH ~/.cc-switch/cc-switch.db cc switch 数据库路径Path to cc switch database
CODEX_CONFIG_PATH ~/.codex/config.toml Codex 配置文件路径Path to local Codex config

📋 运行要求Requirements

常见问题Troubleshooting

cc switch is not installed or incomplete
cc switch is not installed or incomplete
请确认以下文件存在:
~/.cc-switch/settings.json~/.cc-switch/cc-switch.db~/.codex/config.toml
Verify these files exist: ~/.cc-switch/settings.json, ~/.cc-switch/cc-switch.db, ~/.codex/config.toml
Xiaomi MiMo provider not found
Xiaomi MiMo provider not found
请先在 cc switch 中添加 Xiaomi MiMo provider。 Add a Xiaomi MiMo provider in cc switch first.
Xiaomi MiMo API key is empty
Xiaomi MiMo API key is empty
打开 cc switch,编辑 Xiaomi MiMo provider,填入 API Key。 Open cc switch, edit the Xiaomi MiMo provider, and enter the API key.
当前 provider 不是 Xiaomi MiMo
Current provider is not Xiaomi MiMo
这通常不是问题。CCMimoLink 会自动查找 Xiaomi MiMo provider 并完成同步。 This is usually fine. CCMimoLink will automatically locate the Xiaomi MiMo provider for sync.
cc switch 里的请求地址看起来不对
cc switch route still looks incorrect
再执行一次 ./ccmimolink --sync-only,然后重启 cc switch。 Run ./ccmimolink --sync-only again, then restart cc switch.
Codex 仍然使用旧路由或旧 Key
Codex still uses the old route or key
同步完成后请重启 Codex,让它重新加载配置。 Restart Codex after sync so it reloads ~/.codex/config.toml.
为什么必须重启 cc switch 和 Codex?
Why do I need to restart cc switch and Codex?
这两个应用会把 provider 配置缓存在内存里。重启后才能确保改写后的路由和新的 X-Mimo-Api-Key 生效。 Both applications cache provider configuration in memory. Restarting ensures the rewritten route and refreshed X-Mimo-Api-Key take effect.