@khanglvm/llm-router 2.2.1 → 2.2.3
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 +42 -235
- package/package.json +2 -1
- package/src/node/web-console-client.js +23 -23
- package/src/node/web-console-styles.generated.js +1 -1
- package/src/runtime/handler/amp-web-search.js +14 -7
- package/src/runtime/handler/provider-call.js +22 -2
- package/src/runtime/handler/runtime-policy.js +2 -1
- package/src/runtime/handler.js +2 -1
- package/src/runtime/state-store.js +3 -0
- package/wrangler.toml +12 -3
package/README.md
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
# LLM Router
|
|
2
2
|
|
|
3
|
-
LLM
|
|
3
|
+
A unified LLM gateway that routes requests across multiple providers through a single endpoint. Supports both OpenAI and Anthropic-compatible formats. Manage everything via Web UI or CLI — optimized for AI agents.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
NPM package:
|
|
8
|
-
```bash
|
|
9
|
-
@khanglvm/llm-router
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Primary CLI command:
|
|
13
|
-
```bash
|
|
14
|
-
llr
|
|
15
|
-
```
|
|
5
|
+

|
|
16
6
|
|
|
17
7
|
## Install
|
|
18
8
|
|
|
@@ -22,260 +12,77 @@ npm i -g @khanglvm/llm-router@latest
|
|
|
22
12
|
|
|
23
13
|
## Quick Start
|
|
24
14
|
|
|
25
|
-
1. Open the Web UI:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
llr
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
2. Add at least one provider and model.
|
|
32
|
-
3. Optionally create aliases and fallback routes.
|
|
33
|
-
4. Start the local gateway:
|
|
34
|
-
|
|
35
15
|
```bash
|
|
36
|
-
llr
|
|
16
|
+
llr # open Web UI
|
|
17
|
+
llr start # start the local gateway
|
|
18
|
+
llr ai-help # agent-oriented setup brief
|
|
37
19
|
```
|
|
38
20
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
21
|
+
1. Open the Web UI and add a provider (API key or OAuth login)
|
|
22
|
+
2. Create model aliases with routing strategy
|
|
23
|
+
3. Start the gateway and point your tools at the local endpoint
|
|
42
24
|
|
|
43
|
-
|
|
44
|
-
- Web UI: browser-based config editing, provider probing, and local router control
|
|
45
|
-
|
|
46
|
-
The legacy TUI flow is no longer part of the supported workflow.
|
|
47
|
-
|
|
48
|
-
## Core Commands
|
|
49
|
-
|
|
50
|
-
Open the Web UI:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
llr
|
|
54
|
-
llr config
|
|
55
|
-
llr web
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Run direct config operations:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
llr config --operation=validate
|
|
62
|
-
llr config --operation=snapshot
|
|
63
|
-
llr config --operation=tool-status
|
|
64
|
-
llr config --operation=list
|
|
65
|
-
llr config --operation=discover-provider-models --endpoints=https://openrouter.ai/api/v1 --api-key=sk-...
|
|
66
|
-
llr config --operation=test-provider --endpoints=https://openrouter.ai/api/v1 --api-key=sk-... --models=gpt-4o-mini,gpt-4o
|
|
67
|
-
llr config --operation=upsert-provider --provider-id=openrouter --name=OpenRouter --base-url=https://openrouter.ai/api/v1 --api-key=sk-... --models=gpt-4o-mini,gpt-4o
|
|
68
|
-
llr config --operation=upsert-model-alias --alias-id=chat.default --strategy=auto --targets=openrouter/gpt-4o-mini@3,anthropic/claude-3-5-haiku@2
|
|
69
|
-
llr config --operation=set-provider-rate-limits --provider-id=openrouter --bucket-name="Monthly cap" --bucket-models=all --bucket-requests=20000 --bucket-window=month:1
|
|
70
|
-
llr config --operation=set-master-key --generate-master-key=true
|
|
71
|
-
llr config --operation=set-codex-cli-routing --enabled=true --default-model=chat.default
|
|
72
|
-
llr config --operation=set-claude-code-routing --enabled=true --primary-model=chat.default
|
|
73
|
-
llr config --operation=set-amp-client-routing --enabled=true --amp-client-settings-scope=workspace
|
|
74
|
-
```
|
|
25
|
+
## What You Can Do
|
|
75
26
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
llr
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Get the agent-oriented setup brief:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
llr ai-help
|
|
90
|
-
```
|
|
27
|
+
- **Add & manage providers** — connect any OpenAI/Anthropic-compatible API endpoint, test connectivity, auto-discover models
|
|
28
|
+
- **Unified endpoint** — one local gateway that accepts both OpenAI and Anthropic request formats
|
|
29
|
+
- **Model aliases with routing** — group models into stable alias names with weighted round-robin, quota-aware balancing, and automatic fallback
|
|
30
|
+
- **Rate limiting** — set request caps per model or across all models over configurable time windows
|
|
31
|
+
- **Coding tool routing** — one-click routing config for Codex CLI, Claude Code, and AMP
|
|
32
|
+
- **Web search** — built-in web search for AMP and other router-managed tools
|
|
33
|
+
- **Deployable** — run locally or deploy to Cloudflare Workers
|
|
34
|
+
- **AI-agent friendly** — full CLI parity with `llr config --operation=...` so agents can configure everything programmatically
|
|
91
35
|
|
|
92
36
|
## Web UI
|
|
93
37
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
llr
|
|
98
|
-
llr web --port=9090
|
|
99
|
-
llr web --open=false
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
What it covers:
|
|
38
|
+
### Alias & Fallback
|
|
103
39
|
|
|
104
|
-
|
|
105
|
-
- provider discovery and probe flows
|
|
106
|
-
- alias, fallback, rate-limit, and AMP management
|
|
107
|
-
- local router start, stop, and restart
|
|
108
|
-
- coding-tool patch helpers for Codex CLI, Claude Code, and AMP
|
|
40
|
+
Create stable route names across multiple providers with balancing and failover.
|
|
109
41
|
|
|
110
|
-
|
|
42
|
+

|
|
111
43
|
|
|
112
|
-
|
|
44
|
+
### AMP (Beta)
|
|
113
45
|
|
|
114
|
-
|
|
46
|
+
Route AMP-compatible requests through LLM Router with custom model mapping.
|
|
115
47
|
|
|
116
|
-
|
|
117
|
-
llr config --operation=validate
|
|
118
|
-
llr config --operation=snapshot
|
|
119
|
-
llr config --operation=tool-status
|
|
120
|
-
llr reclaim
|
|
121
|
-
llr config --operation=set-codex-cli-routing --enabled=true --default-model=chat.default
|
|
122
|
-
llr config --operation=set-claude-code-routing --enabled=true --primary-model=chat.default --default-haiku-model=chat.fast
|
|
123
|
-
llr config --operation=set-amp-client-routing --enabled=true --amp-client-settings-scope=workspace
|
|
124
|
-
llr config --operation=set-codex-cli-routing --enabled=false
|
|
125
|
-
llr config --operation=set-claude-code-routing --enabled=false
|
|
126
|
-
llr config --operation=set-amp-client-routing --enabled=false --amp-client-settings-scope=workspace
|
|
127
|
-
```
|
|
48
|
+

