@wengine-ai/claude-code-router-next 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +389 -340
  2. package/dist/cli.js +251 -251
  3. package/dist/index.html +19 -21
  4. package/package.json +3 -6
package/README.md CHANGED
@@ -1,57 +1,58 @@
1
1
  ![](blog/images/claude-code-router-img.png)
2
2
 
3
- [![](https://img.shields.io/badge/%F0%9F%87%A8%F0%9F%87%B3-%E4%B8%AD%E6%96%87%E7%89%88-ff0000?style=flat)](README_zh.md)
4
- [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white)](https://discord.gg/rdftVMaUcS)
5
- [![](https://img.shields.io/github/license/musistudio/claude-code-router)](https://github.com/musistudio/claude-code-router/blob/main/LICENSE)
3
+ **[🇨🇳 中文文档](README.md)** | **[🇬🇧 English](README_en.md)** | [![npm version](https://badge.fury.io/js/@wengine-ai_claude-code-router-next.svg)](https://www.npmjs.com/package/@wengine-ai/claude-code-router-next)
4
+
5
+ > **说明**:原版 [claude-code-router](https://github.com/musistudio/claude-code-router) 仓库已不再活跃维护。本项目是基于原仓库 fork 的社区活跃版本,持续进行 Bug 修复、功能开发和长期维护。
6
6
 
7
7
  <hr>
8
8
 
9
- > [Progressive Disclosure of Agent Tools from the Perspective of CLI Tool Style](/blog/en/progressive-disclosure-of-agent-tools-from-the-perspective-of-cli-tool-style.md)
9
+ > [CLI工具风格看工具渐进式披露](/blog/zh/从CLI工具风格看工具渐进式披露.md)
10
10
 
11
- > A powerful tool to route Claude Code requests to different models and customize any request.
11
+ > 一款强大的工具,可将 Claude Code 请求路由到不同的模型,并自定义任何请求。
12
12
 
13
13
  ![](blog/images/claude-code.png)
14
14
 
15
- ## ✨ Features
16
15
 
17
- - **Model Routing**: Route requests to different models based on your needs (e.g., background tasks, thinking, long context).
18
- - **Multi-Provider Support**: Supports various model providers like OpenRouter, DeepSeek, Ollama, Gemini, Volcengine, and SiliconFlow.
19
- - **Request/Response Transformation**: Customize requests and responses for different providers using transformers.
20
- - **Dynamic Model Switching**: Switch models on-the-fly within Claude Code using the `/model` command.
21
- - **CLI Model Management**: Manage models and providers directly from the terminal with `ccr model`.
22
- - **GitHub Actions Integration**: Trigger Claude Code tasks in your GitHub workflows.
23
- - **Plugin System**: Extend functionality with custom transformers.
16
+ ## 功能
17
+
18
+ - **模型路由**: 根据您的需求将请求路由到不同的模型(例如,后台任务、思考、长上下文)。
19
+ - **多提供商支持**: 支持 OpenRouter、DeepSeek、Ollama、Gemini、Volcengine SiliconFlow 等各种模型提供商。
20
+ - **请求/响应转换**: 使用转换器为不同的提供商自定义请求和响应。
21
+ - **动态模型切换**: Claude Code 中使用 `/model` 命令动态切换模型。
22
+ - **GitHub Actions 集成**: 在您的 GitHub 工作流程中触发 Claude Code 任务。
23
+ - **用量统计与限额监控**: 追踪请求的 Token 数、缓存命中率、首 Token 延迟 (TTFT) 和生成速度,并实时展示主流服务商(如智谱、Qwen 等)的限额使用情况。
24
+ - **插件系统**: 使用自定义转换器扩展功能。
24
25
 
25
- ## 🚀 Getting Started
26
+ ## 🚀 快速入门
26
27
 
27
- ### 1. Installation
28
+ ### 1. 安装
28
29
 
29
- You can install Claude Code Router either from the npm registry or directly from this GitHub repository for the latest development version.
30
+ 您可以从 npm 官方仓库安装 Claude Code Router,或者直接从本 GitHub 仓库安装以获取最新的开发版本。
30
31
 
31
- #### Option A: Install from npm registry (Stable)
32
+ #### 选项 A:从 npm 官方仓库安装(稳定版)
32
33
 
33
- First, ensure you have [Claude Code](https://docs.anthropic.com/en/docs/claude-code/quickstart) installed:
34
+ 首先,请确保您已安装 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/quickstart)
34
35
 
35
36
  ```shell
36
37
  npm install -g @anthropic-ai/claude-code
37
38
  ```
38
39
 
39
- Then, install Claude Code Router:
40
+ 然后,安装 Claude Code Router
40
41
 
41
42
  ```shell
42
- npm install -g claude-code-router-next
43
+ npm install -g @wengine-ai/claude-code-router-next
43
44
  ```
44
45
 
45
- #### Option B: Install from GitHub (Latest Development Version)
46
+ #### 选项 B:从 GitHub 安装(最新开发版)
46
47
 
47
- If you want to use the latest features and bug fixes directly from the source code:
48
+ 如果您想直接使用源码中的最新功能和修复:
48
49
 
49
- 1. **Uninstall the current version first** (to prevent command conflicts):
50
+ 1. **先卸载已安装的全局版本**(以避免指令冲突):
50
51
  ```shell
51
- npm uninstall -g claude-code-router-next @musistudio/claude-code-router @wengine-ai/claude-code-router
52
+ npm uninstall -g @wengine-ai/claude-code-router-next @musistudio/claude-code-router @wengine-ai/claude-code-router
52
53
  ```
53
54
 
54
- 2. **Clone and link locally** (recommended for developers):
55
+ 2. **克隆本仓库并在本地进行 Link**(推荐开发者使用):
55
56
  ```shell
56
57
  git clone https://github.com/xiaoliu10/claude-code-router-next.git
57
58
  cd claude-code-router-next
@@ -60,67 +61,46 @@ If you want to use the latest features and bug fixes directly from the source co
60
61
  npm link
61
62
  ```
62
63
 
63
- *Alternatively, install directly from GitHub globally:*
64
+ *或者直接从 GitHub 进行全局安装:*
64
65
  ```shell
65
66
  npm install -g github:xiaoliu10/claude-code-router-next
66
67
  ```
67
68
 
68
- #### 🔄 Migrating from the Official Upstream (@musistudio/claude-code-router)
69
+ #### 🔄 从官方原版社区版迁移 (@musistudio/claude-code-router)
69
70
 
70
- If you are currently using the upstream community version `@musistudio/claude-code-router` and want to switch to this repository's version (`claude-code-router-next`) for advanced features (e.g. enhanced token-limit UI bars, DeepSeek thinking compatibilities, active health probes):
71
+ 如果您当前正在使用官方原版社区版本 `@musistudio/claude-code-router` 或之前的版本 `@wengine-ai/claude-code-router`,希望切换到 `@wengine-ai/claude-code-router-next`:
71
72
 
72
- 1. **Uninstall the upstream community version**:
73
+ 1. **先卸载旧版本**:
73
74
  ```shell
74
- npm uninstall -g @musistudio/claude-code-router
75
+ npm uninstall -g @musistudio/claude-code-router @wengine-ai/claude-code-router
75
76
  ```
76
77
 
77
- 2. **Install this version**:
78
+ 2. **安装本仓库增强版本**:
78
79
  ```shell
79
- npm install -g claude-code-router-next
80
+ npm install -g @wengine-ai/claude-code-router-next
80
81
  ```
81
82
 
82
- ### 2. Configuration
83
-
84
- Create and configure your `~/.claude-code-router/config.json` file. For more details, you can refer to `config.example.json`.
85
-
86
- The `config.json` file has several key sections:
83
+ > **说明**:卸载旧包**不会影响**您已有的配置文件 `~/.claude-code-router/config.json`,新版本会自动读取原有配置。
87
84
 
88
- - **`PROXY_URL`** (optional): You can set a proxy for API requests, for example: `"PROXY_URL": "http://127.0.0.1:7890"`.
89
- - **`LOG`** (optional): You can enable logging by setting it to `true`. When set to `false`, no log files will be created. Default is `true`.
90
- - **`LOG_LEVEL`** (optional): Set the logging level. Available options are: `"fatal"`, `"error"`, `"warn"`, `"info"`, `"debug"`, `"trace"`. Default is `"debug"`.
91
- - **Logging Systems**: The Claude Code Router uses two separate logging systems:
92
- - **Server-level logs**: HTTP requests, API calls, and server events are logged using pino in the `~/.claude-code-router/logs/` directory with filenames like `ccr-*.log`
93
- - **Application-level logs**: Routing decisions and business logic events are logged in `~/.claude-code-router/claude-code-router.log`
94
- - **`APIKEY`** (optional): You can set a secret key to authenticate requests. When set, clients must provide this key in the `Authorization` header (e.g., `Bearer your-secret-key`) or the `x-api-key` header. Example: `"APIKEY": "your-secret-key"`.
95
- - **`HOST`** (optional): You can set the host address for the server. If `APIKEY` is not set, the host will be forced to `127.0.0.1` for security reasons to prevent unauthorized access. Example: `"HOST": "0.0.0.0"`.
96
- - **`NON_INTERACTIVE_MODE`** (optional): When set to `true`, enables compatibility with non-interactive environments like GitHub Actions, Docker containers, or other CI/CD systems. This sets appropriate environment variables (`CI=true`, `FORCE_COLOR=0`, etc.) and configures stdin handling to prevent the process from hanging in automated environments. Example: `"NON_INTERACTIVE_MODE": true`.
85
+ ### 2. 配置
97
86
 
98
- - **`Providers`**: Used to configure different model providers.
99
- - **`Router`**: Used to set up routing rules. `default` specifies the default model, which will be used for all requests if no other route is configured.
100
- - **`API_TIMEOUT_MS`**: Specifies the timeout for API calls in milliseconds.
87
+ 创建并配置您的 `~/.claude-code-router/config.json` 文件。有关更多详细信息,您可以参考 `config.example.json`。
101
88
 
102
- #### Environment Variable Interpolation
89
+ `config.json` 文件有几个关键部分:
90
+ - **`PROXY_URL`** (可选): 您可以为 API 请求设置代理,例如:`"PROXY_URL": "http://127.0.0.1:7890"`。
91
+ - **`LOG`** (可选): 您可以通过将其设置为 `true` 来启用日志记录。当设置为 `false` 时,将不会创建日志文件。默认值为 `true`。
92
+ - **`LOG_LEVEL`** (可选): 设置日志级别。可用选项包括:`"fatal"`、`"error"`、`"warn"`、`"info"`、`"debug"`、`"trace"`。默认值为 `"debug"`。
93
+ - **日志系统**: Claude Code Router 使用两个独立的日志系统:
94
+ - **服务器级别日志**: HTTP 请求、API 调用和服务器事件使用 pino 记录在 `~/.claude-code-router/logs/` 目录中,文件名类似于 `ccr-*.log`
95
+ - **应用程序级别日志**: 路由决策和业务逻辑事件记录在 `~/.claude-code-router/claude-code-router.log` 文件中
96
+ - **`APIKEY`** (可选): 您可以设置一个密钥来进行身份验证。设置后,客户端请求必须在 `Authorization` 请求头 (例如, `Bearer your-secret-key`) 或 `x-api-key` 请求头中提供此密钥。例如:`"APIKEY": "your-secret-key"`。
97
+ - **`HOST`** (可选): 您可以设置服务的主机地址。如果未设置 `APIKEY`,出于安全考虑,主机地址将强制设置为 `127.0.0.1`,以防止未经授权的访问。例如:`"HOST": "0.0.0.0"`。
98
+ - **`NON_INTERACTIVE_MODE`** (可选): 当设置为 `true` 时,启用与非交互式环境(如 GitHub Actions、Docker 容器或其他 CI/CD 系统)的兼容性。这会设置适当的环境变量(`CI=true`、`FORCE_COLOR=0` 等)并配置 stdin 处理,以防止进程在自动化环境中挂起。例如:`"NON_INTERACTIVE_MODE": true`。
99
+ - **`Providers`**: 用于配置不同的模型提供商。
100
+ - **`Router`**: 用于设置路由规则。`default` 指定默认模型,如果未配置其他路由,则该模型将用于所有请求。
101
+ - **`API_TIMEOUT_MS`**: API 请求超时时间,单位为毫秒。
103
102
 
104
- Claude Code Router supports environment variable interpolation for secure API key management. You can reference environment variables in your `config.json` using either `$VAR_NAME` or `${VAR_NAME}` syntax:
105
-
106
- ```json
107
- {
108
- "OPENAI_API_KEY": "$OPENAI_API_KEY",
109
- "GEMINI_API_KEY": "${GEMINI_API_KEY}",
110
- "Providers": [
111
- {
112
- "name": "openai",
113
- "api_base_url": "https://api.openai.com/v1/chat/completions",
114
- "api_key": "$OPENAI_API_KEY",
115
- "models": ["gpt-5", "gpt-5-mini"]
116
- }
117
- ]
118
- }
119
- ```
120
-
121
- This allows you to keep sensitive API keys in environment variables instead of hardcoding them in configuration files. The interpolation works recursively through nested objects and arrays.
122
-
123
- Here is a comprehensive example:
103
+ 这是一个综合示例:
124
104
 
125
105
  ```json
126
106
  {
@@ -239,330 +219,301 @@ Here is a comprehensive example:
239
219
  }
240
220
  ```
241
221
 
242
- ### 🔑 API Key / Token Guide
222
+ ### 🔑 阿里云百炼用量 Token (Cookie) 获取引导
243
223
 
244
- To use the router, you need to acquire API Keys from your preferred LLM providers. Below are guides for some popular providers:
224
+ 如果您想让 Claude Code Router 的后台 Web UI 实时拉取并可视化展示您的 **Qwen Coding Plan(Qwen 编程时限套餐)** 剩余用量额度条,您需要获取控制台的浏览器 `Cookie` 作为 `quotaToken` 填入配置:
245
225
 
246
- #### 1. Zhipu AI (BigModel / GLM CODING PLAN)
247
- * **Platform**: Zhipu BigModel Platform (sponsored partner)
248
- * **Link**: [Zhipu AI BigModel Platform](https://www.bigmodel.cn/claude-code?ic=RRVJPB5SII) (Use this referral link for a 10% discount on GLM CODING PLAN)
249
- * **Acquisition Method**:
250
- 1. Register and log in using the link above.
251
- 2. Go to the top-right **Console** -> **API Keys**.
252
- 3. Copy your API Key.
226
+ 1. 登录 [阿里云百炼控制台](https://bailian.console.aliyun.com/)
227
+ 2. 按键盘 `F12` 打开浏览器开发者工具,并切换到 **Network (网络)** 标签页。
228
+ 3. 点击页面用量模块右上角的 **用量刷新**(旋转循环箭头)按钮。
229
+ 4. 在左侧网络请求列表中,找到一个以 `api.json?action=BroadScope...` 开头的接口调用请求并点击。
230
+ 5. 在右侧 **Headers (标头)** **Request Headers (请求头)** 中找到 **`Cookie`** 这一项,将其右侧的完整超长内容复制下来。
231
+ 6. 在您的 `config.json` 中,将这个 cookie 填入阿里云 provider 下的 **`quotaToken`** 属性中即可!
253
232
 
254
- GLM CODING PLAN quota information is fetched with this API Key, so you no longer need to configure a web token or `quotaToken`.
233
+ ![阿里云用量 Cookie 获取方式](blog/images/aliyun-quota-auth.png)
255
234
 
256
- #### 2. Alibaba Cloud (DashScope / Bailian / Qwen-Coder)
257
- * **Platform**: Alibaba Cloud Bailian (highly capable Qwen-Coder models)
258
- * **Link**: [Alibaba Cloud Bailian Console](https://bailian.console.aliyun.com/)
259
- * **Acquisition Methods**:
260
- * **Method A: Standard Developer API Key (For Request Routing)**
261
- 1. Log in to Alibaba Cloud and enable the "Bailian" model service.
262
- 2. Go to the Bailian Console, click on your **profile icon** in the top-right corner.
263
- 3. Click on **API-KEY** in the dropdown.
264
- 4. Click **Create New API-KEY** and copy the generated key.
265
- * **Method B: Aliyun Console Cookie (For Quota Visualization in UI)**
266
- If you want the Claude Code Router UI to fetch and display your monthly **Qwen Coding Plan** quota progress bars, you need to configure your console session `Cookie` as `quotaToken` in your configuration:
267
- 1. Log in to the [Alibaba Cloud Bailian Console](https://bailian.console.aliyun.com/).
268
- 2. Open your browser's Developer Tools (F12) and switch to the **Network** tab.
269
- 3. Click the **Refresh** (用量刷新) button on the console's usage cards.
270
- 4. Look for an API request starting with `api.json?action=BroadScope...` in the network log.
271
- 5. Select the request, find the **`Cookie`** header under **Request Headers**, and copy its entire value.
272
- 6. Paste this copied cookie string as the **`quotaToken`** property inside the Alibaba Cloud provider block in your `config.json`.
235
+ 配置成功后,Web UI Provider 列表中将会实时展示您的套餐剩余用量额度条与刷新状态:
273
236
 
274
- ![Alibaba Cloud Quota Cookie Acquisition](blog/images/aliyun-quota-auth.png)
237
+ ![阿里云用量额度条展示](blog/images/aliyun-quota-display.png)
275
238
 
276
- ### 3. Running Claude Code with the Router
239
+ ### 3. 使用 Router 运行 Claude Code
277
240
 
278
- Start Claude Code using the router:
241
+ 使用 router 启动 Claude Code
279
242
 
280
243
  ```shell
281
244
  ccr code
282
245
  ```
283
246
 
284
- > **Note**: After modifying the configuration file, you need to restart the service for the changes to take effect:
285
- >
247
+ > **注意**: 修改配置文件后,需要重启服务使配置生效:
286
248
  > ```shell
287
249
  > ccr restart
288
250
  > ```
289
251
 
290
- ### 4. UI Mode
252
+ ### 4. UI 模式
291
253
 
292
- For a more intuitive experience, you can use the UI mode to manage your configuration:
254
+ 为了获得更直观的体验,您可以使用 UI 模式来管理您的配置:
293
255
 
294
256
  ```shell
295
257
  ccr ui
296
258
  ```
297
259
 
298
- This will open a web-based interface where you can easily view and edit your `config.json` file.
260
+ 这将打开一个基于 Web 的界面,您可以在其中轻松查看和编辑您的 `config.json` 文件。
299
261
 
300
262
  ![UI](/blog/images/ui.png)
301
263
 
302
- #### Usage Statistics
264
+ #### 用量统计
265
+
266
+ 仪表盘在主页面底部内置了**用量统计**面板。当您的请求通过 Claude Code Router 进行路由时,系统会自动收集用量记录并在 UI 界面中展示。
303
267
 
304
- The dashboard includes a built-in **Usage Statistics** panel at the bottom of the main page. Once your requests are routed through Claude Code Router, usage records are collected automatically and displayed in the UI.
268
+ 您可以使用它来查看:
305
269
 
306
- You can use it to view:
270
+ - 总请求数
271
+ - 输入和输出 Token 数
272
+ - 平均首 Token 延迟 (TTFT)
273
+ - 平均生成速度 (Tokens/秒)
274
+ - 请求成功率
275
+ - 每日用量图表
276
+ - 支持筛选和分页的详细请求历史记录
307
277
 
308
- - Total requests
309
- - Input and output tokens
310
- - Average TTFT
311
- - Average generation speed
312
- - Success rate
313
- - Daily usage chart
314
- - Detailed request records with filters and pagination
278
+ ![用量统计](/blog/images/usage-statistics.png)
315
279
 
316
- How to use it:
280
+ 如何使用:
317
281
 
318
- 1. Start the router service with `ccr start`
319
- 2. Open the UI with `ccr ui`
320
- 3. Send requests through Claude Code Router, for example with `ccr code`
321
- 4. Return to the main dashboard and check the **Usage Statistics** panel
282
+ 1. 使用 `ccr start` 启动路由器服务
283
+ 2. 使用 `ccr ui` 打开 Web 界面
284
+ 3. 通过 Claude Code Router 发送请求(例如使用 `ccr code`)
285
+ 4. 返回主仪表盘,查看**用量统计**面板
322
286
 
323
- Usage data is stored in:
287
+ 用量数据保存在:
324
288
 
325
289
  ```shell
326
290
  ~/.claude-code-router/data/usage.jsonl
327
291
  ```
328
292
 
329
- You can also filter records by date range, provider, model, and scenario directly in the UI.
330
-
331
- If the `token-speed` plugin is enabled, the panel will also show TTFT and tokens-per-second metrics. Without that plugin, token counts and request statistics still work, but TTFT and speed may appear as `-`.
332
-
333
- For API-based access, Claude Code Router also provides:
334
-
335
- - `GET /api/usage` — paginated records with summary
336
- - `GET /api/usage/summary` — summary only
337
- - `DELETE /api/usage` — clear usage data
293
+ ### 5. CLI 模型管理
338
294
 
339
- ### 5. CLI Model Management
340
-
341
- For users who prefer terminal-based workflows, you can use the interactive CLI model selector:
295
+ 对于偏好终端工作流的用户,可以使用交互式 CLI 模型选择器:
342
296
 
343
297
  ```shell
344
298
  ccr model
345
299
  ```
346
- ![](blog/images/models.gif)
347
300
 
348
- This command provides an interactive interface to:
301
+ 该命令提供交互式界面来:
349
302
 
350
- - View current configuration:
351
- - See all configured models (default, background, think, longContext, webSearch, image)
352
- - Switch models: Quickly change which model is used for each router type
353
- - Add new models: Add models to existing providers
354
- - Create new providers: Set up complete provider configurations including:
355
- - Provider name and API endpoint
356
- - API key
357
- - Available models
358
- - Transformer configuration with support for:
359
- - Multiple transformers (openrouter, deepseek, gemini, etc.)
360
- - Transformer options (e.g., maxtoken with custom limits)
361
- - Provider-specific routing (e.g., OpenRouter provider preferences)
303
+ - 查看当前配置
304
+ - 查看所有配置的模型(defaultbackgroundthinklongContextwebSearchimage
305
+ - 切换模型:快速更改每个路由器类型使用的模型
306
+ - 添加新模型:向现有提供商添加模型
307
+ - 创建新提供商:设置完整的提供商配置,包括:
308
+ - 提供商名称和 API 端点
309
+ - API 密钥
310
+ - 可用模型
311
+ - Transformer 配置,支持:
312
+ - 多个转换器(openrouterdeepseekgemini 等)
313
+ - Transformer 选项(例如,带自定义限制的 maxtoken
314
+ - 特定于提供商的路由(例如,OpenRouter 提供商偏好)
362
315
 
363
- The CLI tool validates all inputs and provides helpful prompts to guide you through the configuration process, making it easy to manage complex setups without editing JSON files manually.
316
+ CLI 工具验证所有输入并提供有用的提示来引导您完成配置过程,使管理复杂的设置变得容易,无需手动编辑 JSON 文件。
364
317
 
365
- ### 6. Presets Management
318
+ ### 6. 预设管理
366
319
 
367
- Presets allow you to save, share, and reuse configurations easily. You can export your current configuration as a preset and install presets from files or URLs.
320
+ 预设允许您轻松保存、共享和重用配置。您可以将当前配置导出为预设,并从文件或 URL 安装预设。
368
321
 
369
322
  ```shell
370
- # Export current configuration as a preset
323
+ # 将当前配置导出为预设
371
324
  ccr preset export my-preset
372
325
 
373
- # Export with metadata
374
- ccr preset export my-preset --description "My OpenAI config" --author "Your Name" --tags "openai,production"
326
+ # 使用元数据导出
327
+ ccr preset export my-preset --description "我的 OpenAI 配置" --author "您的名字" --tags "openai,生产环境"
375
328
 
376
- # Install a preset from local directory
329
+ # 从本地目录安装预设
377
330
  ccr preset install /path/to/preset
378
331
 
379
- # List all installed presets
332
+ # 列出所有已安装的预设
380
333
  ccr preset list
381
334
 
382
- # Show preset information
335
+ # 显示预设信息
383
336
  ccr preset info my-preset
384
337
 
385
- # Delete a preset
338
+ # 删除预设
386
339
  ccr preset delete my-preset
387
340
  ```
388
341
 
389
- **Preset Features:**
390
- - **Export**: Save your current configuration as a preset directory (with manifest.json)
391
- - **Install**: Install presets from local directories
392
- - **Sensitive Data Handling**: API keys and other sensitive data are automatically sanitized during export (marked as `{{field}}` placeholders)
393
- - **Dynamic Configuration**: Presets can include input schemas for collecting required information during installation
394
- - **Version Control**: Each preset includes version metadata for tracking updates
342
+ **预设功能:**
343
+ - **导出**:将当前配置保存为预设目录(包含 manifest.json
344
+ - **安装**:从本地目录安装预设
345
+ - **敏感数据处理**:导出期间自动清理 API 密钥和其他敏感数据(标记为 `{{field}}` 占位符)
346
+ - **动态配置**:预设可以包含输入架构,用于在安装期间收集所需信息
347
+ - **版本控制**:每个预设包含版本元数据,用于跟踪更新
395
348
 
396
- **Preset File Structure:**
349
+ **预设文件结构:**
397
350
  ```
398
351
  ~/.claude-code-router/presets/
399
352
  ├── my-preset/
400
- │ └── manifest.json # Contains configuration and metadata
353
+ │ └── manifest.json # 包含配置和元数据
401
354
  ```
402
355
 
403
- ### 7. Activate Command (Environment Variables Setup)
356
+ ### 7. Activate 命令(环境变量设置)
404
357
 
405
- The `activate` command allows you to set up environment variables globally in your shell, enabling you to use the `claude` command directly or integrate Claude Code Router with applications built using the Agent SDK.
358
+ `activate` 命令允许您在 shell 中全局设置环境变量,使您能够直接使用 `claude` 命令或将 Claude Code Router 与使用 Agent SDK 构建的应用程序集成。
406
359
 
407
- To activate the environment variables, run:
360
+ 要激活环境变量,请运行:
408
361
 
409
362
  ```shell
410
363
  eval "$(ccr activate)"
411
364
  ```
412
365
 
413
- This command outputs the necessary environment variables in shell-friendly format, which are then set in your current shell session. After activation, you can:
366
+ 此命令会以 shell 友好的格式输出必要的环境变量,这些变量将在当前的 shell 会话中设置。激活后,您可以:
414
367
 
415
- - **Use `claude` command directly**: Run `claude` commands without needing to use `ccr code`. The `claude` command will automatically route requests through Claude Code Router.
416
- - **Integrate with Agent SDK applications**: Applications built with the Anthropic Agent SDK will automatically use the configured router and models.
368
+ - **直接使用 `claude` 命令**:无需使用 `ccr code` 即可运行 `claude` 命令。`claude` 命令将自动通过 Claude Code Router 路由请求。
369
+ - **与 Agent SDK 应用程序集成**:使用 Anthropic Agent SDK 构建的应用程序将自动使用配置的路由器和模型。
417
370
 
418
- The `activate` command sets the following environment variables:
371
+ `activate` 命令设置以下环境变量:
419
372
 
420
- - `ANTHROPIC_AUTH_TOKEN`: API key from your configuration
421
- - `ANTHROPIC_BASE_URL`: The local router endpoint (default: `http://127.0.0.1:3456`)
422
- - `NO_PROXY`: Set to `127.0.0.1` to prevent proxy interference
423
- - `DISABLE_TELEMETRY`: Disables telemetry
424
- - `DISABLE_COST_WARNINGS`: Disables cost warnings
425
- - `API_TIMEOUT_MS`: API timeout from your configuration
373
+ - `ANTHROPIC_AUTH_TOKEN`: 来自配置的 API 密钥
374
+ - `ANTHROPIC_BASE_URL`: 本地路由器端点(默认:`http://127.0.0.1:3456`)
375
+ - `NO_PROXY`: 设置为 `127.0.0.1` 以防止代理干扰
376
+ - `DISABLE_TELEMETRY`: 禁用遥测
377
+ - `DISABLE_COST_WARNINGS`: 禁用成本警告
378
+ - `API_TIMEOUT_MS`: 来自配置的 API 超时时间
426
379
 
427
- > **Note**: Make sure the Claude Code Router service is running (`ccr start`) before using the activated environment variables. The environment variables are only valid for the current shell session. To make them persistent, you can add `eval "$(ccr activate)"` to your shell configuration file (e.g., `~/.zshrc` or `~/.bashrc`).
380
+ > **注意**:在使用激活的环境变量之前,请确保 Claude Code Router 服务正在运行(`ccr start`)。环境变量仅在当前 shell 会话中有效。要使其持久化,您可以将 `eval "$(ccr activate)"` 添加到您的 shell 配置文件(例如 `~/.zshrc` `~/.bashrc`)中。
428
381
 
429
382
  #### Providers
430
383
 
431
- The `Providers` array is where you define the different model providers you want to use. Each provider object requires:
384
+ `Providers` 数组是您定义要使用的不同模型提供商的地方。每个提供商对象都需要:
432
385
 
433
- - `name`: A unique name for the provider.
434
- - `api_base_url`: The full API endpoint for chat completions.
435
- - `api_key`: Your API key for the provider.
436
- - `models`: A list of model names available from this provider.
437
- - `transformer` (optional): Specifies transformers to process requests and responses.
386
+ - `name`: 提供商的唯一名称。
387
+ - `api_base_url`: 聊天补全的完整 API 端点。
388
+ - `api_key`: 您提供商的 API 密钥。
389
+ - `models`: 此提供商可用的模型名称列表。
390
+ - `transformer` (可选): 指定用于处理请求和响应的转换器。
438
391
 
439
392
  #### Transformers
440
393
 
441
- Transformers allow you to modify the request and response payloads to ensure compatibility with different provider APIs.
442
-
443
- - **Global Transformer**: Apply a transformer to all models from a provider. In this example, the `openrouter` transformer is applied to all models under the `openrouter` provider.
444
- ```json
445
- {
446
- "name": "openrouter",
447
- "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
448
- "api_key": "sk-xxx",
449
- "models": [
450
- "google/gemini-2.5-pro-preview",
451
- "anthropic/claude-sonnet-4",
452
- "anthropic/claude-3.5-sonnet"
453
- ],
454
- "transformer": { "use": ["openrouter"] }
455
- }
456
- ```
457
- - **Model-Specific Transformer**: Apply a transformer to a specific model. In this example, the `deepseek` transformer is applied to all models, and an additional `tooluse` transformer is applied only to the `deepseek-chat` model.
458
-
459
- ```json
460
- {
461
- "name": "deepseek",
462
- "api_base_url": "https://api.deepseek.com/chat/completions",
463
- "api_key": "sk-xxx",
464
- "models": ["deepseek-chat", "deepseek-reasoner"],
465
- "transformer": {
466
- "use": ["deepseek"],
467
- "deepseek-chat": { "use": ["tooluse"] }
468
- }
469
- }
470
- ```
471
-
472
- - **Passing Options to a Transformer**: Some transformers, like `maxtoken`, accept options. To pass options, use a nested array where the first element is the transformer name and the second is an options object.
473
- ```json
474
- {
475
- "name": "siliconflow",
476
- "api_base_url": "https://api.siliconflow.cn/v1/chat/completions",
477
- "api_key": "sk-xxx",
478
- "models": ["moonshotai/Kimi-K2-Instruct"],
479
- "transformer": {
480
- "use": [
481
- [
482
- "maxtoken",
483
- {
484
- "max_tokens": 16384
485
- }
486
- ]
487
- ]
488
- }
489
- }
490
- ```
491
-
492
- **Available Built-in Transformers:**
493
-
494
- - `Anthropic`:If you use only the `Anthropic` transformer, it will preserve the original request and response parameters(you can use it to connect directly to an Anthropic endpoint).
495
- - `deepseek`: Adapts requests/responses for DeepSeek API.
496
- - `gemini`: Adapts requests/responses for Gemini API.
497
- - `openrouter`: Adapts requests/responses for OpenRouter API. It can also accept a `provider` routing parameter to specify which underlying providers OpenRouter should use. For more details, refer to the [OpenRouter documentation](https://openrouter.ai/docs/features/provider-routing). See an example below:
498
- ```json
499
- "transformer": {
500
- "use": ["openrouter"],
501
- "moonshotai/kimi-k2": {
394
+ Transformers 允许您修改请求和响应负载,以确保与不同提供商 API 的兼容性。
395
+
396
+ - **全局 Transformer**: 将转换器应用于提供商的所有模型。在此示例中,`openrouter` 转换器将应用于 `openrouter` 提供商下的所有模型。
397
+ ```json
398
+ {
399
+ "name": "openrouter",
400
+ "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
401
+ "api_key": "sk-xxx",
402
+ "models": [
403
+ "google/gemini-2.5-pro-preview",
404
+ "anthropic/claude-sonnet-4",
405
+ "anthropic/claude-3.5-sonnet"
406
+ ],
407
+ "transformer": { "use": ["openrouter"] }
408
+ }
409
+ ```
410
+ - **特定于模型的 Transformer**: 将转换器应用于特定模型。在此示例中,`deepseek` 转换器应用于所有模型,而额外的 `tooluse` 转换器仅应用于 `deepseek-chat` 模型。
411
+ ```json
412
+ {
413
+ "name": "deepseek",
414
+ "api_base_url": "https://api.deepseek.com/chat/completions",
415
+ "api_key": "sk-xxx",
416
+ "models": ["deepseek-chat", "deepseek-reasoner"],
417
+ "transformer": {
418
+ "use": ["deepseek"],
419
+ "deepseek-chat": { "use": ["tooluse"] }
420
+ }
421
+ }
422
+ ```
423
+
424
+ - **向 Transformer 传递选项**: 某些转换器(如 `maxtoken`)接受选项。要传递选项,请使用嵌套数组,其中第一个元素是转换器名称,第二个元素是选项对象。
425
+ ```json
426
+ {
427
+ "name": "siliconflow",
428
+ "api_base_url": "https://api.siliconflow.cn/v1/chat/completions",
429
+ "api_key": "sk-xxx",
430
+ "models": ["moonshotai/Kimi-K2-Instruct"],
431
+ "transformer": {
502
432
  "use": [
503
433
  [
504
- "openrouter",
434
+ "maxtoken",
505
435
  {
506
- "provider": {
507
- "only": ["moonshotai/fp8"]
508
- }
436
+ "max_tokens": 16384
509
437
  }
510
438
  ]
511
439
  ]
512
440
  }
513
441
  }
514
- ```
515
- - `groq`: Adapts requests/responses for groq API.
516
- - `maxtoken`: Sets a specific `max_tokens` value.
517
- - `tooluse`: Optimizes tool usage for certain models via `tool_choice`.
518
- - `gemini-cli` (experimental): Unofficial support for Gemini via Gemini CLI [gemini-cli.js](https://gist.github.com/musistudio/1c13a65f35916a7ab690649d3df8d1cd).
519
- - `reasoning`: Used to process the `reasoning_content` field.
520
- - `sampling`: Used to process sampling information fields such as `temperature`, `top_p`, `top_k`, and `repetition_penalty`.
521
- - `enhancetool`: Adds a layer of error tolerance to the tool call parameters returned by the LLM (this will cause the tool call information to no longer be streamed).
522
- - `cleancache`: Clears the `cache_control` field from requests.
523
- - `vertex-gemini`: Handles the Gemini API using Vertex authentication.
524
- - `chutes-glm` Unofficial support for GLM 4.5 model via Chutes [chutes-glm-transformer.js](https://gist.github.com/vitobotta/2be3f33722e05e8d4f9d2b0138b8c863).
525
- - `qwen-cli` (experimental): Unofficial support for qwen3-coder-plus model via Qwen CLI [qwen-cli.js](https://gist.github.com/musistudio/f5a67841ced39912fd99e42200d5ca8b).
526
- - `rovo-cli` (experimental): Unofficial support for gpt-5 via Atlassian Rovo Dev CLI [rovo-cli.js](https://gist.github.com/SaseQ/c2a20a38b11276537ec5332d1f7a5e53).
527
-
528
- **Custom Transformers:**
529
-
530
- You can also create your own transformers and load them via the `transformers` field in `config.json`.
442
+ ```
443
+
444
+ **可用的内置 Transformer:**
445
+
446
+ - `Anthropic`: 如果你只使用这一个转换器,则会直接透传请求和响应(你可以用它来接入其他支持Anthropic端点的服务商)
447
+ - `deepseek`: 适配 DeepSeek API 的请求/响应。
448
+ - `gemini`: 适配 Gemini API 的请求/响应。
449
+ - `openrouter`: 适配 OpenRouter API 的请求/响应。它还可以接受一个 `provider` 路由参数,以指定 OpenRouter 应使用哪些底层提供商。有关更多详细信息,请参阅 [OpenRouter 文档](https://openrouter.ai/docs/features/provider-routing)。请参阅下面的示例:
450
+ ```json
451
+ "transformer": {
452
+ "use": ["openrouter"],
453
+ "moonshotai/kimi-k2": {
454
+ "use": [
455
+ [
456
+ "openrouter",
457
+ {
458
+ "provider": {
459
+ "only": ["moonshotai/fp8"]
460
+ }
461
+ }
462
+ ]
463
+ ]
464
+ }
465
+ }
466
+ ```
467
+ - `groq`: 适配 groq API 的请求/响应
468
+ - `maxtoken`: 设置特定的 `max_tokens` 值。
469
+ - `tooluse`: 优化某些模型的工具使用(通过`tool_choice`参数)。
470
+ - `gemini-cli` (实验性): 通过 Gemini CLI [gemini-cli.js](https://gist.github.com/musistudio/1c13a65f35916a7ab690649d3df8d1cd) 对 Gemini 的非官方支持。
471
+ - `reasoning`: 用于处理 `reasoning_content` 字段。
472
+ - `sampling`: 用于处理采样信息字段,如 `temperature`、`top_p`、`top_k` 和 `repetition_penalty`。
473
+ - `enhancetool`: 对 LLM 返回的工具调用参数增加一层容错处理(这会导致不再流式返回工具调用信息)。
474
+ - `cleancache`: 清除请求中的 `cache_control` 字段。
475
+ - `vertex-gemini`: 处理使用 vertex 鉴权的 gemini api。
476
+ - `qwen-cli` (实验性): 通过 Qwen CLI [qwen-cli.js](https://gist.github.com/musistudio/f5a67841ced39912fd99e42200d5ca8b) 对 qwen3-coder-plus 的非官方支持。
477
+ - `rovo-cli` (experimental): 通过 Atlassian Rovo Dev CLI [rovo-cli.js](https://gist.github.com/SaseQ/c2a20a38b11276537ec5332d1f7a5e53) 对 GPT-5 的非官方支持。
478
+
479
+ **自定义 Transformer:**
480
+
481
+ 您还可以创建自己的转换器,并通过 `config.json` 中的 `transformers` 字段加载它们。
531
482
 
532
483
  ```json
533
484
  {
534
485
  "transformers": [
535
- {
536
- "path": "/User/xxx/.claude-code-router/plugins/gemini-cli.js",
537
- "options": {
538
- "project": "xxx"
486
+ {
487
+ "path": "/User/xxx/.claude-code-router/plugins/gemini-cli.js",
488
+ "options": {
489
+ "project": "xxx"
490
+ }
539
491
  }
540
- }
541
492
  ]
542
493
  }
543
494
  ```
544
495
 
545
496
  #### Router
546
497
 
547
- The `Router` object defines which model to use for different scenarios:
498
+ `Router` 对象定义了在不同场景下使用哪个模型:
548
499
 
549
- - `default`: The default model for general tasks.
550
- - `background`: A model for background tasks. This can be a smaller, local model to save costs.
551
- - `think`: A model for reasoning-heavy tasks, like Plan Mode.
552
- - `longContext`: A model for handling long contexts (e.g., > 60K tokens).
553
- - `longContextThreshold` (optional): The token count threshold for triggering the long context model. Defaults to 60000 if not specified.
554
- - `webSearch`: Used for handling web search tasks and this requires the model itself to support the feature. If you're using openrouter, you need to add the `:online` suffix after the model name.
555
- - `image` (beta): Used for handling image-related tasks (supported by CCR’s built-in agent). If the model does not support tool calling, you need to set the `config.forceUseImageAgent` property to `true`.
500
+ - `default`: 用于常规任务的默认模型。
501
+ - `background`: 用于后台任务的模型。这可以是一个较小的本地模型以节省成本。
502
+ - `think`: 用于推理密集型任务(如计划模式)的模型。
503
+ - `longContext`: 用于处理长上下文(例如,> 60K 令牌)的模型。
504
+ - `longContextThreshold` (可选): 触发长上下文模型的令牌数阈值。如果未指定,默认为 60000
505
+ - `webSearch`: 用于处理网络搜索任务,需要模型本身支持。如果使用`openrouter`需要在模型后面加上`:online`后缀。
506
+ - `image`(测试版): 用于处理图片类任务(采用CCR内置的agent支持),如果该模型不支持工具调用,需要将`config.forceUseImageAgent`属性设置为`true`。
556
507
 
557
- - You can also switch models dynamically in Claude Code with the `/model` command:
508
+ 您还可以使用 `/model` 命令在 Claude Code 中动态切换模型:
558
509
  `/model provider_name,model_name`
559
- Example: `/model openrouter,anthropic/claude-3.5-sonnet`
510
+ 示例: `/model openrouter,anthropic/claude-3.5-sonnet`
560
511
 
561
- #### Custom Router
512
+ #### 自定义路由器
562
513
 
563
- For more advanced routing logic, you can specify a custom router script via the `CUSTOM_ROUTER_PATH` in your `config.json`. This allows you to implement complex routing rules beyond the default scenarios.
514
+ 对于更高级的路由逻辑,您可以在 `config.json` 中通过 `CUSTOM_ROUTER_PATH` 字段指定一个自定义路由器脚本。这允许您实现超出默认场景的复杂路由规则。
564
515
 
565
- In your `config.json`:
516
+ 在您的 `config.json` 中配置:
566
517
 
567
518
  ```json
568
519
  {
@@ -570,74 +521,54 @@ In your `config.json`:
570
521
  }
571
522
  ```
572
523
 
573
- The custom router file must be a JavaScript module that exports an `async` function. This function receives the request object and the config object as arguments and should return the provider and model name as a string (e.g., `"provider_name,model_name"`), or `null` to fall back to the default router.
524
+ 自定义路由器文件必须是一个导出 `async` 函数的 JavaScript 模块。该函数接收请求对象和配置对象作为参数,并应返回提供商和模型名称的字符串(例如 `"provider_name,model_name"`),如果返回 `null` 则回退到默认路由。
574
525
 
575
- Here is an example of a `custom-router.js` based on `custom-router.example.js`:
526
+ 这是一个基于 `custom-router.example.js` `custom-router.js` 示例:
576
527
 
577
528
  ```javascript
578
529
  // /User/xxx/.claude-code-router/custom-router.js
579
530
 
580
531
  /**
581
- * A custom router function to determine which model to use based on the request.
532
+ * 一个自定义路由函数,用于根据请求确定使用哪个模型。
582
533
  *
583
- * @param {object} req - The request object from Claude Code, containing the request body.
584
- * @param {object} config - The application's config object.
585
- * @returns {Promise<string|null>} - A promise that resolves to the "provider,model_name" string, or null to use the default router.
534
+ * @param {object} req - 来自 Claude Code 的请求对象,包含请求体。
535
+ * @param {object} config - 应用程序的配置对象。
536
+ * @returns {Promise<string|null>} - 一个解析为 "provider,model_name" 字符串的 Promise,如果返回 null,则使用默认路由。
586
537
  */
587
538
  module.exports = async function router(req, config) {
588
- const userMessage = req.body.messages.find((m) => m.role === "user")?.content;
539
+ const userMessage = req.body.messages.find(m => m.role === 'user')?.content;
589
540
 
590
- if (userMessage && userMessage.includes("explain this code")) {
591
- // Use a powerful model for code explanation
592
- return "openrouter,anthropic/claude-3.5-sonnet";
541
+ if (userMessage && userMessage.includes('解释这段代码')) {
542
+ // 为代码解释任务使用更强大的模型
543
+ return 'openrouter,anthropic/claude-3.5-sonnet';
593
544
  }
594
545
 
595
- // Fallback to the default router configuration
546
+ // 回退到默认的路由配置
596
547
  return null;
597
548
  };
598
549
  ```
599
550
 
600
- ##### Subagent Routing
551
+ ##### 子代理路由
601
552
 
602
- For routing within subagents, you must specify a particular provider and model by including `<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>` at the **beginning** of the subagent's prompt. This allows you to direct specific subagent tasks to designated models.
553
+ 对于子代理内的路由,您必须在子代理提示词的**开头**包含 `<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>` 来指定特定的提供商和模型。这样可以将特定的子代理任务定向到指定的模型。
603
554
 
604
- **Example:**
555
+ **示例:**
605
556
 
606
557
  ```
607
558
  <CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
608
- Please help me analyze this code snippet for potential optimizations...
559
+ 请帮我分析这段代码是否存在潜在的优化空间...
609
560
  ```
610
561
 
611
562
  ## Status Line (Beta)
612
-
613
- To better monitor the status of Claude Code Router at runtime, the project includes a built-in status line tool that can be enabled from the UI.
614
-
563
+ 为了在运行时更好的查看claude-code-router的状态,claude-code-router在v1.0.40内置了一个statusline工具,你可以在UI中启用它,
615
564
  ![statusline-config.png](/blog/images/statusline-config.png)
616
565
 
617
- How to use it:
618
-
619
- 1. Open the UI with `ccr ui`
620
- 2. Enable **StatusLine** in the configuration panel
621
- 3. Save the configuration and restart the service with `ccr restart`
622
- 4. Start Claude Code with `ccr code`
623
-
624
- > The built-in status line is injected automatically when Claude Code is launched with `ccr code`.
625
-
626
- The status line supports token-related variables such as:
627
-
628
- - `{{inputTokens}}`
629
- - `{{outputTokens}}`
630
- - `{{tokenSpeed}}`
631
-
632
- This makes it possible to display input tokens, output tokens, and streaming speed directly in the terminal while requests are running.
633
-
634
- The effect is as follows:
635
-
566
+ 效果如下:
636
567
  ![statusline](/blog/images/statusline.png)
637
568
 
638
569
  ## 🤖 GitHub Actions
639
570
 
640
- Integrate Claude Code Router into your CI/CD pipeline. After setting up [Claude Code Actions](https://docs.anthropic.com/en/docs/claude-code/github-actions), modify your `.github/workflows/claude.yaml` to use the router:
571
+ Claude Code Router 集成到您的 CI/CD 管道中。在设置 [Claude Code Actions](https://docs.anthropic.com/en/docs/claude-code/github-actions) 后,修改您的 `.github/workflows/claude.yaml` 以使用路由器:
641
572
 
642
573
  ```yaml
643
574
  name: Claude Code
@@ -681,7 +612,7 @@ jobs:
681
612
 
682
613
  - name: Start Claude Code Router
683
614
  run: |
684
- nohup ~/.bun/bin/bunx claude-code-router-next@latest start &
615
+ nohup ~/.bun/bin/bunx @wengine-ai/claude-code-router-next@latest start &
685
616
  shell: bash
686
617
 
687
618
  - name: Run Claude Code
@@ -693,28 +624,146 @@ jobs:
693
624
  anthropic_api_key: "any-string-is-ok"
694
625
  ```
695
626
 
696
- > **Note**: When running in GitHub Actions or other automation environments, make sure to set `"NON_INTERACTIVE_MODE": true` in your configuration to prevent the process from hanging due to stdin handling issues.
627
+ 这种设置可以实现有趣的自动化,例如在非高峰时段运行任务以降低 API 成本。
628
+
629
+ ## 🎯 高级功能
630
+
631
+ ### 模型族映射 (Family Routing)
632
+
633
+ Claude Code Router 支持**模型族映射**,将 Claude Code 的模型分级(opus/sonnet/haiku)映射到不同服务商的模型。这实现了智能成本控制:主进程保持相同模型以最大化缓存命中,子代理可自动降级。
634
+
635
+ #### 配置示例
636
+
637
+ ```json
638
+ {
639
+ "Router": {
640
+ "enableFamilyRouting": true,
641
+ "families": {
642
+ "opus": {
643
+ "default": "智谱 Coding Plan,glm-5",
644
+ "think": "DeepSeek,deepseek-reasoner",
645
+ "longContext": "阿里云,qwen3-plus",
646
+ "webSearch": "Gemini,gemini-2.5-flash",
647
+ "fallback": {
648
+ "default": ["阿里云,glm-4", "DeepSeek,deepseek-chat"],
649
+ "think": ["阿里云,qwen-plus", "DeepSeek,deepseek-reasoner"]
650
+ }
651
+ },
652
+ "sonnet": {
653
+ "default": "OpenRouter,deepseek/deepseek-v3",
654
+ "think": "DeepSeek,deepseek-reasoner",
655
+ "fallback": {
656
+ "default": ["阿里云,qwen-turbo", "Gemini,gemini-2.0-flash"]
657
+ }
658
+ },
659
+ "haiku": {
660
+ "default": "阿里云,qwen-turbo",
661
+ "fallback": {
662
+ "default": ["Gemini,gemini-2.0-flash-lite"]
663
+ }
664
+ }
665
+ }
666
+ }
667
+ }
668
+ ```
669
+
670
+ #### 场景说明
671
+
672
+ | 场景 | 触发条件 | 说明 |
673
+ |------|----------|------|
674
+ | `default` | 默认 | 日常对话和代码生成 |
675
+ | `think` | Plan Mode | 复杂推理、架构设计 |
676
+ | `longContext` | token > 60000 | 大文件分析 |
677
+ | `webSearch` | web_search tool | 网络搜索任务 |
678
+ | `background` | 后台任务 | 自动提交、简单检查 |
679
+
680
+ ### Fallback 机制
681
+
682
+ 当主模型失败时,Router 会自动尝试 fallback 链中的备用模型,确保请求不中断。
683
+
684
+ #### 工作流程
685
+
686
+ 1. **健康检查**:每个 provider/model 维护健康状态
687
+ - `closed`(健康)→ 绿色指示器
688
+ - `open`(失败池)→ 红色指示器,自动跳过
689
+ - `half-open`(恢复中)→ 黄色指示器
690
+
691
+ 2. **失败判定**:连续 3 次失败后进入 `open` 状态
692
+
693
+ 3. **拖动排序**:UI 支持拖动 fallback 模型调整优先级,排序越靠前越先尝试
694
+
695
+ 4. **Fallback Promotion**:当主模型失败且 fallback 成功时,临时"晋升" fallback 模型(TTL 10 分钟),后续请求直接使用晋升模型,避免重复尝试失败的主模型
696
+
697
+ 5. **自动恢复**:每 5 分钟探测失败模型,成功后恢复为 `half-open`,再成功 2 次后恢复为 `closed`
698
+
699
+ ![Provider 健康状态](/blog/images/provider-health-healthy.png)
700
+
701
+ #### Fallback 配置层级
702
+
703
+ ```
704
+ family fallback → global fallback
705
+ ```
706
+
707
+ 优先使用模型族专属的 fallback 配置,其次使用全局 fallback。
708
+
709
+ ```json
710
+ {
711
+ "Router": {
712
+ "enableFallback": true,
713
+ "families": {
714
+ "opus": {
715
+ "fallback": {
716
+ "default": ["阿里云,glm-4", "DeepSeek,deepseek-chat"]
717
+ }
718
+ }
719
+ }
720
+ },
721
+ "fallback": {
722
+ "default": ["OpenRouter,deepseek/deepseek-v3", "Gemini,gemini-2.5-flash"],
723
+ "think": ["DeepSeek,deepseek-reasoner"]
724
+ }
725
+ }
726
+ ```
727
+
728
+ ### 用量统计
729
+
730
+ Router 提供完善的用量统计功能:
731
+
732
+ #### Quota 监控
697
733
 
698
- This setup allows for interesting automations, like running tasks during off-peak hours to reduce API costs.
734
+ UI 界面实时显示各服务商的额度使用情况:
699
735
 
700
- ## 📝 Further Reading
736
+ - **5h 额度**:短窗口限额(5 小时重置)
737
+ - **7d 额度**:周度限额(7 天重置)
738
+ - **重置时间**:显示下次额度重置时间
701
739
 
702
- - [Project Motivation and How It Works](blog/en/project-motivation-and-how-it-works.md)
703
- - [Maybe We Can Do More with the Router](blog/en/maybe-we-can-do-more-with-the-route.md)
704
- - [GLM-4.6 Supports Reasoning and Interleaved Thinking](blog/en/glm-4.6-supports-reasoning.md)
740
+ ![Quota 用量条](/blog/images/provider-quota-usage.png)
705
741
 
706
- ## ❤️ Support & Sponsoring
742
+ 支持的服务商:
743
+ - 智谱 GLM Coding Plan
744
+ - 阿里云 Qwen Coding Plan
745
+ - Kimi Coding Plan
746
+ - MiniMax Coding Plan
747
+ - DeepSeek
748
+ - OpenRouter
749
+ - SiliconFlow
707
750
 
708
- If you find this project helpful, please consider sponsoring its development. Your support is greatly appreciated!
751
+ #### Usage 记录
709
752
 
710
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F31GN2GM)
753
+ 每次请求都会记录详细统计信息:
711
754
 
712
- [Paypal](https://paypal.me/musistudio1999)
755
+ | 字段 | 说明 |
756
+ |------|------|
757
+ | `inputTokens` | 输入 token 数 |
758
+ | `outputTokens` | 输出 token 数 |
759
+ | `cacheReadInputTokens` | 缓存读取 token |
760
+ | `cacheCreationInputTokens` | 缓存创建 token |
761
+ | `ttft` | 首 token 时间 (ms) |
762
+ | `tokensPerSecond` | 输出速度 |
763
+ | `durationMs` | 请求耗时 |
764
+ | `status` | success / error |
713
765
 
714
- <table>
715
- <tr>
716
- <td><img src="/blog/images/alipay.jpg" width="200" alt="Alipay" /></td>
717
- <td><img src="/blog/images/wechat.jpg" width="200" alt="WeChat Pay" /></td>
718
- </tr>
719
- </table>
766
+ 数据存储位置:`~/.claude-code-router/data/usage.jsonl`
720
767
 
768
+ ## 交流群
769
+ <img src="/blog/images/wechat_group.jpg" width="200" alt="wechat_group" />