@euraika-bert/claude-model-router 0.1.4 → 0.1.6
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 +183 -178
- package/bin/claude-model-router.mjs +5 -5
- package/files/configure.mjs +19 -19
- package/files/models-sync.mjs +1 -1
- package/files/update-check.mjs +2 -2
- package/install.ps1 +9 -9
- package/install.sh +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,71 +1,73 @@
|
|
|
1
1
|
# Claude Model Router
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A local router for macOS, Linux and Windows that adds extra models to Claude Code without replacing the built-in Claude models.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Available through `/model`, each only for the providers you have a key or login for:
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **Kimi K3.1 Pro**
|
|
9
|
-
- **Mistral Large 4**
|
|
10
|
-
- **Qwen 3.8/3.7 Max**, **DeepSeek V4 Pro**, **DeepSeek V4.1 Flash**
|
|
11
|
-
- **GPT 6 Astra**, **GPT 6.1 Terra**, **GPT 6.1 Sol**
|
|
12
|
-
- **MiniMax M3.1 Flash**
|
|
13
|
-
- **
|
|
7
|
+
- **All Claude models**, passed through to Anthropic unchanged, including new models such as **Fable 5.2** as soon as Anthropic offers them.
|
|
8
|
+
- **Kimi K3.1 Pro** with 1M context, through your existing Kimi Code OAuth login.
|
|
9
|
+
- **Mistral Large 4** and **GLM 5.3 (Mistral Hosted)** with 1M context, through a Mistral API key.
|
|
10
|
+
- **Qwen 3.8/3.7 Max**, **DeepSeek V4 Pro**, **DeepSeek V4.1 Flash** and **GLM 5.3** with 1M context, through Alibaba Cloud Bailian (token plan, region `ap-southeast-1`).
|
|
11
|
+
- **GPT 6 Astra**, **GPT 6.1 Terra**, **GPT 6.1 Sol** and **GPT 5.6 Luna** through your ChatGPT account (the Codex CLI login).
|
|
12
|
+
- **MiniMax M3.1 Flash** and **MiniMax M3** with 1M context, through a MiniMax M Plan API key.
|
|
13
|
+
- **Auto-added models** from the Mistral, Kimi and ChatGPT/Codex catalogs; see [Automatic model sync](#automatic-model-sync).
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Quick start
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Requires Node.js 22 or later and Claude Code. Install or update on macOS, Linux and Windows:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
npx @euraika-bert/claude-model-router@latest install
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Or install the command globally with npm:
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
npm install -g @euraika-bert/claude-model-router
|
|
27
27
|
claude-model-router install
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
**
|
|
30
|
+
**Upgrading** to the latest version:
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
npx @euraika-bert/claude-model-router@latest install #
|
|
34
|
-
claude-model-router upgrade #
|
|
33
|
+
npx @euraika-bert/claude-model-router@latest install # with npx
|
|
34
|
+
claude-model-router upgrade # after npm install -g
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
`upgrade`
|
|
37
|
+
`upgrade` always fetches the latest version from npm, even when your global install itself is old. Your keys, logins and settings are kept. So after `npm install -g`, don't use `claude-model-router install` to upgrade: that runs the installer of the version you already have.
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
The installer asks for your API keys (Enter skips a provider), enables only the providers you have a key or login for, and starts the router as a background service. Then restart Claude Code and pick a model with `/model`. When a new version is out, Claude Code shows a notice; see [Install and update via npm](#install-and-update-via-npm-macos-linux-windows).
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
The repository and the npm package contain **no API keys, OAuth tokens or personal `settings.json`**.
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## How it works
|
|
44
44
|
|
|
45
|
-
Claude Code
|
|
45
|
+
Claude Code sends its API requests to `http://127.0.0.1:8765`. The router reads the model ID and picks the route:
|
|
46
46
|
|
|
47
|
-
| Model | Route |
|
|
47
|
+
| Model | Route | Authentication |
|
|
48
48
|
| --- | --- | --- |
|
|
49
|
-
| `k3.1-pro[1m]`
|
|
50
|
-
| `mistral-large-4[1m]`, `zai-glm-5-3[1m]`
|
|
51
|
-
| `qwen*`, `deepseek*`, `glm*` (
|
|
52
|
-
| `gpt-*` (
|
|
53
|
-
| `MiniMax-*` (
|
|
54
|
-
|
|
|
49
|
+
| `k3.1-pro[1m]` and the other models in the Kimi catalog (e.g. `k3`, `k3-256k`, `k3.1-pro-highspeed`) | `api.kimi.com/coding` | Existing Kimi Code OAuth credentials, refreshed automatically |
|
|
50
|
+
| `mistral-large-4[1m]`, `zai-glm-5-3[1m]` and every ID and alias in the Mistral catalog (e.g. `mistral-medium-latest`, `codestral-latest`, `glm-5-2`) | `api.mistral.ai/v1/chat/completions` | Mistral API key (macOS Keychain, Linux key file, Windows DPAPI file) |
|
|
51
|
+
| `qwen*`, `deepseek*`, `glm*` (e.g. `qwen3.8-max[1m]`, `deepseek-v4-pro[1m]`, `glm-5.3[1m]`), except `zai-glm-*` and IDs from the Mistral catalog | `token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic` | Bailian token-plan API key (macOS Keychain, Linux key file, Windows DPAPI file) |
|
|
52
|
+
| `gpt-*` (e.g. `gpt-6-astra`, `gpt-6.1-sol`) | `chatgpt.com/backend-api/codex/responses` | ChatGPT OAuth login of the Codex CLI (`~/.codex/auth.json`, `codex login`), refreshed automatically |
|
|
53
|
+
| `MiniMax-*` (e.g. `MiniMax-M3.1-Flash[1m]`, `MiniMax-M3[1m]`) | `api.minimax.io/anthropic` | MiniMax M Plan API key (macOS Keychain, Linux key file, Windows DPAPI file) |
|
|
54
|
+
| All other models | `api.anthropic.com` | Your existing Claude Code login, forwarded unchanged |
|
|
55
55
|
|
|
56
|
-
**Claude
|
|
56
|
+
**Claude models.** Claude Code treats an `ANTHROPIC_BASE_URL` that does not point to `api.anthropic.com` as a third-party gateway and then shows a built-in, outdated model list, for example Fable 5.1 instead of Fable 5.2. The router forwards Claude requests unchanged, so the installer sets `_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL=1`. Claude Code then fetches the current model list from Anthropic itself, and new Claude models show up in `/model` on their own.
|
|
57
57
|
|
|
58
|
-
**Aliyun.**
|
|
58
|
+
**Aliyun.** This route uses Bailian's Anthropic-compatible endpoint. Requests are forwarded 1:1 with the key as a Bearer token; the `[1m]` suffix is stripped from the model ID, as for Kimi. Host and path can be overridden with `ALIYUN_ANTHROPIC_HOST` / `ALIYUN_ANTHROPIC_PATH` (useful for another region or the `/compatible-mode/v1` endpoint). Only models on your token plan work; `GET /compatible-mode/v1/models` shows what the plan offers, but not all of it is purchased. Always test a model with a real request before adding it.
|
|
59
59
|
|
|
60
|
-
**MiniMax.**
|
|
60
|
+
**MiniMax.** This route uses MiniMax's Anthropic-compatible endpoint (M Plan) and works like the Aliyun route: requests are forwarded 1:1 with the key as a Bearer token and the `[1m]` suffix is stripped (MiniMax itself rejects it: `unknown model`). The host can be overridden with `MINIMAX_ANTHROPIC_HOST` (the path is fixed at `/anthropic`). The catalog (`/v1/models`) also lists retired M2.x models and no context sizes, so MiniMax models are not synced automatically; curate them in `files/configure.mjs` after a real test.
|
|
61
61
|
|
|
62
|
-
**Mistral
|
|
62
|
+
**Mistral and GLM.** The router translates Anthropic Messages to and from Mistral's OpenAI-compatible format, including streaming, images, tool calls and the effort level. Each Mistral model accepts a different set of `reasoning_effort` values, or none at all. When a request is rejected, the router reads the accepted values from the error message and retries with the closest one. What it learns this way is remembered until the router restarts.
|
|
63
63
|
|
|
64
|
-
**ChatGPT/Codex.**
|
|
64
|
+
**ChatGPT/Codex.** The router translates to the OpenAI Responses API of the Codex backend, following the request shape of the Codex CLI: the effort level you pick, the model's encrypted reasoning carried across tool calls, and a stable session for the prompt cache. The backend only supports streaming; non-streaming requests are streamed internally and returned as one message. The login (`~/.codex/auth.json`) is refreshed before it expires: 5 minutes ahead, one refresh at a time, written atomically. Which models your account offers is listed in the Codex catalog; the router adds them automatically. Class mapping: astra = Fable, sol = Opus, terra = Sonnet, luna = Haiku. The Codex models have 272k context (the 6.1 models 500k), not 1M. They are therefore listed in `/model` without `[1m]`, with `autoCompactWindow` at 95% of the context, the same way the Codex CLI counts.
|
|
65
65
|
|
|
66
|
-
**
|
|
66
|
+
**Prompt caching.** Claude Code puts a billing header in the system prompt that changes on every request. Anthropic ignores it for caching, but other providers would treat it as prompt text and miss their cache on every turn, so the router removes it on all non-Anthropic routes. Cached tokens are reported to Claude Code the way Anthropic does (not counted twice).
|
|
67
67
|
|
|
68
|
-
**
|
|
68
|
+
**Tools.** Dynamic `ToolSearch` tools go to all routes. MCP tools that Claude Code sends as `tool_addition` blocks are turned into regular `tools` entries for Kimi, Aliyun and MiniMax. Tools without an `input_schema` (e.g. the `advisor` tool) get an explicit empty schema; MiniMax rejects them otherwise with `function parameters is empty (2013)`.
|
|
69
|
+
|
|
70
|
+
**Quota failover.** When a provider hits its usage limit (HTTP 429/402, or 403 with a quota message such as `AccessDenied.Unpurchased` or `Throttling`), the router retries the request on a model of the same class at another provider, never at Anthropic:
|
|
69
71
|
|
|
70
72
|
- Kimi → `qwen3.8-max` → `zai-glm-5-3`
|
|
71
73
|
- Aliyun → `zai-glm-5-3` → `k3.1-pro`
|
|
@@ -73,207 +75,208 @@ Claude Code stuurt API-verzoeken naar `http://127.0.0.1:8765`. De router leest d
|
|
|
73
75
|
- ChatGPT → `qwen3.8-max` → `zai-glm-5-3`
|
|
74
76
|
- MiniMax → `qwen3.8-max` → `k3.1-pro`
|
|
75
77
|
|
|
76
|
-
Providers
|
|
78
|
+
Providers without a key or login are skipped in the chain. A provider that returned a quota error is skipped for 5 minutes and then tried again automatically. If the last model in the chain fails too, Claude Code gets that error. Switches are logged (`Quota limit on ...; switching to ...`): on macOS and Linux in `~/.claude/logs/kimi-router.error.log`, on Windows in `%USERPROFILE%\.claude\logs\kimi-router.log`.
|
|
77
79
|
|
|
78
|
-
**Provider
|
|
80
|
+
**Provider without a login.** If you pick a model of a provider without a key or login, the router answers with HTTP 503 and a hint such as `run 'kimi login'`. It keeps running, so other sessions are not affected.
|
|
79
81
|
|
|
80
|
-
##
|
|
82
|
+
## Automatic model sync
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
When the router starts, and every 12 hours after that, it fetches the model catalog of every provider you have a key or login for:
|
|
83
85
|
|
|
84
|
-
| Provider |
|
|
86
|
+
| Provider | Catalog | Which models |
|
|
85
87
|
| --- | --- | --- |
|
|
86
|
-
| Mistral | `api.mistral.ai/v1/models` |
|
|
87
|
-
| Kimi | `api.kimi.com/coding/v1/models` |
|
|
88
|
-
| ChatGPT/Codex | `chatgpt.com/backend-api/codex/models` |
|
|
88
|
+
| Mistral | `api.mistral.ai/v1/models` | Chat models with tool support that are not deprecated |
|
|
89
|
+
| Kimi | `api.kimi.com/coding/v1/models` | All models |
|
|
90
|
+
| ChatGPT/Codex | `chatgpt.com/backend-api/codex/models` | The models the Codex CLI shows, for your Codex CLI version |
|
|
89
91
|
|
|
90
|
-
Aliyun
|
|
92
|
+
Aliyun is not synced: its catalog also lists models your plan rejects. Add Aliyun models yourself in `files/configure.mjs`, after a real test.
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
What the sync does:
|
|
93
95
|
|
|
94
|
-
1. **
|
|
95
|
-
2. **
|
|
96
|
-
3. **
|
|
97
|
-
4. **
|
|
96
|
+
1. **Routing.** Every ID and alias in a catalog goes to that provider. This routing comes before the Aliyun rule, so Mistral models like `glm-5-2` go to Mistral.
|
|
97
|
+
2. **Selection.** Models with at least 100k context that are not yet in `/model` become candidates. For each group of aliases the router picks one ID: preferably a `-latest` alias, otherwise the shortest ID. Models with 1M context get `[1m]`.
|
|
98
|
+
3. **Testing.** Every new candidate first gets a real test through the router: a non-streaming tool call, then a streamed answer to the tool result, without failover. Only if that passes does the model go into `modelPicker.options`, with the description *Auto-added from the … catalog* and `autoCompactWindow` equal to the context (at most 1M). A failed test (e.g. because of an exhausted quota) is retried on the next sync; the reason is in `/__health` under `modelSync.probeFailures`.
|
|
99
|
+
4. **Class.** `behavesAs` follows from the name:
|
|
98
100
|
- `astra` → Fable
|
|
99
101
|
- `luna`, `small`, `ministral` → Haiku
|
|
100
102
|
- `sol`, `large`, `pro`, `max` → Opus
|
|
101
103
|
- `terra`, `medium`, `flash`, `highspeed`, `codestral`, `leanstral` → Sonnet
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
5. **
|
|
104
|
+
- other GLM and Kimi models → Opus
|
|
105
|
+
- everything else → Sonnet
|
|
106
|
+
5. **Management.** The router only changes entries it added itself; the list is in `~/.claude/router-models.json`. When a model leaves the catalog, or the login goes away, it removes the entry. Before every change it writes a backup to `~/.claude/backups/settings.json.router-sync-*`. If nothing changes, it writes nothing.
|
|
105
107
|
|
|
106
|
-
##
|
|
108
|
+
## Requirements
|
|
107
109
|
|
|
108
|
-
- macOS (`launchd`
|
|
109
|
-
- Claude Code 2.1.242
|
|
110
|
-
- Node.js 22
|
|
111
|
-
-
|
|
112
|
-
- **Kimi:** Kimi Code CLI
|
|
113
|
-
- **Mistral
|
|
114
|
-
- **Qwen, DeepSeek
|
|
115
|
-
- **ChatGPT (GPT
|
|
116
|
-
- **MiniMax (M Plan):**
|
|
110
|
+
- macOS (`launchd` and Keychain), Linux with systemd (user service), or Windows 10/11 (Task Scheduler and Windows PowerShell 5.1, present by default).
|
|
111
|
+
- Claude Code 2.1.242 or later. That new Claude models appear on their own is verified with Claude Code 2.1.322.
|
|
112
|
+
- Node.js 22 or later.
|
|
113
|
+
- All providers below are **optional**. The installer only enables the providers that have a key or login; the others don't appear in `/model` and take no part in failover or sync.
|
|
114
|
+
- **Kimi:** the Kimi Code CLI and an active login via `kimi login`.
|
|
115
|
+
- **Mistral and GLM:** a valid Mistral API key with access to these models.
|
|
116
|
+
- **Qwen, DeepSeek and GLM via Aliyun:** a Bailian token-plan API key for region `ap-southeast-1`.
|
|
117
|
+
- **ChatGPT (GPT models):** the Codex CLI with an active login via `codex login` (ChatGPT account).
|
|
118
|
+
- **MiniMax (M Plan):** a MiniMax M Plan API key from [platform.minimax.io](https://platform.minimax.io/console/plan).
|
|
117
119
|
|
|
118
|
-
##
|
|
120
|
+
## Install and update via npm (macOS, Linux, Windows)
|
|
119
121
|
|
|
120
122
|
```bash
|
|
121
123
|
npx @euraika-bert/claude-model-router@latest install
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
With `npm install -g @euraika-bert/claude-model-router` followed by `claude-model-router install` it works too; you then update with `claude-model-router upgrade` (fetches the latest version, even when the global install itself is old).
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
This runs your platform's installer (`install.sh` on macOS and Linux, `install.ps1` on Windows) from the npm package. The same command also **updates**. Your settings, keys and logins are kept.
|
|
127
129
|
|
|
128
|
-
**
|
|
130
|
+
**Update notice:** once a day the router asks `registry.npmjs.org` for the latest version and sends nothing about you or your setup. When a newer version exists, Claude Code shows a notice with the update command at the start of a session; it comes from a SessionStart hook the installer adds to `settings.json`. It never updates automatically. To turn the check off, set `CLAUDE_MODEL_ROUTER_NO_UPDATE_CHECK=1` in the router's environment. The version is shown in `/__health` (`version`, `latestVersion`, `updateAvailable`) and by `npx @euraika-bert/claude-model-router version`.
|
|
129
131
|
|
|
130
|
-
##
|
|
132
|
+
## Installing on macOS
|
|
131
133
|
|
|
132
|
-
Via npm (
|
|
134
|
+
Via npm (see above), or from a copy of this repository:
|
|
133
135
|
|
|
134
136
|
```bash
|
|
135
137
|
./install.sh
|
|
136
138
|
```
|
|
137
139
|
|
|
138
|
-
|
|
140
|
+
The installer:
|
|
139
141
|
|
|
140
|
-
1.
|
|
141
|
-
2.
|
|
142
|
-
3.
|
|
143
|
-
4.
|
|
144
|
-
5.
|
|
145
|
-
6.
|
|
142
|
+
1. copies the router files to `~/.claude/` and a backup copy to `~/.local/share/claude-model-router/`;
|
|
143
|
+
2. installs the recovery command as `~/.local/bin/claude-model-router-setup`;
|
|
144
|
+
3. asks for your Mistral API key, Aliyun token-plan key and MiniMax M Plan key with a hidden prompt if they are not in the Keychain yet (Enter = skip);
|
|
145
|
+
4. detects which providers are usable: the Keychain items `claude-code-mistral`/`claude-code-aliyun`/`claude-code-minimax`, `kimi login` and `codex login`;
|
|
146
|
+
5. backs up `~/.claude/settings.json` to `~/.claude/backups/` and writes only the settings of those providers; entries of providers without a login are removed;
|
|
147
|
+
6. installs and starts `com.bert.claude-kimi-router` as a LaunchAgent, and shows which providers were skipped and how to enable them.
|
|
146
148
|
|
|
147
|
-
|
|
149
|
+
Then restart Claude Code and open `/model`. To add a provider later: set up the key or login, then run `claude-model-router-setup` again.
|
|
148
150
|
|
|
149
|
-
|
|
151
|
+
Non-interactive install:
|
|
150
152
|
|
|
151
153
|
```bash
|
|
152
154
|
MISTRAL_API_KEY='...' ALIYUN_API_KEY='...' MINIMAX_API_KEY='...' ./install.sh
|
|
153
155
|
```
|
|
154
156
|
|
|
155
|
-
|
|
157
|
+
These variables can end up in your shell history, so the hidden interactive prompt is preferred.
|
|
156
158
|
|
|
157
|
-
##
|
|
159
|
+
## Installing on Windows
|
|
158
160
|
|
|
159
|
-
> **Status:**
|
|
161
|
+
> **Status:** the Windows install has not been tested on a real Windows machine yet. It did run end to end in a Linux container with PowerShell 7.7, with Task Scheduler and the port check stubbed; see [Known limitations](#known-limitations).
|
|
160
162
|
|
|
161
|
-
|
|
163
|
+
Via npm (see above), or from a copy of this repository in PowerShell; no administrator rights needed:
|
|
162
164
|
|
|
163
165
|
```powershell
|
|
164
166
|
powershell -NoProfile -ExecutionPolicy Bypass -File .\install.ps1
|
|
165
167
|
```
|
|
166
168
|
|
|
167
|
-
|
|
169
|
+
The Windows install does the same as `install.sh`, with these differences:
|
|
168
170
|
|
|
169
|
-
- **Keys:**
|
|
170
|
-
- **Router:**
|
|
171
|
-
- **Log:** stdout
|
|
172
|
-
- **
|
|
173
|
-
- **
|
|
171
|
+
- **Keys:** the Mistral, Aliyun and MiniMax keys are stored DPAPI-encrypted in `%LOCALAPPDATA%\claude-model-router\` (`claude-code-mistral.dpapi`, `claude-code-aliyun.dpapi`, `claude-code-minimax.dpapi`). Only your Windows account can decrypt them.
|
|
172
|
+
- **Router:** runs as the scheduled task `claude-model-router`, started at logon. A hidden PowerShell loop (`%USERPROFILE%\.claude\kimi-router-run.ps1`) restarts the router within 2 seconds after a crash. A window may flash briefly at logon.
|
|
173
|
+
- **Log:** stdout and stderr go to one file: `%USERPROFILE%\.claude\logs\kimi-router.log`.
|
|
174
|
+
- **Reinstall:** a new install stops the running router; the loop restarts it right away with the new files.
|
|
175
|
+
- **Recovery:** there is no recovery command like `claude-model-router-setup`; run the npm command or `install.ps1` again.
|
|
174
176
|
|
|
175
|
-
Kimi
|
|
177
|
+
Kimi and ChatGPT/Codex work as soon as `kimi login` and `codex login` put their login in `%USERPROFILE%\.kimi-code` and `%USERPROFILE%\.codex`. Those are the default locations; `KIMI_CODE_HOME` and `CODEX_HOME` are respected.
|
|
176
178
|
|
|
177
|
-
|
|
179
|
+
Non-interactive install:
|
|
178
180
|
|
|
179
181
|
```powershell
|
|
180
182
|
$env:MISTRAL_API_KEY = '...'; $env:ALIYUN_API_KEY = '...'; $env:MINIMAX_API_KEY = '...'
|
|
181
183
|
powershell -NoProfile -ExecutionPolicy Bypass -File .\install.ps1
|
|
182
184
|
```
|
|
183
185
|
|
|
184
|
-
##
|
|
186
|
+
## Installing on Linux
|
|
185
187
|
|
|
186
|
-
> **Status:**
|
|
188
|
+
> **Status:** tested on Ubuntu 22.04 with real systemd (Node 24): installation, the service (`active`/`enabled`), key files with mode `600`, `/__health`, automatic restart after a crash (~11 s), `systemctl --user restart` and the uninstall steps below. Also real requests through the router for Mistral (7 models), ChatGPT/Codex (6) and MiniMax (2): non-streaming, streaming and a tool round trip, plus real Claude Code sessions (2.1.303) with the Read and Bash tools. Kimi and Aliyun were not tested (quota exhausted). Also tested in a Debian container with Node 22.
|
|
187
189
|
|
|
188
|
-
|
|
190
|
+
Use the npm command or the same `./install.sh` as on macOS. On Linux these things differ:
|
|
189
191
|
|
|
190
|
-
- **Keys:**
|
|
191
|
-
- **Service:**
|
|
192
|
-
- **Logs:**
|
|
193
|
-
- **
|
|
192
|
+
- **Keys:** each key is a separate file with mode `600` in `~/.config/claude-model-router/` (`claude-code-mistral`, `claude-code-aliyun`, `claude-code-minimax`; respects `XDG_CONFIG_HOME`). Linux has no keychain a background service can always reach; the Codex and Kimi logins store their tokens the same way.
|
|
193
|
+
- **Service:** a systemd user service `claude-model-router.service` in `~/.config/systemd/user/`. It starts when you log in. To run the router without a login session too (e.g. over SSH): `loginctl enable-linger $USER`.
|
|
194
|
+
- **Logs:** the same files as on macOS, in `~/.claude/logs/`.
|
|
195
|
+
- **Restart:** `systemctl --user restart claude-model-router`.
|
|
194
196
|
|
|
195
|
-
##
|
|
197
|
+
## Reinstall or recover
|
|
196
198
|
|
|
197
|
-
|
|
199
|
+
On every platform, `npx @euraika-bert/claude-model-router@latest install` works. On macOS and Linux it also works offline from the backup copy, after a deleted or broken configuration:
|
|
198
200
|
|
|
199
201
|
```bash
|
|
200
202
|
claude-model-router-setup
|
|
201
203
|
```
|
|
202
204
|
|
|
203
|
-
|
|
205
|
+
On Windows: run the npm command or `install.ps1` again. All installers are idempotent: you can run them as often as you like. Other settings are kept and duplicate model entries are avoided.
|
|
204
206
|
|
|
205
|
-
|
|
207
|
+
If the Kimi credentials are missing, run `kimi login` and then the installer again. If on macOS or Linux the backup copy is gone too, reinstall via `npx`.
|
|
206
208
|
|
|
207
|
-
##
|
|
209
|
+
## Checking
|
|
208
210
|
|
|
209
|
-
|
|
211
|
+
Check the router, the logins and the model sync:
|
|
210
212
|
|
|
211
213
|
```bash
|
|
212
214
|
curl --fail --silent http://127.0.0.1:8765/__health
|
|
213
215
|
```
|
|
214
216
|
|
|
215
|
-
|
|
217
|
+
On Windows: `Invoke-RestMethod http://127.0.0.1:8765/__health`.
|
|
216
218
|
|
|
217
|
-
|
|
219
|
+
`npx @euraika-bert/claude-model-router version` also shows the installed version.
|
|
218
220
|
|
|
219
|
-
|
|
221
|
+
The response includes:
|
|
220
222
|
|
|
221
|
-
- `version`, `latestVersion`
|
|
222
|
-
- `kimiLoginAvailable`, `mistralLoginAvailable`, `aliyunLoginAvailable`, `codexLoginAvailable`
|
|
223
|
-
- `modelSync`,
|
|
223
|
+
- `version`, `latestVersion` and `updateAvailable` (the installed version and the latest on npm);
|
|
224
|
+
- `kimiLoginAvailable`, `mistralLoginAvailable`, `aliyunLoginAvailable`, `codexLoginAvailable` and `minimaxLoginAvailable`;
|
|
225
|
+
- `modelSync`, with `syncedAt`, the number of models and any errors per provider, `pickerManaged` (the auto-added entries) and `probeFailures`.
|
|
224
226
|
|
|
225
|
-
|
|
227
|
+
Then check in Claude Code:
|
|
226
228
|
|
|
227
|
-
1. `/model`
|
|
228
|
-
2.
|
|
229
|
-
3.
|
|
229
|
+
1. `/model` shows the latest Claude models (e.g. Fable 5.2), your providers' models and the auto-added models.
|
|
230
|
+
2. A short prompt works with every model you want to use.
|
|
231
|
+
3. A simple Bash command works with a selected model too.
|
|
230
232
|
|
|
231
|
-
|
|
233
|
+
The parser for Mistral effort values has its own check: `node test/mistral-effort.test.mjs`. Token usage (cached tokens), the Codex request shape and the version check are covered by `node test/usage.test.mjs`.
|
|
232
234
|
|
|
233
|
-
##
|
|
235
|
+
## Authentication and secrets
|
|
234
236
|
|
|
235
|
-
- **Kimi:**
|
|
236
|
-
- **Mistral
|
|
237
|
-
- macOS: Keychain
|
|
238
|
-
- Linux: `~/.config/claude-model-router/claude-code-mistral` (
|
|
237
|
+
- **Kimi:** shared credentials from `~/.kimi-code/credentials/kimi-code.json` or, with newer versions of `kimi login`, the newest `kimi-code-env-<hash>.json`. The router refreshes tokens through Kimi's OAuth flow and writes them back atomically.
|
|
238
|
+
- **Mistral and GLM:**
|
|
239
|
+
- macOS: Keychain item `claude-code-mistral`;
|
|
240
|
+
- Linux: `~/.config/claude-model-router/claude-code-mistral` (mode `600`);
|
|
239
241
|
- Windows: `%LOCALAPPDATA%\claude-model-router\claude-code-mistral.dpapi`;
|
|
240
|
-
-
|
|
242
|
+
- or the `MISTRAL_API_KEY` environment variable of the router process.
|
|
241
243
|
- **Qwen (Aliyun):**
|
|
242
|
-
- macOS: Keychain
|
|
243
|
-
- Linux: `~/.config/claude-model-router/claude-code-aliyun` (
|
|
244
|
+
- macOS: Keychain item `claude-code-aliyun`;
|
|
245
|
+
- Linux: `~/.config/claude-model-router/claude-code-aliyun` (mode `600`);
|
|
244
246
|
- Windows: `claude-code-aliyun.dpapi`;
|
|
245
|
-
-
|
|
247
|
+
- or the `ALIYUN_API_KEY` environment variable of the router process.
|
|
246
248
|
- **MiniMax (M Plan):**
|
|
247
|
-
- macOS: Keychain
|
|
248
|
-
- Linux: `~/.config/claude-model-router/claude-code-minimax` (
|
|
249
|
+
- macOS: Keychain item `claude-code-minimax`;
|
|
250
|
+
- Linux: `~/.config/claude-model-router/claude-code-minimax` (mode `600`);
|
|
249
251
|
- Windows: `claude-code-minimax.dpapi`;
|
|
250
|
-
-
|
|
251
|
-
- **ChatGPT/Codex:**
|
|
252
|
-
- **Claude:**
|
|
253
|
-
-
|
|
254
|
-
- Logs
|
|
255
|
-
|
|
256
|
-
##
|
|
257
|
-
|
|
258
|
-
-
|
|
259
|
-
- Claude Code Remote Control
|
|
260
|
-
- `_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL` is
|
|
261
|
-
-
|
|
262
|
-
-
|
|
263
|
-
-
|
|
264
|
-
-
|
|
265
|
-
-
|
|
266
|
-
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
-
|
|
270
|
-
- Linux
|
|
271
|
-
- **
|
|
272
|
-
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
252
|
+
- or the `MINIMAX_API_KEY` environment variable of the router process.
|
|
253
|
+
- **ChatGPT/Codex:** the Codex CLI's OAuth login in `~/.codex/auth.json`. The router refreshes the token via `auth.openai.com` and writes it back atomically.
|
|
254
|
+
- **Claude:** the router stores no Anthropic token; incoming authentication is only forwarded to `api.anthropic.com`.
|
|
255
|
+
- The router keeps keys in memory for 5 minutes. On Windows it decrypts them through Windows PowerShell, which slows the first request after those 5 minutes slightly (not measured).
|
|
256
|
+
- Logs contain no API keys or request messages.
|
|
257
|
+
|
|
258
|
+
## Known limitations
|
|
259
|
+
|
|
260
|
+
- The router runs locally; Claude Code cloud sessions don't use this configuration.
|
|
261
|
+
- Claude Code Remote Control needs a direct connection to `api.anthropic.com` and is not available through this local route.
|
|
262
|
+
- `_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL` is an undocumented internal Claude Code setting. If an update ignores it, `/model` shows outdated Claude models again. Then pick the model by its ID, e.g. `/model claude-fable-5-2`. `ANTHROPIC_DEFAULT_FABLE_MODEL` does not help: with it the picker kept showing Fable 5.1.
|
|
263
|
+
- If you remove an auto-added model from `/model` by hand, the next sync puts it back. There is no exclude list (yet).
|
|
264
|
+
- The sync and Claude Code both write to `settings.json`. If they write at exactly the same moment, one of the two changes can be lost. The window is small and the sync always makes a backup first.
|
|
265
|
+
- Right after a fresh install, models from a synced catalog (e.g. `mistral-medium-latest`) can go to the wrong provider until the first catalog sync has finished.
|
|
266
|
+
- When Claude Code loads a new MCP tool mid-session, Kimi, Aliyun and MiniMax reprocess the prompt once without cache.
|
|
267
|
+
- Ministral 3B/8B/14B work through the router, but are weak as agents: after a tool error they often give up.
|
|
268
|
+
- Codex models above 272k context (the catalog lists up to 872k) are not tested.
|
|
269
|
+
- The costs Claude Code shows for custom models can differ from what the provider actually bills.
|
|
270
|
+
- **Verification status:**
|
|
271
|
+
- **macOS, end to end (17 November 2026):** all 23 models with available quota in `/model` (Codex 9, Mistral 12, MiniMax 2) pass non-streaming, streaming and a tool round trip through the router (`x-router-probe: 1`), plus real Claude Code sessions on Claude Haiku, Mistral Medium, GLM 5.3, DeepSeek, MiniMax M3.1-Flash and GPT 6.1 Terra/Sol.
|
|
272
|
+
- **Linux (17 November 2026):** tested on Ubuntu 22.04 with real systemd, in an isolated `HOME`: install and service, plus real requests and Claude Code sessions for Mistral, ChatGPT/Codex and MiniMax. Not tested: Kimi and Aliyun (quota exhausted) and a machine without `enable-linger`.
|
|
273
|
+
- **MiniMax (13 November 2026):** fully tested for `MiniMax-M3.1-Flash[1m]` and `MiniMax-M3[1m]`. The first attempt failed in real sessions with `function parameters is empty (2013)`: Claude Code sends tools without `input_schema` (e.g. `advisor`) and MiniMax rejects them after conversion; the router now gives such tools an explicit empty schema.
|
|
274
|
+
- **Kimi and Aliyun:** not retested with real requests after the recent changes, because both quotas were exhausted; the Aliyun quota resets on 5 December 2026, 16:00 UTC. New Kimi catalog models are added automatically once their test passes.
|
|
275
|
+
- **Windows:** only tested in a container. Not yet proven on real Windows: DPAPI encryption, Windows PowerShell 5.1, registering the scheduled task, the hidden window, Claude Code on Windows, the login locations of `kimi login` and `codex login`, and the npm `upgrade` command.
|
|
276
|
+
|
|
277
|
+
## Uninstalling
|
|
278
|
+
|
|
279
|
+
On macOS: stop the service and remove the router files:
|
|
277
280
|
|
|
278
281
|
```bash
|
|
279
282
|
launchctl bootout "gui/$(id -u)/com.bert.claude-kimi-router"
|
|
@@ -282,52 +285,54 @@ rm ~/.claude/kimi-router.mjs ~/.claude/kimi-oauth.mjs ~/.claude/mistral.mjs ~/.c
|
|
|
282
285
|
rm -r ~/.local/share/claude-model-router ~/.local/bin/claude-model-router-setup
|
|
283
286
|
```
|
|
284
287
|
|
|
285
|
-
|
|
288
|
+
On Linux:
|
|
286
289
|
|
|
287
290
|
```bash
|
|
288
291
|
systemctl --user disable --now claude-model-router
|
|
289
292
|
rm ~/.config/systemd/user/claude-model-router.service
|
|
290
293
|
rm ~/.claude/kimi-router.mjs ~/.claude/kimi-oauth.mjs ~/.claude/mistral.mjs ~/.claude/secrets.mjs ~/.claude/codex.mjs ~/.claude/models-sync.mjs ~/.claude/update-check.mjs ~/.claude/router-models.json
|
|
291
|
-
rm -r ~/.config/claude-model-router #
|
|
294
|
+
rm -r ~/.config/claude-model-router # the keys
|
|
292
295
|
rm -r ~/.local/share/claude-model-router ~/.local/bin/claude-model-router-setup
|
|
293
296
|
```
|
|
294
297
|
|
|
295
|
-
|
|
298
|
+
On Windows (PowerShell):
|
|
296
299
|
|
|
297
300
|
```powershell
|
|
298
301
|
Unregister-ScheduledTask -TaskName claude-model-router -Confirm:$false
|
|
299
302
|
Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort 8765 -State Listen -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }
|
|
300
303
|
Remove-Item "$env:USERPROFILE\.claude\kimi-router.mjs", "$env:USERPROFILE\.claude\kimi-oauth.mjs", "$env:USERPROFILE\.claude\mistral.mjs", "$env:USERPROFILE\.claude\secrets.mjs", "$env:USERPROFILE\.claude\codex.mjs", "$env:USERPROFILE\.claude\models-sync.mjs", "$env:USERPROFILE\.claude\update-check.mjs", "$env:USERPROFILE\.claude\kimi-router-run.ps1", "$env:USERPROFILE\.claude\router-models.json"
|
|
301
|
-
Remove-Item -Recurse "$env:LOCALAPPDATA\claude-model-router" #
|
|
304
|
+
Remove-Item -Recurse "$env:LOCALAPPDATA\claude-model-router" # the encrypted keys
|
|
302
305
|
```
|
|
303
306
|
|
|
304
|
-
|
|
307
|
+
If you installed the command globally, also run `npm uninstall -g @euraika-bert/claude-model-router`.
|
|
308
|
+
|
|
309
|
+
Then edit `~/.claude/settings.json` on every system; make a backup first. Remove:
|
|
305
310
|
|
|
306
|
-
- `ANTHROPIC_BASE_URL`
|
|
307
|
-
-
|
|
308
|
-
-
|
|
309
|
-
-
|
|
311
|
+
- `ANTHROPIC_BASE_URL` and `_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL`;
|
|
312
|
+
- the Kimi values `ANTHROPIC_CUSTOM_MODEL_OPTION_*`;
|
|
313
|
+
- the SessionStart hook with `update-check.mjs` under `hooks`;
|
|
314
|
+
- the custom `modelPicker` and `modelSettings` entries, including the auto-added ones: their description starts with *Auto-added from the … catalog* (in older versions *Automatisch toegevoegd uit de …-catalogus*).
|
|
310
315
|
|
|
311
|
-
|
|
316
|
+
The macOS Keychain items and the Kimi and Codex logins stay in place unless you remove them separately.
|
|
312
317
|
|
|
313
|
-
## Repository
|
|
318
|
+
## Repository layout
|
|
314
319
|
|
|
315
|
-
- `package.json`
|
|
316
|
-
- `.gitlab-ci.yml`
|
|
317
|
-
- `install.sh` —
|
|
318
|
-
- `install.ps1` —
|
|
319
|
-
- `files/configure.mjs` —
|
|
320
|
-
- `files/kimi-router.mjs` —
|
|
321
|
-
- `files/kimi-oauth.mjs` — Kimi OAuth
|
|
322
|
-
- `files/mistral.mjs` —
|
|
323
|
-
- `files/codex.mjs` — ChatGPT/Codex
|
|
324
|
-
- `files/secrets.mjs` —
|
|
325
|
-
- `files/models-sync.mjs` —
|
|
326
|
-
- `files/update-check.mjs` —
|
|
327
|
-
- `files/com.bert.claude-kimi-router.plist` — LaunchAgent
|
|
328
|
-
- `test/mistral-effort.test.mjs` —
|
|
329
|
-
- `test/usage.test.mjs` —
|
|
320
|
+
- `package.json` and `bin/claude-model-router.mjs` — the npm package and the `npx` command, which runs your platform's installer.
|
|
321
|
+
- `.gitlab-ci.yml` and `scripts/` — CI: tests and a secret scan on every push; on a version tag (`npm version patch`, then `git push --follow-tags`) CI publishes to npm automatically.
|
|
322
|
+
- `install.sh` — install and recovery on macOS and Linux.
|
|
323
|
+
- `install.ps1` — install on Windows.
|
|
324
|
+
- `files/configure.mjs` — writes the router settings into `settings.json` for the providers with a key or login; used by both installers.
|
|
325
|
+
- `files/kimi-router.mjs` — the localhost router: model routing, Kimi, Aliyun and MiniMax forwarding, quota failover and `/__health`.
|
|
326
|
+
- `files/kimi-oauth.mjs` — Kimi OAuth token refresh with shared credentials.
|
|
327
|
+
- `files/mistral.mjs` — translation between Anthropic and Mistral, including the `reasoning_effort` fallback.
|
|
328
|
+
- `files/codex.mjs` — ChatGPT/Codex route: OAuth refresh from `~/.codex/auth.json` and translation between Anthropic Messages and the OpenAI Responses API.
|
|
329
|
+
- `files/secrets.mjs` — reads the Mistral, Aliyun and MiniMax keys from the macOS Keychain, a DPAPI file (Windows) or a mode-`600` file (Linux).
|
|
330
|
+
- `files/models-sync.mjs` — automatic sync of the Mistral, Kimi and Codex catalogs, plus the login check per provider.
|
|
331
|
+
- `files/update-check.mjs` — version number and daily update check (via `/__health`); with `--session-notice`, the notice for the SessionStart hook.
|
|
332
|
+
- `files/com.bert.claude-kimi-router.plist` — LaunchAgent configuration (macOS).
|
|
333
|
+
- `test/mistral-effort.test.mjs` — check for the Mistral effort-value parser.
|
|
334
|
+
- `test/usage.test.mjs` — checks that cached tokens are taken out of `input_tokens` (Mistral/Codex), the Codex effort mapping, `environmentContext` and the version check.
|
|
330
335
|
|
|
331
|
-
##
|
|
336
|
+
## License
|
|
332
337
|
|
|
333
|
-
MIT, © 2026 Euraika BV.
|
|
338
|
+
MIT, © 2026 Euraika BV. See [LICENSE](LICENSE).
|
|
@@ -32,10 +32,10 @@ if (command === 'version' || command === '--version' || command === '-v') {
|
|
|
32
32
|
} else {
|
|
33
33
|
console.log(`claude-model-router ${VERSION}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
npx @euraika-bert/claude-model-router@latest install
|
|
37
|
-
claude-model-router upgrade
|
|
38
|
-
claude-model-router install
|
|
39
|
-
npx @euraika-bert/claude-model-router version
|
|
35
|
+
Usage:
|
|
36
|
+
npx @euraika-bert/claude-model-router@latest install install or update (macOS, Linux, Windows)
|
|
37
|
+
claude-model-router upgrade after npm install -g: fetch and install the latest version
|
|
38
|
+
claude-model-router install rerun the installer of this installed version
|
|
39
|
+
npx @euraika-bert/claude-model-router version show the installed package version`);
|
|
40
40
|
process.exit(command === 'help' || command === '--help' || command === '-h' ? 0 : 1);
|
|
41
41
|
}
|
package/files/configure.mjs
CHANGED
|
@@ -6,9 +6,9 @@ import path from 'node:path';
|
|
|
6
6
|
import { hasLogin } from './models-sync.mjs';
|
|
7
7
|
|
|
8
8
|
const PROVIDERS = {
|
|
9
|
-
mistral: ['Mistral (incl. GLM via Mistral)', 'Mistral API
|
|
10
|
-
aliyun: ['Aliyun (Qwen/DeepSeek/GLM)', 'Aliyun token-plan key
|
|
11
|
-
minimax: ['MiniMax (M Plan)', 'MiniMax M Plan API
|
|
9
|
+
mistral: ['Mistral (incl. GLM via Mistral)', 'enter a Mistral API key in the installer'],
|
|
10
|
+
aliyun: ['Aliyun (Qwen/DeepSeek/GLM)', 'enter an Aliyun token-plan key in the installer'],
|
|
11
|
+
minimax: ['MiniMax (M Plan)', 'enter a MiniMax M Plan API key in the installer'],
|
|
12
12
|
kimi: ['Kimi', 'kimi login'],
|
|
13
13
|
codex: ['ChatGPT/Codex', 'codex login'],
|
|
14
14
|
};
|
|
@@ -36,7 +36,7 @@ settings.env = {
|
|
|
36
36
|
const kimiOption = {
|
|
37
37
|
ANTHROPIC_CUSTOM_MODEL_OPTION: 'k3.1-pro[1m]',
|
|
38
38
|
ANTHROPIC_CUSTOM_MODEL_OPTION_NAME: 'Kimi K3.1 Pro',
|
|
39
|
-
ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION: 'Kimi Code
|
|
39
|
+
ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION: 'Kimi Code with 1M context; all Claude models stay available',
|
|
40
40
|
ANTHROPIC_CUSTOM_MODEL_OPTION_SUPPORTED_CAPABILITIES: 'effort,xhigh_effort,max_effort,thinking,adaptive_thinking,interleaved_thinking',
|
|
41
41
|
};
|
|
42
42
|
for (const key of Object.keys(kimiOption)) delete settings.env[key];
|
|
@@ -60,7 +60,7 @@ const curated = [
|
|
|
60
60
|
provider: 'mistral',
|
|
61
61
|
model: 'mistral-large-4[1m]',
|
|
62
62
|
label: 'Mistral Large 4',
|
|
63
|
-
description: 'Mistral
|
|
63
|
+
description: 'Mistral with 1M context; all Claude models stay available',
|
|
64
64
|
behavesAs: 'claude-opus-5-5',
|
|
65
65
|
modelSettings: oneMillion,
|
|
66
66
|
},
|
|
@@ -68,7 +68,7 @@ const curated = [
|
|
|
68
68
|
provider: 'mistral',
|
|
69
69
|
model: 'zai-glm-5-3[1m]',
|
|
70
70
|
label: 'GLM 5.3 (Mistral Hosted)',
|
|
71
|
-
description: 'GLM 5.3 via Mistral
|
|
71
|
+
description: 'GLM 5.3 via Mistral with 1M context',
|
|
72
72
|
behavesAs: 'claude-opus-5-5',
|
|
73
73
|
modelSettings: { effortLevel: 'max', autoCompactWindow: 1000000 },
|
|
74
74
|
},
|
|
@@ -76,7 +76,7 @@ const curated = [
|
|
|
76
76
|
provider: 'aliyun',
|
|
77
77
|
model: 'qwen3.8-max[1m]',
|
|
78
78
|
label: 'Qwen 3.8 Max (Aliyun)',
|
|
79
|
-
description: 'Qwen 3.8 Max via Alibaba Cloud Bailian
|
|
79
|
+
description: 'Qwen 3.8 Max via Alibaba Cloud Bailian with 1M context',
|
|
80
80
|
behavesAs: 'claude-opus-5-5',
|
|
81
81
|
modelSettings: oneMillion,
|
|
82
82
|
},
|
|
@@ -84,7 +84,7 @@ const curated = [
|
|
|
84
84
|
provider: 'aliyun',
|
|
85
85
|
model: 'qwen3.7-max[1m]',
|
|
86
86
|
label: 'Qwen 3.7 Max (Aliyun)',
|
|
87
|
-
description: 'Qwen 3.7 Max via Alibaba Cloud Bailian
|
|
87
|
+
description: 'Qwen 3.7 Max via Alibaba Cloud Bailian with 1M context',
|
|
88
88
|
behavesAs: 'claude-opus-5-5',
|
|
89
89
|
modelSettings: oneMillion,
|
|
90
90
|
},
|
|
@@ -92,7 +92,7 @@ const curated = [
|
|
|
92
92
|
provider: 'aliyun',
|
|
93
93
|
model: 'deepseek-v4-pro[1m]',
|
|
94
94
|
label: 'DeepSeek V4 Pro (Aliyun)',
|
|
95
|
-
description: 'DeepSeek V4 Pro via Alibaba Cloud Bailian
|
|
95
|
+
description: 'DeepSeek V4 Pro via Alibaba Cloud Bailian with 1M context',
|
|
96
96
|
behavesAs: 'claude-opus-5-5',
|
|
97
97
|
modelSettings: oneMillion,
|
|
98
98
|
},
|
|
@@ -100,14 +100,14 @@ const curated = [
|
|
|
100
100
|
provider: 'aliyun',
|
|
101
101
|
model: 'deepseek-v4.1-flash[1m]',
|
|
102
102
|
label: 'DeepSeek V4.1 Flash (Aliyun)',
|
|
103
|
-
description: 'DeepSeek V4.1 Flash (
|
|
103
|
+
description: 'DeepSeek V4.1 Flash (fast variant) via Alibaba Cloud Bailian with 1M context',
|
|
104
104
|
behavesAs: 'claude-sonnet-5-5',
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
107
|
provider: 'aliyun',
|
|
108
108
|
model: 'glm-5.3[1m]',
|
|
109
109
|
label: 'GLM 5.3 (Aliyun)',
|
|
110
|
-
description: 'GLM 5.3 via Alibaba Cloud Bailian
|
|
110
|
+
description: 'GLM 5.3 via Alibaba Cloud Bailian with 1M context (not the same as GLM 5.3 via Mistral)',
|
|
111
111
|
behavesAs: 'claude-opus-5-5',
|
|
112
112
|
modelSettings: oneMillion,
|
|
113
113
|
},
|
|
@@ -115,7 +115,7 @@ const curated = [
|
|
|
115
115
|
provider: 'codex',
|
|
116
116
|
model: 'gpt-6-astra',
|
|
117
117
|
label: 'GPT 6 Astra (ChatGPT/Codex)',
|
|
118
|
-
description: 'GPT 6 Astra (
|
|
118
|
+
description: 'GPT 6 Astra (top model) via the ChatGPT backend with the Codex OAuth login (codex login)',
|
|
119
119
|
behavesAs: 'claude-fable-5-2', // same class target as models-sync.mjs BEHAVES_AS.fable
|
|
120
120
|
modelSettings: { autoCompactWindow: 258400 },
|
|
121
121
|
},
|
|
@@ -123,7 +123,7 @@ const curated = [
|
|
|
123
123
|
provider: 'codex',
|
|
124
124
|
model: 'gpt-6.1-terra',
|
|
125
125
|
label: 'GPT 6.1 Terra (ChatGPT/Codex)',
|
|
126
|
-
description: 'GPT 6.1 Terra via
|
|
126
|
+
description: 'GPT 6.1 Terra via the ChatGPT backend with the Codex OAuth login (codex login)',
|
|
127
127
|
behavesAs: 'claude-sonnet-5-5',
|
|
128
128
|
modelSettings: { autoCompactWindow: 475000 },
|
|
129
129
|
},
|
|
@@ -131,7 +131,7 @@ const curated = [
|
|
|
131
131
|
provider: 'codex',
|
|
132
132
|
model: 'gpt-6.1-sol',
|
|
133
133
|
label: 'GPT 6.1 Sol (ChatGPT/Codex)',
|
|
134
|
-
description: 'GPT 6.1 Sol via
|
|
134
|
+
description: 'GPT 6.1 Sol via the ChatGPT backend with the Codex OAuth login',
|
|
135
135
|
behavesAs: 'claude-opus-5-5',
|
|
136
136
|
modelSettings: { autoCompactWindow: 475000 },
|
|
137
137
|
},
|
|
@@ -139,7 +139,7 @@ const curated = [
|
|
|
139
139
|
provider: 'codex',
|
|
140
140
|
model: 'gpt-5.6-luna',
|
|
141
141
|
label: 'GPT 5.6 Luna (ChatGPT/Codex)',
|
|
142
|
-
description: 'GPT 5.6 Luna (
|
|
142
|
+
description: 'GPT 5.6 Luna (light variant) via the ChatGPT backend with the Codex OAuth login',
|
|
143
143
|
behavesAs: 'claude-haiku-5-5',
|
|
144
144
|
modelSettings: { autoCompactWindow: 258400 },
|
|
145
145
|
},
|
|
@@ -147,7 +147,7 @@ const curated = [
|
|
|
147
147
|
provider: 'minimax',
|
|
148
148
|
model: 'MiniMax-M3.1-Flash[1m]',
|
|
149
149
|
label: 'MiniMax M3.1 Flash',
|
|
150
|
-
description: 'MiniMax M3.1 Flash (agentic coding) via api.minimax.io
|
|
150
|
+
description: 'MiniMax M3.1 Flash (agentic coding) via api.minimax.io with 1M context',
|
|
151
151
|
behavesAs: 'claude-opus-5-5',
|
|
152
152
|
modelSettings: oneMillion,
|
|
153
153
|
},
|
|
@@ -155,7 +155,7 @@ const curated = [
|
|
|
155
155
|
provider: 'minimax',
|
|
156
156
|
model: 'MiniMax-M3[1m]',
|
|
157
157
|
label: 'MiniMax M3',
|
|
158
|
-
description: 'MiniMax M3 via api.minimax.io
|
|
158
|
+
description: 'MiniMax M3 via api.minimax.io with 1M context',
|
|
159
159
|
behavesAs: 'claude-opus-5-5',
|
|
160
160
|
modelSettings: oneMillion,
|
|
161
161
|
},
|
|
@@ -184,7 +184,7 @@ if (available.has('kimi')) {
|
|
|
184
184
|
}
|
|
185
185
|
fs.writeFileSync(file, `${JSON.stringify(settings, null, 2)}\n`, { mode: 0o600 });
|
|
186
186
|
|
|
187
|
-
console.log(`
|
|
187
|
+
console.log(`Enabled providers: ${[...available].join(', ') || 'none'}`);
|
|
188
188
|
for (const [provider, [label, fix]] of Object.entries(PROVIDERS)) {
|
|
189
|
-
if (!available.has(provider)) console.log(` - ${label}
|
|
189
|
+
if (!available.has(provider)) console.log(` - ${label} skipped: ${fix}, then rerun the installer`);
|
|
190
190
|
}
|
package/files/models-sync.mjs
CHANGED
|
@@ -284,7 +284,7 @@ async function runSync(baseUrl) {
|
|
|
284
284
|
option: {
|
|
285
285
|
model: pickerId(c),
|
|
286
286
|
label: `${c.label || c.id} (${PROVIDER_LABEL[c.provider]})`,
|
|
287
|
-
description: `
|
|
287
|
+
description: `Auto-added from the ${PROVIDER_LABEL[c.provider]} catalog · ${Math.round(c.ctx / 1000)}k context`,
|
|
288
288
|
behavesAs: BEHAVES_AS[classOf(c.id)],
|
|
289
289
|
},
|
|
290
290
|
}));
|
package/files/update-check.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
|
|
7
|
-
export const VERSION = '0.1.
|
|
7
|
+
export const VERSION = '0.1.6'; // keep equal to package.json (test/usage.test.mjs checks it)
|
|
8
8
|
const PACKAGE = '@euraika-bert/claude-model-router';
|
|
9
9
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
10
10
|
let latestVersion = null;
|
|
@@ -41,7 +41,7 @@ if (process.argv.includes('--session-notice') && path.resolve(process.argv[1] ??
|
|
|
41
41
|
const health = await (await fetch('http://127.0.0.1:8765/__health', { signal: AbortSignal.timeout(1500) })).json();
|
|
42
42
|
if (health.updateAvailable) {
|
|
43
43
|
console.log(JSON.stringify({
|
|
44
|
-
systemMessage: `claude-model-router ${health.latestVersion} is
|
|
44
|
+
systemMessage: `claude-model-router ${health.latestVersion} is available (installed: ${health.version}). Update: npx @euraika-bert/claude-model-router@latest install`,
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
47
|
} catch {} // router down or old router without update fields: stay silent
|
package/install.ps1
CHANGED
|
@@ -13,8 +13,8 @@ $TaskName = 'claude-model-router'
|
|
|
13
13
|
$Port = 8765
|
|
14
14
|
|
|
15
15
|
$node = (Get-Command node -ErrorAction SilentlyContinue).Source
|
|
16
|
-
if (-not $node) { throw 'Node.js 22
|
|
17
|
-
if ([int]((& $node --version).TrimStart('v').Split('.')[0]) -lt 22) { throw 'Node.js 22
|
|
16
|
+
if (-not $node) { throw 'Node.js 22 or later is required but was not found.' }
|
|
17
|
+
if ([int]((& $node --version).TrimStart('v').Split('.')[0]) -lt 22) { throw 'Node.js 22 or later is required.' }
|
|
18
18
|
|
|
19
19
|
New-Item -ItemType Directory -Force -Path (Join-Path $ClaudeDir 'logs'), $SecretDir | Out-Null
|
|
20
20
|
foreach ($file in 'kimi-router.mjs', 'kimi-oauth.mjs', 'mistral.mjs', 'secrets.mjs', 'codex.mjs', 'models-sync.mjs', 'update-check.mjs') {
|
|
@@ -28,13 +28,13 @@ function Save-Key([string]$Service, [string]$EnvVar, [string]$Prompt) {
|
|
|
28
28
|
if (Test-Path -LiteralPath $target) { return }
|
|
29
29
|
$plain = [Environment]::GetEnvironmentVariable($EnvVar)
|
|
30
30
|
if ($plain) { $secure = ConvertTo-SecureString $plain -AsPlainText -Force }
|
|
31
|
-
elseif (-not [Console]::IsInputRedirected) { $secure = Read-Host -AsSecureString "$Prompt (Enter =
|
|
31
|
+
elseif (-not [Console]::IsInputRedirected) { $secure = Read-Host -AsSecureString "$Prompt (Enter = skip)" }
|
|
32
32
|
else { return }
|
|
33
33
|
if ($secure.Length -gt 0) { $secure | ConvertFrom-SecureString | Set-Content -LiteralPath $target }
|
|
34
34
|
}
|
|
35
|
-
Save-Key 'claude-code-mistral' 'MISTRAL_API_KEY' 'Mistral API
|
|
36
|
-
Save-Key 'claude-code-aliyun' 'ALIYUN_API_KEY' 'Aliyun Bailian API
|
|
37
|
-
Save-Key 'claude-code-minimax' 'MINIMAX_API_KEY' 'MiniMax M Plan API
|
|
35
|
+
Save-Key 'claude-code-mistral' 'MISTRAL_API_KEY' 'Mistral API key'
|
|
36
|
+
Save-Key 'claude-code-aliyun' 'ALIYUN_API_KEY' 'Aliyun Bailian API key (token plan)'
|
|
37
|
+
Save-Key 'claude-code-minimax' 'MINIMAX_API_KEY' 'MiniMax M Plan API key'
|
|
38
38
|
Remove-Item Env:MISTRAL_API_KEY, Env:ALIYUN_API_KEY, Env:MINIMAX_API_KEY -ErrorAction SilentlyContinue
|
|
39
39
|
|
|
40
40
|
$env:ROUTER_NODE = $node # stable path for the SessionStart hook (nvm-windows symlinks resolve to versioned dirs)
|
|
@@ -73,7 +73,7 @@ foreach ($attempt in 1..30) {
|
|
|
73
73
|
try { $health = Invoke-RestMethod -Uri "http://127.0.0.1:$Port/__health" -UseBasicParsing -TimeoutSec 2; break }
|
|
74
74
|
catch { Start-Sleep -Milliseconds 500 }
|
|
75
75
|
}
|
|
76
|
-
if (-not $health) { throw "
|
|
76
|
+
if (-not $health) { throw "The router does not respond on port $Port; see $Log" }
|
|
77
77
|
Write-Host ''
|
|
78
|
-
Write-Host '
|
|
79
|
-
Write-Host "Router: http://127.0.0.1:$Port (
|
|
78
|
+
Write-Host 'Done. All built-in Claude models stay available in /model.'
|
|
79
|
+
Write-Host "Router: http://127.0.0.1:$Port (task '$TaskName', log $Log). Restart Claude Code."
|
package/install.sh
CHANGED
|
@@ -15,7 +15,7 @@ SYSTEMD_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
|
|
|
15
15
|
UNIT="claude-model-router.service"
|
|
16
16
|
|
|
17
17
|
if [[ "$OS" != Darwin && "$OS" != Linux ]]; then
|
|
18
|
-
printf '
|
|
18
|
+
printf 'Unsupported OS: %s. Use install.ps1 on Windows.\n' "$OS" >&2
|
|
19
19
|
exit 1
|
|
20
20
|
fi
|
|
21
21
|
|
|
@@ -28,7 +28,7 @@ if [[ -d "$REPO_DIR/files" ]]; then
|
|
|
28
28
|
cp "$REPO_DIR/files/"* "$SOURCE_DIR/"
|
|
29
29
|
fi
|
|
30
30
|
if [[ ! -f "$SOURCE_DIR/kimi-router.mjs" ]]; then
|
|
31
|
-
printf '
|
|
31
|
+
printf 'Backup copy missing in %s\n' "$SOURCE_DIR" >&2
|
|
32
32
|
exit 1
|
|
33
33
|
fi
|
|
34
34
|
|
|
@@ -40,7 +40,7 @@ for candidate in "$HOME/.local/bin/node" /opt/homebrew/bin/node /usr/local/bin/n
|
|
|
40
40
|
fi
|
|
41
41
|
done
|
|
42
42
|
if [[ -z "$NODE_BIN" ]]; then
|
|
43
|
-
printf 'Node.js is
|
|
43
|
+
printf 'Node.js 22 or later is required but was not found.\n' >&2
|
|
44
44
|
exit 1
|
|
45
45
|
fi
|
|
46
46
|
|
|
@@ -110,15 +110,15 @@ store_key() { # <service> <env var> <prompt>
|
|
|
110
110
|
key_stored "$1" && return 0
|
|
111
111
|
key="${!2:-}"
|
|
112
112
|
if [[ -z "$key" && -t 0 ]]; then
|
|
113
|
-
read -r -s -p "$3 (Enter =
|
|
113
|
+
read -r -s -p "$3 (Enter = skip): " key
|
|
114
114
|
printf '\n'
|
|
115
115
|
fi
|
|
116
116
|
[[ -n "$key" ]] || return 0
|
|
117
117
|
write_key "$1" "$key"
|
|
118
118
|
}
|
|
119
|
-
store_key claude-code-mistral MISTRAL_API_KEY 'Mistral API
|
|
120
|
-
store_key claude-code-aliyun ALIYUN_API_KEY 'Aliyun Bailian API
|
|
121
|
-
store_key claude-code-minimax MINIMAX_API_KEY 'MiniMax M Plan API
|
|
119
|
+
store_key claude-code-mistral MISTRAL_API_KEY 'Mistral API key'
|
|
120
|
+
store_key claude-code-aliyun ALIYUN_API_KEY 'Aliyun Bailian API key (token plan)'
|
|
121
|
+
store_key claude-code-minimax MINIMAX_API_KEY 'MiniMax M Plan API key'
|
|
122
122
|
unset MISTRAL_API_KEY ALIYUN_API_KEY MINIMAX_API_KEY
|
|
123
123
|
|
|
124
124
|
ROUTER_NODE="$NODE_BIN" "$NODE_BIN" "$SOURCE_DIR/configure.mjs"
|
|
@@ -143,12 +143,12 @@ for _ in {1..20}; do
|
|
|
143
143
|
sleep 0.5
|
|
144
144
|
done
|
|
145
145
|
HEALTH="$(curl --fail --silent http://127.0.0.1:8765/__health)" || {
|
|
146
|
-
printf '
|
|
146
|
+
printf 'The router does not respond on port 8765; see %s\n' "$CLAUDE_DIR/logs/kimi-router.error.log" >&2
|
|
147
147
|
exit 1
|
|
148
148
|
}
|
|
149
149
|
ROUTER_VERSION="$(printf '%s' "$HEALTH" | "$NODE_BIN" -e 'let s="";process.stdin.on("data",(d)=>(s+=d)).on("end",()=>{try{console.log(JSON.parse(s).version??"?")}catch{console.log("?")}})')"
|
|
150
|
-
printf '\
|
|
151
|
-
printf 'Router %s: http://127.0.0.1:8765 (logs in %s).
|
|
150
|
+
printf '\nDone. All built-in Claude models stay available in /model.\n'
|
|
151
|
+
printf 'Router %s: http://127.0.0.1:8765 (logs in %s). Restart Claude Code.\n' "$ROUTER_VERSION" "$CLAUDE_DIR/logs"
|
|
152
152
|
if [[ "$OS" == Linux ]] && ! loginctl show-user "$USER" -p Linger 2>/dev/null | grep -q yes; then
|
|
153
|
-
printf 'Tip:
|
|
153
|
+
printf 'Tip: the router starts when you log in. To run it without a login session too (e.g. over SSH): loginctl enable-linger %s\n' "$USER"
|
|
154
154
|
fi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@euraika-bert/claude-model-router",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Local router that adds Kimi, Mistral/GLM, Aliyun Qwen/DeepSeek, ChatGPT/Codex and MiniMax models to Claude Code without replacing the built-in Claude models (macOS, Linux, Windows).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|