|
|
128
49
|
|
|
129
|
-
|
|
50
|
+
### Codex CLI
|
|
130
51
|
|
|
131
|
-
|
|
132
|
-
- `snapshot` combines config, runtime, startup, and coding-tool routing state.
|
|
133
|
-
- `tool-status` focuses only on Codex CLI, Claude Code, and AMP client wiring.
|
|
134
|
-
- `reclaim` force-frees the fixed local router port when another listener is blocking `llr start`.
|
|
135
|
-
- `set-codex-cli-routing` accepts `--default-model=<route>` or `--default-model=__codex_cli_inherit__` to keep Codex's own model selection.
|
|
136
|
-
- `set-claude-code-routing` accepts `--primary-model`, `--default-opus-model`, `--default-sonnet-model`, `--default-haiku-model`, `--subagent-model`, and `--thinking-level`.
|
|
137
|
-
- `set-amp-client-routing` patches or restores AMP client settings/secrets separately from router-side AMP config.
|
|
52
|
+
Route Codex CLI requests through the gateway with model override and thinking level.
|
|
138
53
|
|
|
139
|
-
|
|
54
|
+

|
|
140
55
|
|
|
141
|
-
|
|
142
|
-
- Model: one upstream model id exposed by that provider
|
|
143
|
-
- Alias: one stable route name that can fan out to multiple provider/model targets
|
|
144
|
-
- Rate-limit bucket: request cap scoped to one or more models over a time window
|
|
56
|
+
### Claude Code
|
|
145
57
|
|
|
146
|
-
|
|
58
|
+
Route Claude Code through the gateway with per-tier model bindings.
|
|
147
59
|
|
|
148
|
-
|
|
149
|
-
2. Create aliases for stable client-facing route names.
|
|
150
|
-
3. Put balancing/fallback behavior behind the alias, not in the client.
|
|
60
|
+

