@alexeiled/claude-router 1.20.1 → 1.21.0
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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +27 -0
- package/README.md +3 -3
- package/docs/activity-routing.md +1 -1
- package/docs/architecture.md +5 -3
- package/docs/configuration.md +9 -8
- package/docs/evaluation.md +4 -4
- package/docs/native-router.md +11 -11
- package/docs/providers.md +3 -3
- package/docs/router-band.svg +158 -137
- package/docs/router-pane-classifier.svg +21 -23
- package/docs/router-pane-now.svg +138 -173
- package/docs/router-pane-policy.svg +21 -23
- package/docs/router-pane-routes.svg +32 -34
- package/docs/router-pane-usage-whatif.svg +139 -157
- package/docs/router-pane-usage.svg +165 -165
- package/docs/user-guide.md +129 -70
- package/hooks/native-router.mjs +9 -5
- package/lib/band.mjs +254 -172
- package/lib/config.mjs +24 -15
- package/lib/cost.mjs +26 -10
- package/lib/costs.mjs +156 -0
- package/lib/display.mjs +102 -93
- package/lib/panel.mjs +486 -445
- package/lib/policy.mjs +1 -1
- package/lib/prices.mjs +113 -0
- package/lib/providers.mjs +9 -21
- package/lib/route.mjs +1 -1
- package/lib/savings.mjs +14 -8
- package/lib/subagents.mjs +3 -3
- package/package.json +2 -1
package/lib/policy.mjs
CHANGED
|
@@ -130,7 +130,7 @@ export function cashGate(config, route, facts, now, costs, routeFor = (tier) =>
|
|
|
130
130
|
if (routeSpec(config, route).billing !== 'credits') return { blocked: false };
|
|
131
131
|
if (costs.isWarm(facts.models[costs.routeCacheKey(config, route, facts.effort)], now, config.cache))
|
|
132
132
|
return { blocked: false };
|
|
133
|
-
const cold = costs.coldWriteUsd(config, route.model, costs.nextContextTokens(facts));
|
|
133
|
+
const cold = costs.coldWriteUsd(config, route.model, costs.nextContextTokens(facts), now);
|
|
134
134
|
if (cold <= config.policy.cashCapUsd) return { blocked: false };
|
|
135
135
|
const fallback = [...TIERS].reverse().find((t) => routeSpec(config, routeFor(t)).billing === 'plan');
|
|
136
136
|
const estimate = {
|
package/lib/prices.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Generated by scripts/check-prices.mjs from each vendor's official price page: `npm run prices:check -- --write`
|
|
2
|
+
// rewrites this file, and the weekly price check proposes the change as a pull request. USD per million tokens.
|
|
3
|
+
// `checked` is the date the prices last changed or a person confirmed them against the page. `offPeak` multiplies
|
|
4
|
+
// every rate outside the peak hours (UTC days 0-6 from Sunday, [from, to) hours). Limit: DeepSeek also bills Chinese
|
|
5
|
+
// public holidays off-peak, which this does not know, so a holiday prices at peak, the higher bound.
|
|
6
|
+
export const PRICE_SOURCES = {
|
|
7
|
+
anthropic: {
|
|
8
|
+
url: 'https://platform.claude.com/docs/en/about-claude/pricing.md',
|
|
9
|
+
checked: '2026-11-04',
|
|
10
|
+
},
|
|
11
|
+
deepseek: {
|
|
12
|
+
url: 'https://api-docs.deepseek.com/quick_start/pricing.md',
|
|
13
|
+
checked: '2026-11-04',
|
|
14
|
+
},
|
|
15
|
+
kimi: {
|
|
16
|
+
url: 'https://platform.kimi.ai/docs/pricing/chat',
|
|
17
|
+
checked: '2026-11-04',
|
|
18
|
+
},
|
|
19
|
+
minimax: {
|
|
20
|
+
url: 'https://platform.minimax.io/docs/guides/pricing-paygo.md',
|
|
21
|
+
checked: '2026-11-04',
|
|
22
|
+
},
|
|
23
|
+
zai: {
|
|
24
|
+
url: 'https://docs.z.ai/guides/overview/pricing.md',
|
|
25
|
+
checked: '2026-11-04',
|
|
26
|
+
},
|
|
27
|
+
mimo: {
|
|
28
|
+
url: 'https://mimo.mi.com/docs/en-US/price/pay-as-you-go',
|
|
29
|
+
checked: '2026-11-04',
|
|
30
|
+
manual: true,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const PRICES = {
|
|
35
|
+
'claude-opus-5-5': {
|
|
36
|
+
source: 'anthropic',
|
|
37
|
+
input: 4,
|
|
38
|
+
output: 20,
|
|
39
|
+
cacheRead: 0.2,
|
|
40
|
+
},
|
|
41
|
+
'claude-sonnet-5-5': {
|
|
42
|
+
source: 'anthropic',
|
|
43
|
+
input: 2,
|
|
44
|
+
output: 10,
|
|
45
|
+
cacheRead: 0.1,
|
|
46
|
+
},
|
|
47
|
+
'claude-haiku-5-5': {
|
|
48
|
+
source: 'anthropic',
|
|
49
|
+
input: 0.1,
|
|
50
|
+
output: 0.5,
|
|
51
|
+
cacheRead: 0.01,
|
|
52
|
+
longContext: {
|
|
53
|
+
above: 100000,
|
|
54
|
+
multiplier: 5,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
'deepseek-flash[1m]': {
|
|
58
|
+
source: 'deepseek',
|
|
59
|
+
input: 0.3,
|
|
60
|
+
output: 1.2,
|
|
61
|
+
cacheRead: 0.006,
|
|
62
|
+
offPeak: {
|
|
63
|
+
multiplier: 0.5,
|
|
64
|
+
peakDays: [1, 2, 3, 4, 5],
|
|
65
|
+
peakHoursUtc: [
|
|
66
|
+
[1, 4],
|
|
67
|
+
[6, 10],
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
'kimi-k3.1-pro[1m]': {
|
|
72
|
+
source: 'kimi',
|
|
73
|
+
input: 2,
|
|
74
|
+
output: 10,
|
|
75
|
+
cacheRead: 0.2,
|
|
76
|
+
},
|
|
77
|
+
'MiniMax-M3.1-Flash[1m]': {
|
|
78
|
+
source: 'minimax',
|
|
79
|
+
input: 0.15,
|
|
80
|
+
output: 0.6,
|
|
81
|
+
cacheRead: 0.015,
|
|
82
|
+
},
|
|
83
|
+
'glm-5.3-flash[1m]': {
|
|
84
|
+
source: 'zai',
|
|
85
|
+
input: 0.15,
|
|
86
|
+
output: 0.5,
|
|
87
|
+
cacheRead: 0.03,
|
|
88
|
+
},
|
|
89
|
+
'glm-5.3[1m]': {
|
|
90
|
+
source: 'zai',
|
|
91
|
+
input: 1.4,
|
|
92
|
+
output: 4.4,
|
|
93
|
+
cacheRead: 0.26,
|
|
94
|
+
},
|
|
95
|
+
'mimo-v2.6-flash[1m]': {
|
|
96
|
+
source: 'mimo',
|
|
97
|
+
input: 0.14,
|
|
98
|
+
output: 0.28,
|
|
99
|
+
cacheRead: 0.0028,
|
|
100
|
+
},
|
|
101
|
+
'mimo-v2.6-pro[1m]': {
|
|
102
|
+
source: 'mimo',
|
|
103
|
+
input: 0.435,
|
|
104
|
+
output: 0.87,
|
|
105
|
+
cacheRead: 0.0036,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// A model's rates for a router.json entry, without the bookkeeping field.
|
|
110
|
+
export function listPrice(id) {
|
|
111
|
+
const { source, ...rates } = PRICES[id];
|
|
112
|
+
return rates;
|
|
113
|
+
}
|
package/lib/providers.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { listPrice } from './prices.mjs';
|
|
2
|
+
|
|
1
3
|
// Execution presets, not classifier services. Prices are API list-price estimates, never a plan bill.
|
|
2
4
|
// Sources and the limits of these starting routes are in docs/configuration.md#provider-profiles.
|
|
3
5
|
const EFFORTS = ['low', 'high', 'max'];
|
|
@@ -22,9 +24,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
22
24
|
models: {
|
|
23
25
|
flash: {
|
|
24
26
|
id: 'MiniMax-M3.1-Flash[1m]',
|
|
25
|
-
|
|
26
|
-
output: 0.6,
|
|
27
|
-
cacheRead: 0.015,
|
|
27
|
+
...listPrice('MiniMax-M3.1-Flash[1m]'),
|
|
28
28
|
contextWindow: 1_000_000,
|
|
29
29
|
billing: 'credits',
|
|
30
30
|
// xhigh is documented but some Claude Code versions serialize it as high; use max instead.
|
|
@@ -49,9 +49,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
49
49
|
models: {
|
|
50
50
|
flash: {
|
|
51
51
|
id: 'mimo-v2.6-flash[1m]',
|
|
52
|
-
|
|
53
|
-
output: 0.28,
|
|
54
|
-
cacheRead: 0.0028,
|
|
52
|
+
...listPrice('mimo-v2.6-flash[1m]'),
|
|
55
53
|
contextWindow: 1_000_000,
|
|
56
54
|
billing: 'credits',
|
|
57
55
|
// The Anthropic endpoint documents binary thinking, not granular effort. Keep its default thinking.
|
|
@@ -61,9 +59,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
61
59
|
},
|
|
62
60
|
pro: {
|
|
63
61
|
id: 'mimo-v2.6-pro[1m]',
|
|
64
|
-
|
|
65
|
-
output: 0.87,
|
|
66
|
-
cacheRead: 0.0036,
|
|
62
|
+
...listPrice('mimo-v2.6-pro[1m]'),
|
|
67
63
|
contextWindow: 1_000_000,
|
|
68
64
|
billing: 'credits',
|
|
69
65
|
efforts: [],
|
|
@@ -86,9 +82,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
86
82
|
models: {
|
|
87
83
|
k3: {
|
|
88
84
|
id: 'kimi-k3.1-pro[1m]',
|
|
89
|
-
|
|
90
|
-
output: 10,
|
|
91
|
-
cacheRead: 0.2,
|
|
85
|
+
...listPrice('kimi-k3.1-pro[1m]'),
|
|
92
86
|
contextWindow: 1_048_576,
|
|
93
87
|
billing: 'credits',
|
|
94
88
|
efforts: EFFORTS,
|
|
@@ -110,9 +104,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
110
104
|
models: {
|
|
111
105
|
flash: {
|
|
112
106
|
id: 'deepseek-flash[1m]',
|
|
113
|
-
|
|
114
|
-
output: 1.2,
|
|
115
|
-
cacheRead: 0.006,
|
|
107
|
+
...listPrice('deepseek-flash[1m]'),
|
|
116
108
|
contextWindow: 1_000_000,
|
|
117
109
|
billing: 'credits',
|
|
118
110
|
efforts: EFFORTS,
|
|
@@ -136,9 +128,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
136
128
|
models: {
|
|
137
129
|
flash: {
|
|
138
130
|
id: 'glm-5.3-flash[1m]',
|
|
139
|
-
|
|
140
|
-
output: 0.5,
|
|
141
|
-
cacheRead: 0.03,
|
|
131
|
+
...listPrice('glm-5.3-flash[1m]'),
|
|
142
132
|
contextWindow: 1_000_000,
|
|
143
133
|
billing: 'credits',
|
|
144
134
|
efforts: EFFORTS,
|
|
@@ -147,9 +137,7 @@ export const PROVIDER_DEFAULTS = {
|
|
|
147
137
|
},
|
|
148
138
|
glm: {
|
|
149
139
|
id: 'glm-5.3[1m]',
|
|
150
|
-
|
|
151
|
-
output: 4.4,
|
|
152
|
-
cacheRead: 0.26,
|
|
140
|
+
...listPrice('glm-5.3[1m]'),
|
|
153
141
|
contextWindow: 1_000_000,
|
|
154
142
|
billing: 'credits',
|
|
155
143
|
efforts: EFFORTS,
|
package/lib/route.mjs
CHANGED
|
@@ -67,7 +67,7 @@ export function emptyLoop(config, model) {
|
|
|
67
67
|
// The message count at the last review applied inside a turn: tool calls before it were already judged, so only
|
|
68
68
|
// later ones can move the route up again (observedMove).
|
|
69
69
|
observedFrom: 0,
|
|
70
|
-
// Each configured model's simulated cache, by models key, for the routing-vs-
|
|
70
|
+
// Each configured model's simulated cache, by models key, for the routing-vs-no-routing readout (compareModels in
|
|
71
71
|
// savings.mjs).
|
|
72
72
|
yoursBy: {},
|
|
73
73
|
};
|
package/lib/savings.mjs
CHANGED
|
@@ -38,9 +38,15 @@ export function modelAlias(config, id) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// One request's list price in USD: `counts` are its uncached input, cache read, cache write and output tokens, the
|
|
41
|
-
// writes at `writeMultiplier` times input. Long-context rates follow the whole prompt
|
|
42
|
-
export function requestUsd(
|
|
43
|
-
|
|
41
|
+
// writes at `writeMultiplier` times input. Long-context rates follow the whole prompt, off-peak rates the time `at`.
|
|
42
|
+
export function requestUsd(
|
|
43
|
+
model,
|
|
44
|
+
{ input, cacheRead, cacheWrite, output },
|
|
45
|
+
writeMultiplier,
|
|
46
|
+
cacheMode = 'explicit',
|
|
47
|
+
at,
|
|
48
|
+
) {
|
|
49
|
+
const rates = ratesAt(model, input + cacheRead + cacheWrite, at);
|
|
44
50
|
const inputUsd =
|
|
45
51
|
cacheMode === 'disabled'
|
|
46
52
|
? rates.input * (input + cacheRead + cacheWrite)
|
|
@@ -49,7 +55,7 @@ export function requestUsd(model, { input, cacheRead, cacheWrite, output }, writ
|
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
// Actual observed counters can be priced without inventing the cache on another route.
|
|
52
|
-
export function observedReplyUsd(config, usage, ttl) {
|
|
58
|
+
export function observedReplyUsd(config, usage, ttl, at) {
|
|
53
59
|
const counts = {
|
|
54
60
|
input: usage?.input_tokens,
|
|
55
61
|
cacheRead: usage?.cache_read_input_tokens,
|
|
@@ -65,7 +71,7 @@ export function observedReplyUsd(config, usage, ttl) {
|
|
|
65
71
|
!Object.values(counts).every((n) => Number.isFinite(n) && n >= 0)
|
|
66
72
|
)
|
|
67
73
|
return null;
|
|
68
|
-
return requestUsd(model, counts, write, config.cache.mode);
|
|
74
|
+
return requestUsd(model, counts, write, config.cache.mode, at);
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
const truthy = (value) => /^(1|true|yes|on)$/i.test(String(value ?? '').trim());
|
|
@@ -138,7 +144,7 @@ export function compareReply(config, state, { usage, served, yours, ttl, now })
|
|
|
138
144
|
return { state: next, reply: null };
|
|
139
145
|
// Implicit caches have no guaranteed TTL or cross-effort hit rate. Only identical observed routes compare exactly.
|
|
140
146
|
if (config.cache.mode === 'automatic' && !(onYours && (prior?.onYours ?? true))) return { state: next, reply: null };
|
|
141
|
-
const routedUsd = requestUsd(servedSpec, counts, write, config.cache.mode);
|
|
147
|
+
const routedUsd = requestUsd(servedSpec, counts, write, config.cache.mode, now);
|
|
142
148
|
let yoursUsd = routedUsd;
|
|
143
149
|
let servedOnYoursUsd = routedUsd;
|
|
144
150
|
if (!(onYours && (prior?.onYours ?? true))) {
|
|
@@ -150,8 +156,8 @@ export function compareReply(config, state, { usage, served, yours, ttl, now })
|
|
|
150
156
|
prior.total > 0;
|
|
151
157
|
const cacheRead = Math.max(counts.cacheRead, warm ? Math.min(prior.total, total - counts.input) : 0);
|
|
152
158
|
const single = { ...counts, cacheRead, cacheWrite: total - counts.input - cacheRead };
|
|
153
|
-
yoursUsd = requestUsd(yoursSpec, single, write, config.cache.mode);
|
|
154
|
-
servedOnYoursUsd = requestUsd(servedSpec, single, write, config.cache.mode);
|
|
159
|
+
yoursUsd = requestUsd(yoursSpec, single, write, config.cache.mode, now);
|
|
160
|
+
servedOnYoursUsd = requestUsd(servedSpec, single, write, config.cache.mode, now);
|
|
155
161
|
}
|
|
156
162
|
const modelUsd = servedOnYoursUsd - yoursUsd;
|
|
157
163
|
return {
|
package/lib/subagents.mjs
CHANGED
|
@@ -172,7 +172,7 @@ export function spawnRecord({ sessionId, spawn, pass, choice, routedModel, coreM
|
|
|
172
172
|
const isCount = (n) => Number.isFinite(n) && n >= 0;
|
|
173
173
|
|
|
174
174
|
// The record with one reply added. A reply is priced only when both its model and the comparison's have a price.
|
|
175
|
-
export function addAgentReply(config, agent, usage, ttl) {
|
|
175
|
+
export function addAgentReply(config, agent, usage, ttl, at) {
|
|
176
176
|
const counts = {
|
|
177
177
|
input: usage?.input_tokens,
|
|
178
178
|
cacheRead: usage?.cache_read_input_tokens,
|
|
@@ -188,8 +188,8 @@ export function addAgentReply(config, agent, usage, ttl) {
|
|
|
188
188
|
if (!agent.pass && !priced(other)) return next;
|
|
189
189
|
if (config.cache.mode === 'automatic' && other && actual !== other) return next;
|
|
190
190
|
next.pricedRequests += 1;
|
|
191
|
-
next.actualUsd += requestUsd(actual, counts, write, config.cache.mode);
|
|
192
|
-
if (other) next.otherUsd += requestUsd(other, counts, write, config.cache.mode);
|
|
191
|
+
next.actualUsd += requestUsd(actual, counts, write, config.cache.mode, at);
|
|
192
|
+
if (other) next.otherUsd += requestUsd(other, counts, write, config.cache.mode, at);
|
|
193
193
|
return next;
|
|
194
194
|
}
|
|
195
195
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Native Claude Code model and effort routing with Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi defaults, custom provider profiles, and classifier advice.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexei Ledenev",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"test:providers": "node experiments/mod-router/scripts/provider-acceptance.mjs",
|
|
38
38
|
"format": "tools/node_modules/.bin/biome format --write .",
|
|
39
39
|
"docs:images": "node scripts/render-doc-images.mjs",
|
|
40
|
+
"prices:check": "node scripts/check-prices.mjs",
|
|
40
41
|
"docs:modes": "node scripts/mode-matrix.mjs",
|
|
41
42
|
"probe:results": "node scripts/probe-results.mjs",
|
|
42
43
|
"pack:dry": "npm pack --dry-run",
|