@musistudio/claude-code-router 1.0.31 → 1.0.33
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.
- package/README.md +36 -1
- package/README_zh.md +34 -1
- package/config.example.json +2 -1
- package/dist/cli.js +3825 -3624
- package/dist/index.html +52 -42
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ The `config.json` file has several key sections:
|
|
|
41
41
|
- **`LOG`** (optional): You can enable logging by setting it to `true`. The log file will be located at `$HOME/.claude-code-router.log`.
|
|
42
42
|
- **`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"`.
|
|
43
43
|
- **`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"`.
|
|
44
|
+
- **`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`.
|
|
44
45
|
|
|
45
46
|
- **`Providers`**: Used to configure different model providers.
|
|
46
47
|
- **`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.
|
|
@@ -54,6 +55,7 @@ Here is a comprehensive example:
|
|
|
54
55
|
"PROXY_URL": "http://127.0.0.1:7890",
|
|
55
56
|
"LOG": true,
|
|
56
57
|
"API_TIMEOUT_MS": 600000,
|
|
58
|
+
"NON_INTERACTIVE_MODE": false,
|
|
57
59
|
"Providers": [
|
|
58
60
|
{
|
|
59
61
|
"name": "openrouter",
|
|
@@ -261,7 +263,24 @@ Transformers allow you to modify the request and response payloads to ensure com
|
|
|
261
263
|
- `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).
|
|
262
264
|
- `deepseek`: Adapts requests/responses for DeepSeek API.
|
|
263
265
|
- `gemini`: Adapts requests/responses for Gemini API.
|
|
264
|
-
- `openrouter`: Adapts requests/responses for OpenRouter API.
|
|
266
|
+
- `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:
|
|
267
|
+
```json
|
|
268
|
+
"transformer": {
|
|
269
|
+
"use": ["openrouter"],
|
|
270
|
+
"moonshotai/kimi-k2": {
|
|
271
|
+
"use": [
|
|
272
|
+
[
|
|
273
|
+
"openrouter",
|
|
274
|
+
{
|
|
275
|
+
"provider": {
|
|
276
|
+
"only": ["moonshotai/fp8"]
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
265
284
|
- `groq`: Adapts requests/responses for groq API.
|
|
266
285
|
- `maxtoken`: Sets a specific `max_tokens` value.
|
|
267
286
|
- `tooluse`: Optimizes tool usage for certain models via `tool_choice`.
|
|
@@ -343,6 +362,17 @@ module.exports = async function router(req, config) {
|
|
|
343
362
|
};
|
|
344
363
|
```
|
|
345
364
|
|
|
365
|
+
##### Subagent Routing
|
|
366
|
+
|
|
367
|
+
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.
|
|
368
|
+
|
|
369
|
+
**Example:**
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
<CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
|
|
373
|
+
Please help me analyze this code snippet for potential optimizations...
|
|
374
|
+
```
|
|
375
|
+
|
|
346
376
|
## 🤖 GitHub Actions
|
|
347
377
|
|
|
348
378
|
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:
|
|
@@ -379,6 +409,7 @@ jobs:
|
|
|
379
409
|
cat << 'EOF' > $HOME/.claude-code-router/config.json
|
|
380
410
|
{
|
|
381
411
|
"log": true,
|
|
412
|
+
"NON_INTERACTIVE_MODE": true,
|
|
382
413
|
"OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}",
|
|
383
414
|
"OPENAI_BASE_URL": "https://api.deepseek.com",
|
|
384
415
|
"OPENAI_MODEL": "deepseek-chat"
|
|
@@ -400,6 +431,8 @@ jobs:
|
|
|
400
431
|
anthropic_api_key: "any-string-is-ok"
|
|
401
432
|
```
|
|
402
433
|
|
|
434
|
+
> **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.
|
|
435
|
+
|
|
403
436
|
This setup allows for interesting automations, like running tasks during off-peak hours to reduce API costs.
|
|
404
437
|
|
|
405
438
|
## 📝 Further Reading
|
|
@@ -413,6 +446,8 @@ If you find this project helpful, please consider sponsoring its development. Yo
|
|
|
413
446
|
|
|
414
447
|
[](https://ko-fi.com/F1F31GN2GM)
|
|
415
448
|
|
|
449
|
+
[Paypal](https://paypal.me/musistudio1999)
|
|
450
|
+
|
|
416
451
|
<table>
|
|
417
452
|
<tr>
|
|
418
453
|
<td><img src="/blog/images/alipay.jpg" width="200" alt="Alipay" /></td>
|
package/README_zh.md
CHANGED
|
@@ -38,6 +38,7 @@ npm install -g @musistudio/claude-code-router
|
|
|
38
38
|
- **`LOG`** (可选): 您可以通过将其设置为 `true` 来启用日志记录。日志文件将位于 `$HOME/.claude-code-router.log`。
|
|
39
39
|
- **`APIKEY`** (可选): 您可以设置一个密钥来进行身份验证。设置后,客户端请求必须在 `Authorization` 请求头 (例如, `Bearer your-secret-key`) 或 `x-api-key` 请求头中提供此密钥。例如:`"APIKEY": "your-secret-key"`。
|
|
40
40
|
- **`HOST`** (可选): 您可以设置服务的主机地址。如果未设置 `APIKEY`,出于安全考虑,主机地址将强制设置为 `127.0.0.1`,以防止未经授权的访问。例如:`"HOST": "0.0.0.0"`。
|
|
41
|
+
- **`NON_INTERACTIVE_MODE`** (可选): 当设置为 `true` 时,启用与非交互式环境(如 GitHub Actions、Docker 容器或其他 CI/CD 系统)的兼容性。这会设置适当的环境变量(`CI=true`、`FORCE_COLOR=0` 等)并配置 stdin 处理,以防止进程在自动化环境中挂起。例如:`"NON_INTERACTIVE_MODE": true`。
|
|
41
42
|
- **`Providers`**: 用于配置不同的模型提供商。
|
|
42
43
|
- **`Router`**: 用于设置路由规则。`default` 指定默认模型,如果未配置其他路由,则该模型将用于所有请求。
|
|
43
44
|
- **`API_TIMEOUT_MS`**: API 请求超时时间,单位为毫秒。
|
|
@@ -50,6 +51,7 @@ npm install -g @musistudio/claude-code-router
|
|
|
50
51
|
"PROXY_URL": "http://127.0.0.1:7890",
|
|
51
52
|
"LOG": true,
|
|
52
53
|
"API_TIMEOUT_MS": 600000,
|
|
54
|
+
"NON_INTERACTIVE_MODE": false,
|
|
53
55
|
"Providers": [
|
|
54
56
|
{
|
|
55
57
|
"name": "openrouter",
|
|
@@ -255,7 +257,24 @@ Transformers 允许您修改请求和响应负载,以确保与不同提供商
|
|
|
255
257
|
- `Anthropic`: 如果你只使用这一个转换器,则会直接透传请求和响应(你可以用它来接入其他支持Anthropic端点的服务商)。
|
|
256
258
|
- `deepseek`: 适配 DeepSeek API 的请求/响应。
|
|
257
259
|
- `gemini`: 适配 Gemini API 的请求/响应。
|
|
258
|
-
- `openrouter`: 适配 OpenRouter API
|
|
260
|
+
- `openrouter`: 适配 OpenRouter API 的请求/响应。它还可以接受一个 `provider` 路由参数,以指定 OpenRouter 应使用哪些底层提供商。有关更多详细信息,请参阅 [OpenRouter 文档](https://openrouter.ai/docs/features/provider-routing)。请参阅下面的示例:
|
|
261
|
+
```json
|
|
262
|
+
"transformer": {
|
|
263
|
+
"use": ["openrouter"],
|
|
264
|
+
"moonshotai/kimi-k2": {
|
|
265
|
+
"use": [
|
|
266
|
+
[
|
|
267
|
+
"openrouter",
|
|
268
|
+
{
|
|
269
|
+
"provider": {
|
|
270
|
+
"only": ["moonshotai/fp8"]
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
]
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
259
278
|
- `groq`: 适配 groq API 的请求/响应
|
|
260
279
|
- `maxtoken`: 设置特定的 `max_tokens` 值。
|
|
261
280
|
- `tooluse`: 优化某些模型的工具使用(通过`tool_choice`参数)。
|
|
@@ -337,6 +356,17 @@ module.exports = async function router(req, config) {
|
|
|
337
356
|
};
|
|
338
357
|
```
|
|
339
358
|
|
|
359
|
+
##### 子代理路由
|
|
360
|
+
|
|
361
|
+
对于子代理内的路由,您必须在子代理提示词的**开头**包含 `<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>` 来指定特定的提供商和模型。这样可以将特定的子代理任务定向到指定的模型。
|
|
362
|
+
|
|
363
|
+
**示例:**
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
<CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
|
|
367
|
+
请帮我分析这段代码是否存在潜在的优化空间...
|
|
368
|
+
```
|
|
369
|
+
|
|
340
370
|
|
|
341
371
|
## 🤖 GitHub Actions
|
|
342
372
|
|
|
@@ -374,6 +404,7 @@ jobs:
|
|
|
374
404
|
cat << 'EOF' > $HOME/.claude-code-router/config.json
|
|
375
405
|
{
|
|
376
406
|
"log": true,
|
|
407
|
+
"NON_INTERACTIVE_MODE": true,
|
|
377
408
|
"OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}",
|
|
378
409
|
"OPENAI_BASE_URL": "https://api.deepseek.com",
|
|
379
410
|
"OPENAI_MODEL": "deepseek-chat"
|
|
@@ -408,6 +439,8 @@ jobs:
|
|
|
408
439
|
|
|
409
440
|
[](https://ko-fi.com/F1F31GN2GM)
|
|
410
441
|
|
|
442
|
+
[Paypal](https://paypal.me/musistudio1999)
|
|
443
|
+
|
|
411
444
|
<table>
|
|
412
445
|
<tr>
|
|
413
446
|
<td><img src="/blog/images/alipay.jpg" width="200" alt="Alipay" /></td>
|