|
|
151
61
|
|
|
152
|
-
|
|
62
|
+
### Web Search
|
|
153
63
|
|
|
154
|
-
|
|
64
|
+
Configure search providers for AMP and other router-managed tools.
|
|
155
65
|
|
|
156
|
-
|
|
157
|
-
llr config --operation=upsert-provider --provider-id=chatgpt --name="GPT Sub" --type=subscription --subscription-type=chatgpt-codex --subscription-profile=default
|
|
158
|
-
llr config --operation=upsert-provider --provider-id=claude-sub --name="Claude Sub" --type=subscription --subscription-type=claude-code --subscription-profile=default
|
|
159
|
-
llr subscription login --subscription-type=chatgpt-codex --profile=default
|
|
160
|
-
llr subscription login --subscription-type=claude-code --profile=default
|
|
161
|
-
llr subscription status
|
|
162
|
-
```
|
|
66
|
+

|
|
163
67
|
|
|
164
|
-
|
|
68
|
+
## AMP (Beta)
|
|
165
69
|
|
|
166
|
-
|
|
167
|
-
- `claude-code`
|
|
70
|
+
> AMP support is in beta. Features and API surface may change.
|
|
168
71
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
## AMP
|
|
172
|
-
|
|
173
|
-
LLM Router can front AMP-compatible routes locally and optionally proxy unresolved AMP traffic upstream.
|
|
174
|
-
|
|
175
|
-
Open the Web UI for AMP setup, or use direct CLI operations:
|
|
72
|
+
LLM Router can front AMP-compatible routes locally and proxy unresolved traffic upstream. Configure via the Web UI or CLI:
|
|
176
73
|
|
|
177
74
|
```bash
|
|
178
|
-
llr config --operation=set-amp-config --patch-amp-client-config=true --amp-client-settings-scope=workspace --amp-client-url=http://127.0.0.1:4000
|
|
179
|
-
llr config --operation=set-amp-config --amp-default-route=chat.default --amp-routes="smart => chat.smart, rush => chat.fast"
|
|
180
|
-
llr config --operation=set-amp-config --amp-upstream-url=https://ampcode.com --amp-upstream-api-key=amp_...
|
|
181
75
|
llr config --operation=set-amp-client-routing --enabled=true --amp-client-settings-scope=workspace
|
|
182
76
|
```
|
|
183
77
|
|
|
184
|
-
##
|
|
185
|
-
|
|
186
|
-
The repo includes a local-only real-provider suite for the supported operator surfaces:
|
|
187
|
-
|
|
188
|
-
- CLI config + local gateway start
|
|
189
|
-
- Web UI discovery / probe / save / router control
|
|
190
|
-
|
|
191
|
-
Setup:
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
cp .env.test-suite.example .env.test-suite
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
Then fill in your own provider keys, endpoints, and models.
|
|
198
|
-
|
|
199
|
-
Run:
|
|
200
|
-
|
|
201
|
-
```bash
|
|
202
|
-
npm run test:provider-live
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
Legacy alias:
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
npm run test:provider-smoke
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
The live suite uses isolated temp HOME/config/runtime-state folders and does not overwrite your normal `~/.llm-router.json` or `~/.llm-router.runtime.json`.
|
|
212
|
-
|
|
213
|
-
## Deploy to Cloudflare
|
|
214
|
-
|
|
215
|
-
Deploy the current config to a Worker:
|
|
216
|
-
|
|
217
|
-
```bash
|
|
218
|
-
llr deploy
|
|
219
|
-
llr deploy --dry-run=true
|
|
220
|
-
llr deploy --workers-dev=true
|
|
221
|
-
llr deploy --route-pattern=router.example.com/* --zone-name=example.com
|
|
222
|
-
llr deploy --generate-master-key=true
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
Fast worker key rotation:
|
|
226
|
-
|
|
227
|
-
```bash
|
|
228
|
-
llr worker-key --generate-master-key=true
|
|
229
|
-
llr worker-key --env=production --master-key=rotated-key
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## Config File
|
|
233
|
-
|
|
234
|
-
Local config path:
|
|
235
|
-
|
|
236
|
-
```text
|
|
237
|
-
~/.llm-router.json
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
LLM Router also keeps related runtime and token state under the same namespace for backward compatibility with the published package.
|
|
241
|
-
|
|
242
|
-
Useful runtime env knobs:
|
|
243
|
-
|
|
244
|
-
- `LLM_ROUTER_MAX_REQUEST_BODY_BYTES`: caps inbound JSON body size for the local router and worker runtime. Default is `8 MiB` for `/responses` requests and `1 MiB` for other JSON endpoints.
|
|
245
|
-
- `LLM_ROUTER_UPSTREAM_TIMEOUT_MS`: overrides the provider request timeout.
|
|
246
|
-
|
|
247
|
-
## Development
|
|
248
|
-
|
|
249
|
-
Web UI dev loop:
|
|
250
|
-
|
|
251
|
-
```bash
|
|
252
|
-
npm run dev
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
Build the browser bundle:
|
|
256
|
-
|
|
257
|
-
```bash
|
|
258
|
-
npm run build:web-console
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
Run the JavaScript test suite:
|
|
262
|
-
|
|
263
|
-
```bash
|
|
264
|
-
node --test $(rg --files -g "*.test.js" src)
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
## Documentation
|
|
78
|
+
## Subscription Providers
|
|
268
79
|
|
|
269
|
-
|
|
80
|
+
OAuth-backed subscription login is supported for ChatGPT.
|
|
270
81
|
|
|
271
|
-
|
|
272
|
-
- **[Codebase Summary](./docs/codebase-summary.md)** — Directory structure, module relationships, entry points, test infrastructure
|
|
273
|
-
- **[Code Standards](./docs/code-standards.md)** — Patterns, naming conventions, testing, error handling
|
|
274
|
-
- **[System Architecture](./docs/system-architecture.md)** — Request lifecycle, subsystem boundaries, data flow, deployment models
|
|
275
|
-
- **[Project Roadmap](./docs/project-roadmap.md)** — Current status, planned phases, timeline, success metrics
|
|
82
|
+
> **Note:** ChatGPT subscriptions are separate from the OpenAI API and intended for use within OpenAI's own apps. Using them here may violate OpenAI's terms of service.
|
|
276
83
|
|
|
277
|
-
##
|
|
84
|
+
## Links
|
|
278
85
|
|
|
279
|
-
-
|
|
280
|
-
-
|
|
281
|
-
- AMP
|
|
86
|
+
- [Changelog](https://github.com/khanglvm/llm-router/blob/master/CHANGELOG.md)
|
|
87
|
+
- [Security](https://github.com/khanglvm/llm-router/blob/master/SECURITY.md)
|
|
88
|
+
- [AMP Routing Docs](https://github.com/khanglvm/llm-router/blob/master/assets/amp-routing.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanglvm/llm-router",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "LLM Router: single gateway endpoint for multi-provider LLMs with unified OpenAI+Anthropic format and seamless fallback",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"llm-router",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"test:provider-live": "node --test --test-concurrency=1 ./test/live-provider-suite.test.js",
|
|
33
33
|
"test:provider-smoke": "npm run test:provider-live",
|
|
34
34
|
"test:amp-smoke": "node ./scripts/amp-smoke-suite.mjs",
|
|
35
|
+
"test:worker": "node ./scripts/test-worker.mjs",
|
|
35
36
|
"prepublishOnly": "npm run test:provider-live"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|