@alexeiled/claude-router 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +20 -0
- package/docs/architecture.md +14 -4
- package/docs/configuration.md +16 -15
- package/docs/user-guide.md +1 -1
- package/lib/config.mjs +8 -5
- package/lib/cost.mjs +12 -3
- package/lib/policy.mjs +11 -3
- package/lib/router.mjs +2 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "router",
|
|
3
3
|
"displayName": "jev-router",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.2",
|
|
5
5
|
"description": "Auto-picks the right Claude model for each turn — small models for quick edits, mid-tier for code, frontier for hard problems. Uses Jev to classify each request.",
|
|
6
6
|
"author": { "name": "Alexei Ledenev", "url": "https://github.com/alexei-led" },
|
|
7
7
|
"repository": "https://github.com/alexei-led/claude-router",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.2 (2026-09-25)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- `router.json` accepted a `policy.downgradePivotUsd` of 0 and a
|
|
8
|
+
`policy.downgradeSlope` that is not a number. A zero pivot made the
|
|
9
|
+
downgrade bar `NaN` whenever a switch cost nothing, and then no downgrade
|
|
10
|
+
ever passed. Both values now stop a new gateway from starting, as the
|
|
11
|
+
upgrade keys already did; `/router:status` names the field.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- The downgrade bar counts what a cheaper model saves, not only its cache
|
|
16
|
+
write. The tax used to count the input of the next request alone. It now
|
|
17
|
+
nets the output and cache-read savings of the next
|
|
18
|
+
`policy.downgradeHorizonTurns` turns (default 5). From a warm Opus at
|
|
19
|
+
`xhigh` to a cold Sonnet, with 104k of context and 4k of output, the bar
|
|
20
|
+
drops from 0.935 to 0.922 (1-hour TTL). It never goes below 0.90. A model
|
|
21
|
+
without an `output` price keeps the input-only tax.
|
|
22
|
+
|
|
3
23
|
## 0.7.1 (2026-09-24)
|
|
4
24
|
|
|
5
25
|
### Fixed
|
package/docs/architecture.md
CHANGED
|
@@ -208,6 +208,16 @@ only when that tier is above the current route.
|
|
|
208
208
|
- The downgrade bar grows the same way, from the other side: a candidate
|
|
209
209
|
colder than the incumbent pays a cache write, not just a smaller model.
|
|
210
210
|
`bar = 0.90 + 0.08 × tax / (tax + $0.50)`. It stays between 0.90 and 0.98.
|
|
211
|
+
- The downgrade tax nets the savings of the next `H` turns
|
|
212
|
+
(`policy.downgradeHorizonTurns`, default 5):
|
|
213
|
+
`tax = max(0, next + (H − 1) × later)`. `next` is the cost difference of
|
|
214
|
+
the next turn, input and output. `later` is the difference of each later
|
|
215
|
+
turn, with both caches warm. Both come from the
|
|
216
|
+
[shadow estimate](#cache-and-cost-model). Example: warm Opus at `xhigh` to
|
|
217
|
+
a cold Sonnet, 104k of context, 4k of output, 1-hour TTL. The input tax is
|
|
218
|
+
$0.40 (bar 0.935); net of five turns it is $0.20 (bar 0.922).
|
|
219
|
+
- When either model has no `output` price, or a zero one, the downgrade tax
|
|
220
|
+
is the input tax alone. A missing price is unknown, not free.
|
|
211
221
|
- A prompt continues the task when the Jev continuation answer is 0.7 or
|
|
212
222
|
more. A continuing prompt never votes for a downgrade.
|
|
213
223
|
- Upgrades have no cooldown. Plan, then execute, then hard work again is a
|
|
@@ -260,8 +270,8 @@ tax = max(0, input_cost(candidate) − input_cost(current))
|
|
|
260
270
|
`test/fixtures/list-prices.json`, which names its source and date.
|
|
261
271
|
- **Shadow estimate.** When the Jev choice differs from the current route, the
|
|
262
272
|
log records the cost of the next turn, the cost of each later turn with
|
|
263
|
-
output, and the turns until a switch repays its cost. The
|
|
264
|
-
|
|
273
|
+
output, and the turns until a switch repays its cost. The downgrade tax
|
|
274
|
+
uses the same arithmetic. The upgrade tax counts input only.
|
|
265
275
|
|
|
266
276
|
## Modules
|
|
267
277
|
|
|
@@ -431,7 +441,7 @@ claude --plugin-dir . --model jev-router # with ANTHROPIC_BASE_URL
|
|
|
431
441
|
- Without the hint headers, the gateway guesses side requests. A missed side
|
|
432
442
|
request with a short history counts as a history break.
|
|
433
443
|
- `x-claude-code-agent-type` goes to the log only.
|
|
434
|
-
- The shadow estimate
|
|
435
|
-
changes how much a model writes.
|
|
444
|
+
- The shadow estimate and the downgrade tax use the last output size for
|
|
445
|
+
both routes, but effort changes how much a model writes.
|
|
436
446
|
|
|
437
447
|
A day of real usage is in [Evaluation](evaluation.md).
|
package/docs/configuration.md
CHANGED
|
@@ -118,7 +118,7 @@ A test makes sure that they agree.
|
|
|
118
118
|
| Field | Meaning |
|
|
119
119
|
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
120
120
|
| `id` | The model id that the gateway sends to Anthropic. |
|
|
121
|
-
| `input`, `output`, `cacheRead` | List prices in USD per million tokens. `output` is optional.
|
|
121
|
+
| `input`, `output`, `cacheRead` | List prices in USD per million tokens. `output` is optional. The `shadow` estimate and the downgrade tax use it. |
|
|
122
122
|
| `contextWindow` | The window in tokens. A turn goes only to a model that holds the context at 80% fill. |
|
|
123
123
|
| `maxOutput` | Optional limit for `max_tokens`. Haiku 4.5 rejects more than 64K. |
|
|
124
124
|
| `billing` | `plan` for the subscription limits. `credits` for models that bill usage credits. |
|
|
@@ -133,20 +133,21 @@ from a probe against the real API. A test fails when they differ.
|
|
|
133
133
|
|
|
134
134
|
The [switching policy](architecture.md#switching-policy) uses these values.
|
|
135
135
|
|
|
136
|
-
| Key
|
|
137
|
-
|
|
|
138
|
-
| `upgradeVotes`
|
|
139
|
-
| `upgradeBase`
|
|
140
|
-
| `upgradeSlope`
|
|
141
|
-
| `upgradePivotUsd`
|
|
142
|
-
| `jumpConfidence`
|
|
143
|
-
| `downgradeVotes`
|
|
144
|
-
| `downgradeMass`
|
|
145
|
-
| `downgradeSlope`
|
|
146
|
-
| `downgradePivotUsd`
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
136
|
+
| Key | Default | Meaning |
|
|
137
|
+
| ----------------------- | ------- | ----------------------------------------------------------------------------------------------------- |
|
|
138
|
+
| `upgradeVotes` | `2` | Consecutive votes above the current tier before an upgrade. |
|
|
139
|
+
| `upgradeBase` | `0.75` | The upgrade bar when a switch costs nothing. |
|
|
140
|
+
| `upgradeSlope` | `0.15` | How much a switching cost can raise the bar: `base + slope × tax / (tax + pivot)`. |
|
|
141
|
+
| `upgradePivotUsd` | `0.5` | The switching cost that adds half of the slope. |
|
|
142
|
+
| `jumpConfidence` | `0.95` | The confidence for a jump of two tiers without the vote delay. |
|
|
143
|
+
| `downgradeVotes` | `2` | Consecutive votes for a lower tier before a downgrade. |
|
|
144
|
+
| `downgradeMass` | `0.9` | The downgrade bar when the candidate's cache is already warm. |
|
|
145
|
+
| `downgradeSlope` | `0.08` | How much a cold candidate's cache write can raise the bar, same formula as upgrade. |
|
|
146
|
+
| `downgradePivotUsd` | `0.5` | The switching cost that adds half of the slope. |
|
|
147
|
+
| `downgradeHorizonTurns` | `5` | The turns of output and read savings that a downgrade's tax nets. Input only without `output` prices. |
|
|
148
|
+
| `continuationMass` | `0.7` | The Jev probability for "continues the task" that keeps the route. |
|
|
149
|
+
| `escalationHoldTurns` | `2` | Turns that the route stays up after an escalation. |
|
|
150
|
+
| `cashCapUsd` | `2` | The cold-write guard: the largest first cache write for a switch to a `credits` model. |
|
|
150
151
|
|
|
151
152
|
### cache, jev, context, log
|
|
152
153
|
|
package/docs/user-guide.md
CHANGED
|
@@ -143,7 +143,7 @@ log has no prompt text.
|
|
|
143
143
|
| `reason` | The rule that decided. Tool calls show `tool-continuation`. `error`: routing failed and the default tier served. |
|
|
144
144
|
| `advice` | The Jev probabilities for each tier, and for "continues the task". |
|
|
145
145
|
| `estimate` | The numbers of a vote: confidence, bar, switching tax, cache state. |
|
|
146
|
-
| `shadow` | The cost of the Jev choice against the current route. The
|
|
146
|
+
| `shadow` | The cost of the Jev choice against the current route. The downgrade tax uses the same arithmetic. |
|
|
147
147
|
| `observed` | The usage of the response: model, effort, context tokens, cache reads, output. |
|
|
148
148
|
| `failed` | Anthropic answered a routed turn with an error: status, tier, model, effort. |
|
|
149
149
|
| `historyBreak` | A compaction or a rewind. The votes and the cache estimates reset. |
|
package/lib/config.mjs
CHANGED
|
@@ -24,7 +24,7 @@ export const DEFAULTS = {
|
|
|
24
24
|
},
|
|
25
25
|
// `id` is sent upstream verbatim. List prices in USD per million tokens; `cacheRead` is absolute,
|
|
26
26
|
// not a multiplier (Opus 5.5 reads at 0.05x input, the rest at the standard 0.1x). A price change must also change
|
|
27
|
-
// test/fixtures/list-prices.json, with its source and date. `output` feeds
|
|
27
|
+
// test/fixtures/list-prices.json, with its source and date. `output` feeds the shadow estimate and the downgrade tax.
|
|
28
28
|
// `efforts` lists what the model accepts; an empty list means no effort field and no adaptive thinking. A change
|
|
29
29
|
// must also change test/fixtures/effort-support.json, from a new probe against the real API.
|
|
30
30
|
// `features` lists the FEATURES the model accepts; the gateway removes the others from the request. A model
|
|
@@ -79,6 +79,7 @@ export const DEFAULTS = {
|
|
|
79
79
|
downgradeMass: 0.9,
|
|
80
80
|
downgradeSlope: 0.08, // a cold candidate raises the bar toward ~0.98, same shape as the upgrade bar
|
|
81
81
|
downgradePivotUsd: 0.5,
|
|
82
|
+
downgradeHorizonTurns: 5, // turns whose output and read savings offset a downgrade's cache write
|
|
82
83
|
continuationMass: 0.7,
|
|
83
84
|
escalationHoldTurns: 2,
|
|
84
85
|
// Ceiling on a cold cache write to a `credits` model. No default model bills credits, so this is
|
|
@@ -213,12 +214,14 @@ function validate(config) {
|
|
|
213
214
|
for (const field of ['upgradeBase', 'jumpConfidence', 'downgradeMass', 'continuationMass']) {
|
|
214
215
|
if (!(isNumber(p[field], 0) && p[field] <= 1)) throw new Error(`policy.${field} must be between 0 and 1`);
|
|
215
216
|
}
|
|
216
|
-
for (const field of ['upgradeVotes', 'downgradeVotes', 'escalationHoldTurns']) {
|
|
217
|
+
for (const field of ['upgradeVotes', 'downgradeVotes', 'downgradeHorizonTurns', 'escalationHoldTurns']) {
|
|
217
218
|
if (!isNumber(p[field], 1, { integer: true })) throw new Error(`policy.${field} must be a positive integer`);
|
|
218
219
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
// The pivot divides: tax / (tax + pivot). Zero makes a free switch NaN and silently stops that switch.
|
|
221
|
+
for (const side of ['upgrade', 'downgrade']) {
|
|
222
|
+
if (!isNumber(p[`${side}Slope`], 0)) throw new Error(`policy.${side}Slope must be a non-negative number`);
|
|
223
|
+
if (!isNumber(p[`${side}PivotUsd`], 0, { above: true })) throw new Error(`policy.${side}PivotUsd must be positive`);
|
|
224
|
+
}
|
|
222
225
|
if (!isNumber(p.cashCapUsd, 0)) throw new Error('policy.cashCapUsd must be a non-negative number');
|
|
223
226
|
const { cache, jev, context } = config;
|
|
224
227
|
for (const map of ['writeMultiplier', 'ttlMs']) {
|
package/lib/cost.mjs
CHANGED
|
@@ -62,9 +62,9 @@ export function switchingTaxUsd(config, candidateTier, incumbentTier, facts, now
|
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// Shadow estimate for the decision log; the
|
|
66
|
-
// list-price equivalent, not a charge. Output uses the last observed output size for both routes, although
|
|
67
|
-
// changes how much a model writes.
|
|
65
|
+
// Shadow estimate for the decision log; the downgrade tax nets it over a horizon. At list prices, so for `plan` models
|
|
66
|
+
// it is a list-price equivalent, not a charge. Output uses the last observed output size for both routes, although
|
|
67
|
+
// effort changes how much a model writes.
|
|
68
68
|
// - nextTurnUsd: candidate minus incumbent for the next request, input at the current cache state plus output.
|
|
69
69
|
// - laterTurnUsd: the same difference for each later turn, once both caches are warm.
|
|
70
70
|
// - paybackTurns: 0 when the switch is cheaper at once, n when later turns repay it after n turns, null when never.
|
|
@@ -82,3 +82,12 @@ export function shadowEconomics(config, candidateTier, incumbentTier, facts, now
|
|
|
82
82
|
else if (nextTurnUsd > 0 && laterTurnUsd < 0) paybackTurns = Math.ceil(nextTurnUsd / -laterTurnUsd);
|
|
83
83
|
return { nextTurnUsd, laterTurnUsd, paybackTurns, outputTokens };
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
// A downgrade's tax over `turns` turns: the next one plus the later ones, output included. A missing or zero output
|
|
87
|
+
// price is unknown, not free, so the tax then falls back to the next request's input alone.
|
|
88
|
+
export function downgradeTaxUsd(config, candidateTier, incumbentTier, facts, now, turns) {
|
|
89
|
+
const priced = [candidateTier, incumbentTier].every((tier) => modelOf(config, tier).output > 0);
|
|
90
|
+
if (!priced) return Math.max(0, switchingTaxUsd(config, candidateTier, incumbentTier, facts, now));
|
|
91
|
+
const { nextTurnUsd, laterTurnUsd } = shadowEconomics(config, candidateTier, incumbentTier, facts, now);
|
|
92
|
+
return Math.max(0, nextTurnUsd + (turns - 1) * laterTurnUsd);
|
|
93
|
+
}
|
package/lib/policy.mjs
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// Switching policy v0 (docs/architecture.md): stickiness, escalation floor, cost-gated votes.
|
|
2
2
|
import { rank, TIERS } from './config.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
cacheState,
|
|
5
|
+
coldWriteUsd,
|
|
6
|
+
downgradeTaxUsd,
|
|
7
|
+
isWarm,
|
|
8
|
+
nextContextTokens,
|
|
9
|
+
routeCacheKey,
|
|
10
|
+
switchingTaxUsd,
|
|
11
|
+
} from './cost.mjs';
|
|
4
12
|
|
|
5
13
|
export function initialState() {
|
|
6
14
|
return { turn: 0, votes: [], holdUntilTurn: 0, escalatedSignature: null };
|
|
@@ -49,8 +57,8 @@ export function decide({ config, facts, advice, state, baseline, now }) {
|
|
|
49
57
|
const support = massAtOrBelow(advice.probabilities, choice);
|
|
50
58
|
const streak = trailing(next.votes, (v) => rank(v.tier) <= rank(choice));
|
|
51
59
|
// A downgrade is not always cheaper this turn: a cold candidate next to a warm incumbent can pay a bigger cache
|
|
52
|
-
// write than it saves. The bar rises with that cost the
|
|
53
|
-
const tax =
|
|
60
|
+
// write than it saves. The bar rises with that cost, net of what the next turns save, the way the upgrade bar does.
|
|
61
|
+
const tax = downgradeTaxUsd(config, choice, incumbent, facts, now, config.policy.downgradeHorizonTurns);
|
|
54
62
|
const threshold =
|
|
55
63
|
config.policy.downgradeMass + config.policy.downgradeSlope * (tax / (tax + config.policy.downgradePivotUsd));
|
|
56
64
|
const estimate = { downgradeMass: support, streak, taxUsd: tax, threshold };
|
package/lib/router.mjs
CHANGED
|
@@ -185,7 +185,8 @@ export class Router {
|
|
|
185
185
|
}
|
|
186
186
|
const now = this.now();
|
|
187
187
|
const decision = decide({ config: this.config, facts, advice, state, baseline: gateway.baselineTier, now });
|
|
188
|
-
// Shadow only: what following Jev's choice instead of staying would cost at list prices. The policy
|
|
188
|
+
// Shadow only: what following Jev's choice instead of staying would cost at list prices. The policy does not read
|
|
189
|
+
// this record; the downgrade tax computes its own from the same function.
|
|
189
190
|
const incumbent = TIERS.includes(facts.lastRoute) ? facts.lastRoute : gateway.baselineTier;
|
|
190
191
|
const shadow =
|
|
191
192
|
TIERS.includes(advice?.choice) && advice.choice !== incumbent
|
package/package.json
CHANGED