@alexeiled/claude-router 1.19.1 → 1.20.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 +22 -0
- package/README.md +2 -0
- package/docs/configuration.md +1 -0
- package/docs/evaluation.md +8 -0
- package/docs/providers.md +122 -2
- package/docs/user-guide.md +6 -0
- package/lib/band.mjs +10 -5
- package/lib/display.mjs +94 -11
- package/lib/panel.mjs +139 -42
- package/lib/usage.mjs +2 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "router",
|
|
3
3
|
"displayName": "Router",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.20.0",
|
|
5
5
|
"description": "Native model and effort routing within your provider. Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi defaults, custom provider profiles, classifier advice and one model per subagent.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Alexei Ledenev",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.20.0 (2026-11-03)
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Keep plan and credits apart when a profile mixes them, such as model-proxy with Opus and DeepSeek. The band, `/router`, the Now tab and Usage give each billing its own difference against your model, `routing credits +$4.10 · plan −$50.00 vs Opus 5.5 · medium`, instead of one sum that added plan quota to paid credits. The ledger becomes a per-billing table; cross-billing parts, `vs yours` cells and findings are left out. Single-billing profiles read as before.
|
|
8
|
+
- Document how the model-proxy launch model sets both the fallback and the comparison, and which tier each launch model starts at.
|
|
9
|
+
|
|
10
|
+
### Upgrade
|
|
11
|
+
|
|
12
|
+
Restart Claude Code after updating. No router-file or record changes are needed: existing records split by the billing of the models they name.
|
|
13
|
+
|
|
14
|
+
## 1.19.2 (2026-11-01)
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Document the explicit `model-proxy` custom profile for mixed Anthropic and DeepSeek sessions through a separately started native proxy. No built-in mixed-provider defaults, endpoint switching or credential handling are added to the Mod.
|
|
19
|
+
- Verify two-provider route switching, response-ID normalization, profile isolation and selected-file saves with the existing native hook harness.
|
|
20
|
+
|
|
21
|
+
### Upgrade
|
|
22
|
+
|
|
23
|
+
Restart Claude Code after updating. Existing profiles need no changes. To opt in, create a complete `model-proxy-router.json` in the selected account directory and follow the proxy setup guide. Every selected provider receives the unchanged conversation history.
|
|
24
|
+
|
|
3
25
|
## 1.19.1 (2026-10-31)
|
|
4
26
|
|
|
5
27
|
### Fixed
|
package/README.md
CHANGED
|
@@ -109,6 +109,8 @@ The Anthropic profile uses these activity defaults. Other profiles have [their o
|
|
|
109
109
|
|
|
110
110
|
A [routing mode](docs/routing-modes.md) trades cost against answer quality without new routes: `cost` takes a cheaper model or one effort level less where a turn allows it, `quality` one effort level more or the tier above, and `balanced`, the default, runs the routes as configured. Set it per session with `/router mode cost`, per project in `.claude/router.json`, or for the profile with `"mode"` in `router.json`.
|
|
111
111
|
|
|
112
|
+
For mixed Anthropic and DeepSeek sessions, use the explicit [model-proxy profile](docs/providers.md#mix-anthropic-and-deepseek-with-model-proxy) with a separately started local proxy. No built-in mixed-provider defaults are installed.
|
|
113
|
+
|
|
112
114
|
## Install
|
|
113
115
|
|
|
114
116
|
You need Claude Code 2.1.289 or newer and credentials for one [supported classifier](#supported-classifiers).
|
package/docs/configuration.md
CHANGED
|
@@ -58,6 +58,7 @@ New provider sources: [MiniMax pricing](https://platform.minimax.io/docs/pricing
|
|
|
58
58
|
[MiMo pricing](https://mimo.mi.com/docs/en-US/pricing), and [Kimi pricing](https://platform.kimi.ai/docs/pricing/chat).
|
|
59
59
|
All non-Anthropic built-in presets use `billing: "credits"`.
|
|
60
60
|
For an included-plan model, set `billing: "plan"` to disable the cold-input cash cap.
|
|
61
|
+
When a profile mixes plan and credits models, Usage gives each billing its own difference instead of one sum; see [plan and credits apart](user-guide.md#plan-and-credits-apart).
|
|
61
62
|
A provider name or URL does not establish its billing product.
|
|
62
63
|
|
|
63
64
|
### Provider cache behavior
|
package/docs/evaluation.md
CHANGED
|
@@ -222,3 +222,11 @@ Limits:
|
|
|
222
222
|
- Failure signatures and pins are not present in the trace. The relevant route decisions are excluded from comparison.
|
|
223
223
|
- Most main rows are tool continuations or have no Jev advice. Only 37 advised decisions support the native comparison.
|
|
224
224
|
- Costs cover the next request. They use the last observed output size and do not model effort-dependent output length or future answer quality.
|
|
225
|
+
|
|
226
|
+
## model-proxy integration
|
|
227
|
+
|
|
228
|
+
The explicit two-provider profile is covered by custom-profile validation, native hook harness switching, bare response-ID normalization, selected-file saves and automatic-advice cases. There are no built-in mixed-provider model defaults.
|
|
229
|
+
|
|
230
|
+
A scoped native check on 2026-11-01 used Router 1.19.1 with Claude Code 2.1.316, the new proxy helper and an explicitly selected work account directory. A synthetic conversation completed pinned DeepSeek → Opus → DeepSeek with Read-tool continuation, followed by a successful automatic turn with Jev healthy. The proxy's [verification report](https://github.com/alexei-led/claude-proxy/blob/main/docs/verification.md#two-provider-integration-for-v013) owns this transport evidence.
|
|
231
|
+
|
|
232
|
+
This is not a routing-quality, savings, full-context or universal provider-history benchmark. Automatic switching in both directions remains covered by controlled harness cases rather than that pinned live sequence.
|
package/docs/providers.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Providers
|
|
2
2
|
|
|
3
|
-
Claude Router routes models and effort
|
|
4
|
-
Set a provider name and give the router a matching JSON file.
|
|
3
|
+
Claude Router routes models and effort through the Anthropic-compatible endpoint that Claude Code already uses.
|
|
4
|
+
Set a provider name and give the router a matching JSON file. Direct provider profiles need no proxy. The optional `model-proxy` profile uses a separately started local proxy.
|
|
5
5
|
|
|
6
6
|
**Built-in profiles:** Anthropic, DeepSeek, z.ai, MiniMax, MiMo and Kimi.
|
|
7
7
|
**Custom profiles:** OpenRouter, Ollama, other local servers, and other hosted providers with a Claude Code-compatible Anthropic endpoint.
|
|
@@ -45,6 +45,7 @@ The directory is `CLAUDE_CONFIG_DIR` when set, otherwise `~/.claude`.
|
|
|
45
45
|
| `minimax` | `minimax-router.json` | MiniMax-M3.1-Flash |
|
|
46
46
|
| `mimo` | `mimo-router.json` | MiMo-V2.6-Flash, MiMo-V2.6-Pro |
|
|
47
47
|
| `kimi` | `kimi-router.json` | Kimi-K3.1-Pro |
|
|
48
|
+
| `model-proxy` | `model-proxy-router.json` | None. Supply an explicit mixed-provider profile. |
|
|
48
49
|
| `openrouter` | `openrouter-router.json` | None. Supply a complete profile. |
|
|
49
50
|
| `ollama` | `ollama-router.json` | None. Supply a complete profile. |
|
|
50
51
|
| Any other valid name | `<provider>-router.json` | None. Supply a complete profile. |
|
|
@@ -206,6 +207,125 @@ MiMo's cost/quality modes change models where a neighbouring tier permits it; ot
|
|
|
206
207
|
Kimi uses only `low`, `high`, `max`, the documented controls, and never promotes a session into another model.
|
|
207
208
|
These are starting policies, not an optimal activity matrix. See [research and experiments](provider-experiments.md).
|
|
208
209
|
|
|
210
|
+
## Mix Anthropic and DeepSeek with model-proxy
|
|
211
|
+
|
|
212
|
+
`model-proxy` is a custom execution profile, not another classifier or routing engine.
|
|
213
|
+
Claude Code sends every request to one local `claude-proxy` endpoint. The proxy selects an explicitly configured upstream from the native model ID.
|
|
214
|
+
|
|
215
|
+
1. Install and configure [claude-proxy](https://github.com/alexei-led/claude-proxy/blob/main/docs/integration.md).
|
|
216
|
+
2. Save the following complete profile as `model-proxy-router.json` in the selected Claude Code configuration directory.
|
|
217
|
+
3. Start the proxy manually, then use its `connect` command from v0.1.4 or newer.
|
|
218
|
+
Older proxies forward Claude Code's built-in Artifact tool schema unchanged, and DeepSeek rejects its `pattern` regex with `400 Invalid schema for function 'Artifact'`.
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"models": {
|
|
223
|
+
"deepseek": {
|
|
224
|
+
"id": "deepseek-flash[1m]",
|
|
225
|
+
"input": 0.3,
|
|
226
|
+
"output": 1.2,
|
|
227
|
+
"cacheRead": 0.006,
|
|
228
|
+
"contextWindow": 1000000,
|
|
229
|
+
"billing": "credits",
|
|
230
|
+
"efforts": [
|
|
231
|
+
"low",
|
|
232
|
+
"high",
|
|
233
|
+
"max"
|
|
234
|
+
],
|
|
235
|
+
"strength": 3,
|
|
236
|
+
"imageInput": true
|
|
237
|
+
},
|
|
238
|
+
"claude": {
|
|
239
|
+
"id": "claude-opus-5-5",
|
|
240
|
+
"input": 4,
|
|
241
|
+
"output": 20,
|
|
242
|
+
"cacheRead": 0.2,
|
|
243
|
+
"contextWindow": 1000000,
|
|
244
|
+
"billing": "plan",
|
|
245
|
+
"efforts": [
|
|
246
|
+
"low",
|
|
247
|
+
"medium",
|
|
248
|
+
"high",
|
|
249
|
+
"xhigh",
|
|
250
|
+
"max"
|
|
251
|
+
],
|
|
252
|
+
"strength": 4
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"routes": {
|
|
256
|
+
"micro": {
|
|
257
|
+
"model": "deepseek",
|
|
258
|
+
"effort": "low"
|
|
259
|
+
},
|
|
260
|
+
"low": {
|
|
261
|
+
"model": "deepseek",
|
|
262
|
+
"effort": "low"
|
|
263
|
+
},
|
|
264
|
+
"medium": {
|
|
265
|
+
"model": "deepseek",
|
|
266
|
+
"effort": "high"
|
|
267
|
+
},
|
|
268
|
+
"high": {
|
|
269
|
+
"model": "claude",
|
|
270
|
+
"effort": "xhigh"
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
"activityRouting": "off",
|
|
274
|
+
"subagentRouting": "off",
|
|
275
|
+
"cache": {
|
|
276
|
+
"mode": "disabled"
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
These are experimental starting routes, not measured quality rankings. Both lower tiers use DeepSeek at low effort; medium uses high effort; high uses Opus at xhigh.
|
|
282
|
+
The price fields are API list-price estimates, not subscription charges. DeepSeek values use peak prices.
|
|
283
|
+
Cache-cost assumptions, activity routing and subagent routing are off initially; upstream caching remains active.
|
|
284
|
+
The default classifier is Jev and needs its existing plugin credential. Select another configured classifier explicitly if needed; no local classifier server is required.
|
|
285
|
+
|
|
286
|
+
```sh
|
|
287
|
+
# Terminal 1: the selected account's proxy configuration
|
|
288
|
+
claude-proxy --config /path/to/proxy.json
|
|
289
|
+
|
|
290
|
+
# Terminal 2: preserve that account's existing CLAUDE_CONFIG_DIR
|
|
291
|
+
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 CLAUDE_CODE_ATTRIBUTION_HEADER=0 ENABLE_TOOL_SEARCH=false \
|
|
292
|
+
claude-proxy connect --config /path/to/proxy.json -- claude --model 'deepseek-flash[1m]'
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Any turn may reach DeepSeek, so set the same Claude Code flags a direct DeepSeek session needs:
|
|
296
|
+
|
|
297
|
+
| Variable | Why |
|
|
298
|
+
| --- | --- |
|
|
299
|
+
| `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` | Drops beta request fields that third-party endpoints reject. Opus turns lose those betas too. |
|
|
300
|
+
| `CLAUDE_CODE_ATTRIBUTION_HEADER=0` | Omits the per-version attribution block, so the system prompt stays cacheable upstream. |
|
|
301
|
+
| `ENABLE_TOOL_SEARCH=false` | Tool search sends `tool_definition` blocks; DeepSeek answers `422 unknown variant`. |
|
|
302
|
+
|
|
303
|
+
`connect` supplies `CLAUDE_ROUTER_PROVIDER=model-proxy`, the local URL and the separate local access header only to the child process.
|
|
304
|
+
It does not change saved OAuth, configure provider keys, start the proxy, or install this Mod.
|
|
305
|
+
Without the helper, the proxy guide documents equivalent process-local environment setup.
|
|
306
|
+
Endpoint and credential fields do not belong in this router JSON.
|
|
307
|
+
|
|
308
|
+
### Choose the launch model
|
|
309
|
+
|
|
310
|
+
The `--model` you launch with is your model, as in any profile. It serves the turns routing does not choose, and Usage compares the routed replies against it.
|
|
311
|
+
Launch on the model you would otherwise use:
|
|
312
|
+
|
|
313
|
+
| Launch model | Routing starts | Usage compares with |
|
|
314
|
+
| --- | --- | --- |
|
|
315
|
+
| `deepseek-flash[1m]` | at `low`, on DeepSeek | DeepSeek: Opus turns show as plan quota spent and credits saved |
|
|
316
|
+
| `claude-opus-5-5` | at `high`, on Opus, until the classifier supports a cheaper tier | Opus: DeepSeek turns show as credits spent and plan quota saved |
|
|
317
|
+
|
|
318
|
+
A launch model must be a model that some route runs. On any other model, a fresh session starts with routing off.
|
|
319
|
+
To start on another Claude model, such as Sonnet, add it to `models`, put it on a route, and map it in the proxy configuration.
|
|
320
|
+
|
|
321
|
+
Opus is billed by the plan and DeepSeek in credits, so Usage keeps the two apart: `routing credits +$4.10 · plan −$50.00 vs Opus 5.5 · medium`.
|
|
322
|
+
See [plan and credits apart](user-guide.md#plan-and-credits-apart).
|
|
323
|
+
|
|
324
|
+
Open `/router` and check the selected file, classifier health and routing state before use.
|
|
325
|
+
The catalog must contain the bare native IDs; `[1m]` is client metadata, not a proxy alias.
|
|
326
|
+
Every selected provider receives the unchanged history. Approve each destination; do not mix company context into an unapproved provider.
|
|
327
|
+
Native Anthropic support does not guarantee compatibility with every tool or thinking history. Start with a fresh, non-sensitive conversation.
|
|
328
|
+
|
|
209
329
|
## Add another provider
|
|
210
330
|
|
|
211
331
|
No code change or provider registration is needed.
|
package/docs/user-guide.md
CHANGED
|
@@ -124,6 +124,12 @@ When the whole period is comparable, the answer comes first, in the band's words
|
|
|
124
124
|
| + Cache rebuilds | What rewriting the prompt cache after a model switch cost, and its share of the saving. |
|
|
125
125
|
| = Routed | What the routed replies cost, with a bar against your model: `54% of your model`, or `×2.1`. |
|
|
126
126
|
|
|
127
|
+
#### Plan and credits apart
|
|
128
|
+
|
|
129
|
+
A profile can mix models billed by a Claude plan (`billing: "plan"`) with models billed in credits (`billing: "credits"`), such as the [model-proxy profile](providers.md#mix-anthropic-and-deepseek-with-model-proxy). Plan dollars stand for quota; credits are paid. When the replies ran on, or are compared with, models of both billings, every readout gives each billing its own difference instead of one sum: `routing credits +$4.10 · plan −$50.00 vs Opus 5.5 · medium`. Here routing spent $4.10 of credits on DeepSeek and saved $50.00 of Opus quota at list prices. The ledger becomes a table of routed cost, your model's cost and the difference per billing. The cheaper, stronger and cache-rebuild parts are left out, because each would subtract quota from cash. In **BY**, a row whose models are not billed as your model is names its billing (`credits`, `plan` or `both`) in place of `vs yours`. **What if** names it the same way, and **WORTH A LOOK** keeps only the share of the cost.
|
|
130
|
+
|
|
131
|
+
A model's billing comes from the selected profile, or from a built-in profile when the selected file does not list that model. If your models themselves span both billings in the period, for example after `/model` moved between Opus and DeepSeek, there is no single model to compare with. The readout then shows what each billing cost: `observed credits $4.10 · plan $20.00 · your models mix plan and credits`. A model that no profile prices, and **All** with totals from before dated records, keep the single sum.
|
|
132
|
+
|
|
127
133
|
A line of counts follows: replies, turns, input tokens, the share of the input read from the cache, and output tokens. With routing off or unavailable and no routed reply this session, the tab says the replies use your model and are not counted.
|
|
128
134
|
|
|
129
135
|
**BY** splits the period's cost by **Activity**, **Model** or **Tier**. Press `g` for the next grouping. Each row gives the replies, the routed cost and `vs yours`, the difference against your model. The last column is the route most of the row's replies used, or, by model, the row's share of the cost. Select **▸** to open a row. An activity lists its routes, and a model or a tier lists its activities. A line under them gives the row's cheaper, stronger and switch parts and its tokens. A narrow pane drops the last column first.
|
package/lib/band.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { activeClassifier, TIERS } from './config.mjs';
|
|
2
2
|
import {
|
|
3
3
|
activityVerb,
|
|
4
|
+
answerSegments,
|
|
5
|
+
billingSplit,
|
|
4
6
|
classifierLabel,
|
|
5
7
|
classifierStatus,
|
|
6
8
|
classifierWarns,
|
|
@@ -14,11 +16,11 @@ import {
|
|
|
14
16
|
percentPair,
|
|
15
17
|
reasonActivity,
|
|
16
18
|
routeLabel,
|
|
17
|
-
routingAnswer,
|
|
18
19
|
routingModeText,
|
|
19
20
|
savingsColor,
|
|
20
21
|
sessionUsage,
|
|
21
22
|
shortReason,
|
|
23
|
+
splitCompared,
|
|
22
24
|
TIER_COLOR,
|
|
23
25
|
unavailableReason,
|
|
24
26
|
usageMetrics,
|
|
@@ -221,9 +223,10 @@ export function sessionRow(config, view, columns, now = Date.now()) {
|
|
|
221
223
|
const label = part('session ', { dimColor: true });
|
|
222
224
|
const summary = sessionUsage(view, now);
|
|
223
225
|
const r = readout(summary);
|
|
226
|
+
const split = billingSplit(config, summary);
|
|
224
227
|
if (summary.observed.uncomparedReplies)
|
|
225
228
|
return fitSegments(
|
|
226
|
-
[segment(0, label, part(observedUsageText(summary.observed), { dimColor: true }))],
|
|
229
|
+
[segment(0, label, part(observedUsageText(summary.observed, split), { dimColor: true }))],
|
|
227
230
|
columns,
|
|
228
231
|
).flatMap((s) => s.parts);
|
|
229
232
|
if (!modelSpec(config, view.nativeModel))
|
|
@@ -232,9 +235,9 @@ export function sessionRow(config, view, columns, now = Date.now()) {
|
|
|
232
235
|
const count = `${r.replies} repl${r.replies === 1 ? 'y' : 'ies'}`;
|
|
233
236
|
const answer = [
|
|
234
237
|
label,
|
|
235
|
-
|
|
236
|
-
part(` vs ${comparedModel(config, view, summary)}`),
|
|
237
|
-
];
|
|
238
|
+
...answerSegments(r, split).map(({ text, value }) => part(text, { color: savingsColor(value), bold: true })),
|
|
239
|
+
split && !splitCompared(split) ? null : part(` vs ${comparedModel(config, view, summary)}`),
|
|
240
|
+
].filter(Boolean);
|
|
238
241
|
const width = (row) => row.reduce((n, p) => n + p.text.length, 0);
|
|
239
242
|
const fit = (rows) =>
|
|
240
243
|
fitSegments(
|
|
@@ -244,6 +247,8 @@ export function sessionRow(config, view, columns, now = Date.now()) {
|
|
|
244
247
|
// Below EARLY_REPLIES one switch decides the sum, so the parts wait, as on the pane.
|
|
245
248
|
if (r.early) return fit([[...answer, part(`${SEPARATOR}${count} · early sample`, { dimColor: true })], answer]);
|
|
246
249
|
const replies = part(`${SEPARATOR}${count}`, { dimColor: true });
|
|
250
|
+
// Per billing the parts would subtract quota from cash: a split shows its two differences alone.
|
|
251
|
+
if (split) return fit([[...answer, replies], answer]);
|
|
247
252
|
const parts = costParts(r);
|
|
248
253
|
const named = parts.flatMap(([amount, words, value], i) => [
|
|
249
254
|
part(i ? ' ' : ' = ', { dimColor: true }),
|
package/lib/display.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { readMetrics, readStore, storeSummary, UNPRICED_CAUSES } from './activit
|
|
|
3
3
|
import {
|
|
4
4
|
activeClassifier,
|
|
5
5
|
CLASSIFIER_OPTIONS,
|
|
6
|
+
DEFAULTS,
|
|
6
7
|
endpointSettings,
|
|
7
8
|
resolveRoute,
|
|
8
9
|
routeSpec,
|
|
@@ -12,9 +13,10 @@ import {
|
|
|
12
13
|
import { ratesAt } from './cost.mjs';
|
|
13
14
|
import { applyMode, modeLabel, modeRoute } from './modes.mjs';
|
|
14
15
|
import { PROBE_RESULTS } from './probe-results.mjs';
|
|
16
|
+
import { PROVIDER_DEFAULTS } from './providers.mjs';
|
|
15
17
|
import { cellForModel } from './route.mjs';
|
|
16
18
|
import { modelSpec, readout } from './savings.mjs';
|
|
17
|
-
import { allTime, periodRange, readUsage, summarize, withReplies } from './usage.mjs';
|
|
19
|
+
import { allTime, breakdown, periodRange, readUsage, summarize, withReplies } from './usage.mjs';
|
|
18
20
|
|
|
19
21
|
// Cost order, cheapest first, so the colors read as a scale. Hex values: every surface draws them.
|
|
20
22
|
export const TIER_COLOR = { micro: '#5fd7af', low: '#5f9fe0', medium: '#d7af5f', high: '#e0708a' };
|
|
@@ -345,9 +347,87 @@ export const liveUsage = (view, record) => withReplies(readUsage(record), view.u
|
|
|
345
347
|
// This session's routed replies, the running turns' included.
|
|
346
348
|
export const sessionUsage = (view, now) => summarize(liveUsage(view, view.usageSession), periodRange('session', now));
|
|
347
349
|
|
|
348
|
-
// Observed spend is valid even when a counterfactual cache history cannot be priced.
|
|
349
|
-
|
|
350
|
-
|
|
350
|
+
// Observed spend is valid even when a counterfactual cache history cannot be priced. With a billing split, each
|
|
351
|
+
// billing's spend: plan and credits are not added.
|
|
352
|
+
export const observedUsageText = (observed, split = null) =>
|
|
353
|
+
`observed ${split ? billingCosts(split, 'observedUsd') : usd(observed.routedUsd)} · ${observed.replies} repl${observed.replies === 1 ? 'y' : 'ies'} · comparison unavailable`;
|
|
354
|
+
|
|
355
|
+
// Plan and credits are different money: on a Claude plan the list-price dollars stand for quota, credits are paid.
|
|
356
|
+
export const BILLINGS = ['credits', 'plan'];
|
|
357
|
+
// The billing of the model an API id runs on: the selected profile's entry, else a built-in profile's, so a period
|
|
358
|
+
// that holds another profile's sessions still reads. Null for a model no profile prices.
|
|
359
|
+
const BUILT_IN_PROFILES = [DEFAULTS, ...Object.values(PROVIDER_DEFAULTS)];
|
|
360
|
+
export function billingOf(config, id) {
|
|
361
|
+
for (const profile of [config, ...BUILT_IN_PROFILES]) {
|
|
362
|
+
const spec = modelSpec(profile, id);
|
|
363
|
+
if (spec) return spec.billing;
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const wholeCents = (value) => Math.round(value * 100) / 100;
|
|
368
|
+
|
|
369
|
+
// A summary told per billing when its replies ran on, or are compared with, both plan and credits models: one sum
|
|
370
|
+
// would add quota to cash. `yours` is your model's billing; per billing, in whole cents: `observedUsd` what every
|
|
371
|
+
// reply cost, `routedUsd` what the compared replies cost, and `yoursUsd` your model's cost for them, all of it in your
|
|
372
|
+
// model's billing. `yours` and `yoursUsd` are null when your models themselves span both billings: a record keeps
|
|
373
|
+
// which model was yours, not each reply's cost on it. Null when one billing covers every model, or some model has no
|
|
374
|
+
// known billing: the one-sum readout stands then.
|
|
375
|
+
export function billingSplit(config, summary) {
|
|
376
|
+
const seen = new Set();
|
|
377
|
+
const costs = (cells) => {
|
|
378
|
+
const out = { credits: 0, plan: 0 };
|
|
379
|
+
for (const { name, sums } of breakdown(cells, 'model')) {
|
|
380
|
+
const billing = billingOf(config, name);
|
|
381
|
+
if (!billing) return null;
|
|
382
|
+
seen.add(billing);
|
|
383
|
+
out[billing] += sums[1];
|
|
384
|
+
}
|
|
385
|
+
return out;
|
|
386
|
+
};
|
|
387
|
+
const observed = costs(summary.observed.cells);
|
|
388
|
+
const routed = costs(summary.cells);
|
|
389
|
+
const yours = new Set(Object.keys(summary.yours).map((id) => billingOf(config, id)));
|
|
390
|
+
if (!observed || !routed || yours.has(null)) return null;
|
|
391
|
+
for (const billing of yours) seen.add(billing);
|
|
392
|
+
if (seen.size < 2) return null;
|
|
393
|
+
const mine = yours.size === 1 ? [...yours][0] : null;
|
|
394
|
+
const side = (billing) => ({
|
|
395
|
+
observedUsd: wholeCents(observed[billing]),
|
|
396
|
+
routedUsd: wholeCents(routed[billing]),
|
|
397
|
+
yoursUsd: mine === null ? null : billing === mine ? wholeCents(summary.yoursUsd) : 0,
|
|
398
|
+
});
|
|
399
|
+
return { yours: mine, credits: side('credits'), plan: side('plan') };
|
|
400
|
+
}
|
|
401
|
+
// The split of every reply kept across sessions (allTime). Limit: the undated totals from before the usage records
|
|
402
|
+
// name no models, so while they hold replies the one sum stands.
|
|
403
|
+
export const keptSplit = (config, kept) => (kept.legacy.replies ? null : billingSplit(config, kept.summary));
|
|
404
|
+
|
|
405
|
+
// "credits $4.10 · plan $20.00": each billing's `key` sum.
|
|
406
|
+
const billingCosts = (split, key) => BILLINGS.map((billing) => `${billing} ${usd(split[billing][key])}`).join(' · ');
|
|
407
|
+
// Routing against your model in one billing, in whole cents: minus is less than your model.
|
|
408
|
+
export const billingDifference = (side) => wholeCents(side.routedUsd - side.yoursUsd);
|
|
409
|
+
// Every compared reply of the split is priced against models of one billing.
|
|
410
|
+
export const splitCompared = (split) => split.yours !== null;
|
|
411
|
+
|
|
412
|
+
// The answer as text parts, each with the signed amount that colors it (null: plain): one sum, "routing −$1.84
|
|
413
|
+
// (−22%)"; per billing, "routing credits +$4.10 · plan −$61.20"; or, when your models span both billings, what each
|
|
414
|
+
// billing cost, "observed credits $4.10 · plan $20.00 · your models mix plan and credits".
|
|
415
|
+
export function answerSegments(r, split) {
|
|
416
|
+
if (!split) return [{ text: routingAnswer(r), value: r.differenceUsd }];
|
|
417
|
+
if (!splitCompared(split))
|
|
418
|
+
return [{ text: `observed ${billingCosts(split, 'routedUsd')} · your models mix plan and credits`, value: null }];
|
|
419
|
+
return [
|
|
420
|
+
{ text: 'routing ', value: null },
|
|
421
|
+
...BILLINGS.flatMap((billing, i) => {
|
|
422
|
+
const value = billingDifference(split[billing]);
|
|
423
|
+
return [...(i ? [{ text: ' · ', value: null }] : []), { text: `${billing} ${signedUsd(value)}`, value }];
|
|
424
|
+
}),
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
export const answerText = (r, split) =>
|
|
428
|
+
answerSegments(r, split)
|
|
429
|
+
.map((segment) => segment.text)
|
|
430
|
+
.join('');
|
|
351
431
|
|
|
352
432
|
// The models a session's replies were priced against, when they are not the one `/model` selects now: after a
|
|
353
433
|
// `/model` change the record keeps each reply against the model selected when it ran. Null when they are.
|
|
@@ -382,23 +462,26 @@ export const switchesLost = (r) => r.switchUsd > 0 && r.switchUsd > -r.cheaperUs
|
|
|
382
462
|
export function savingsLine(config, view, now) {
|
|
383
463
|
const summary = sessionUsage(view, now);
|
|
384
464
|
const session = readout(summary);
|
|
465
|
+
const split = billingSplit(config, summary);
|
|
385
466
|
if (summary.observed.uncomparedReplies)
|
|
386
|
-
return `Session: ${observedUsageText(summary.observed)}${session.replies ? `; ${replyCount(session.replies)} comparable only: ${
|
|
467
|
+
return `Session: ${observedUsageText(summary.observed, split)}${session.replies ? `; ${replyCount(session.replies)} comparable only: ${answerText(session, split)}` : ''}, est. at list prices`;
|
|
387
468
|
const label = `vs ${comparedModel(config, view, summary)}`;
|
|
388
469
|
if (!session.replies) {
|
|
389
470
|
const kept = allTime(view.usageStore, view.savingsStore);
|
|
390
471
|
const across = readout(kept.totals);
|
|
472
|
+
const keptBy = keptSplit(config, kept);
|
|
391
473
|
if (kept.observed.uncomparedReplies)
|
|
392
|
-
return `Session ${label}: no routed replies yet; across sessions ${observedUsageText(kept.observed)}, est. at list prices`;
|
|
474
|
+
return `Session ${label}: no routed replies yet; across sessions ${observedUsageText(kept.observed, keptBy)}, est. at list prices`;
|
|
393
475
|
const saved = across.early
|
|
394
476
|
? ''
|
|
395
|
-
: `; ${
|
|
477
|
+
: `; ${answerText(across, keptBy)} since ${sinceDate(kept.since)}, each session against its own model`;
|
|
396
478
|
return `Session ${label}: no routed replies yet${saved}`;
|
|
397
479
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
480
|
+
// Per billing the parts would subtract quota from cash, so a split says its two differences alone.
|
|
481
|
+
const answer = split && !splitCompared(split) ? answerText(session, split) : `${answerText(session, split)} ${label}`;
|
|
482
|
+
if (session.early) return `Session: ${answer}, ${replyCount(session.replies)}, early sample, est. at list prices`;
|
|
483
|
+
const parts = split ? [] : costParts(session).map(([amount, words]) => `${amount} ${words}`);
|
|
484
|
+
return `Session: ${answer}${parts.length ? ` = ${parts.join(' ')}` : ''}, ${replyCount(session.replies)}, est. at list prices`;
|
|
402
485
|
}
|
|
403
486
|
|
|
404
487
|
export const GATEWAY_SETTINGS = 'v0.8 gateway settings remain · see /router';
|
package/lib/panel.mjs
CHANGED
|
@@ -18,6 +18,12 @@ import { effortSharesCache, routeEffort } from './cost.mjs';
|
|
|
18
18
|
import {
|
|
19
19
|
activityReading,
|
|
20
20
|
activityVerb,
|
|
21
|
+
answerSegments,
|
|
22
|
+
answerText,
|
|
23
|
+
BILLINGS,
|
|
24
|
+
billingDifference,
|
|
25
|
+
billingOf,
|
|
26
|
+
billingSplit,
|
|
21
27
|
COST_PART,
|
|
22
28
|
classifierLabel,
|
|
23
29
|
classifierStatus,
|
|
@@ -25,6 +31,7 @@ import {
|
|
|
25
31
|
formatTokens,
|
|
26
32
|
GATEWAY_CLEANUP,
|
|
27
33
|
GATEWAY_SETTINGS,
|
|
34
|
+
keptSplit,
|
|
28
35
|
liveUsage,
|
|
29
36
|
missingCredentials,
|
|
30
37
|
missingText,
|
|
@@ -37,7 +44,6 @@ import {
|
|
|
37
44
|
recordedModels,
|
|
38
45
|
routeLabel,
|
|
39
46
|
routeName,
|
|
40
|
-
routingAnswer,
|
|
41
47
|
routingModeOf,
|
|
42
48
|
routingModeText,
|
|
43
49
|
savingsColor,
|
|
@@ -45,6 +51,7 @@ import {
|
|
|
45
51
|
shownConfig,
|
|
46
52
|
signedUsd,
|
|
47
53
|
sparkline,
|
|
54
|
+
splitCompared,
|
|
48
55
|
switchesLost,
|
|
49
56
|
TIER_COLOR,
|
|
50
57
|
unavailableReason,
|
|
@@ -352,10 +359,10 @@ function nowTab(ui, config, view, usage, actions, _modelOptions, columns, now) {
|
|
|
352
359
|
// Today repeats this session's part of it until another session adds to it.
|
|
353
360
|
const ownToday = summarize(liveUsage(view, view.usageSession), periodRange('today', now));
|
|
354
361
|
if (today.observed.replies > ownToday.observed.replies)
|
|
355
|
-
out.push(ui.text(' '), ...todayLines(ui, today, actions, columns));
|
|
362
|
+
out.push(ui.text(' '), ...todayLines(ui, config, today, actions, columns));
|
|
356
363
|
out.push(
|
|
357
364
|
...sessionAgentLines(ui, view, actions, columns),
|
|
358
|
-
...worthLines(ui, today, actions, columns),
|
|
365
|
+
...worthLines(ui, config, today, actions, columns),
|
|
359
366
|
ui.text(' '),
|
|
360
367
|
ui.gauge('Context ', metrics.contextBar, contextSuffix(metrics)),
|
|
361
368
|
ui.line(
|
|
@@ -500,11 +507,12 @@ function sessionLines(ui, config, view, summary, actions, columns, now) {
|
|
|
500
507
|
if (!strip && !summary.observed.replies) return [ui.line(ui.head('SESSION'), ui.dim(' · no replies yet'))];
|
|
501
508
|
const out = [ui.line(ui.head('SESSION'), head.length ? ui.dim(` · ${head.join(' · ')}`) : null)];
|
|
502
509
|
// The band's session row, then the parts that add up to it.
|
|
510
|
+
const split = billingSplit(config, summary);
|
|
503
511
|
if (summary.observed.uncomparedReplies) {
|
|
504
512
|
out.push(
|
|
505
513
|
ui.line(
|
|
506
514
|
' ',
|
|
507
|
-
ui.text(observedUsageText(summary.observed)),
|
|
515
|
+
ui.text(observedUsageText(summary.observed, split)),
|
|
508
516
|
' ',
|
|
509
517
|
ui.Button({ key: 'usage-session', label: 'Usage', onPress: () => actions.usageFor('session') }),
|
|
510
518
|
),
|
|
@@ -512,11 +520,23 @@ function sessionLines(ui, config, view, summary, actions, columns, now) {
|
|
|
512
520
|
} else if (summary.replies) {
|
|
513
521
|
const r = readout(summary);
|
|
514
522
|
out.push(
|
|
515
|
-
answerLine(
|
|
523
|
+
answerLine(
|
|
524
|
+
ui,
|
|
525
|
+
r,
|
|
526
|
+
split,
|
|
527
|
+
comparedModel(config, view, summary),
|
|
528
|
+
() => actions.usageFor('session'),
|
|
529
|
+
'session',
|
|
530
|
+
columns,
|
|
531
|
+
),
|
|
516
532
|
);
|
|
517
533
|
if (!r.early)
|
|
518
|
-
out.push(
|
|
519
|
-
|
|
534
|
+
out.push(
|
|
535
|
+
...(split
|
|
536
|
+
? billingLedger(ui, split)
|
|
537
|
+
: ledger(ui, config, view, { period: 'session', r, summary, legacy: null, columns, compact: true })),
|
|
538
|
+
);
|
|
539
|
+
if (!r.early && !split && switchesLost(r)) out.push(lostLine(ui, actions));
|
|
520
540
|
}
|
|
521
541
|
if (strip) {
|
|
522
542
|
out.push(
|
|
@@ -579,12 +599,12 @@ function lastSwitchLine(ui, last, now) {
|
|
|
579
599
|
|
|
580
600
|
// Routing against your model in the band's words, "routing −$1.84 (−22%) vs Opus 5.5 · xhigh", with the Usage tab on
|
|
581
601
|
// the same period one press away; an early sample says so.
|
|
582
|
-
function answerLine(ui, r, against, open, period, columns) {
|
|
602
|
+
function answerLine(ui, r, split, against, open, period, columns) {
|
|
583
603
|
const early = ' · early sample';
|
|
584
|
-
const width = 2 +
|
|
604
|
+
const width = 2 + answerText(r, split).length + ` vs ${against}`.length + early.length + USAGE_LINK;
|
|
585
605
|
return ui.line(
|
|
586
606
|
' ',
|
|
587
|
-
...answerParts(ui, r, against),
|
|
607
|
+
...answerParts(ui, r, split, against),
|
|
588
608
|
r.early && (!Number.isFinite(columns) || width <= columns) ? ui.dim(early) : null,
|
|
589
609
|
' ',
|
|
590
610
|
ui.Button({ key: `usage-${period}`, label: 'Usage', onPress: open }),
|
|
@@ -600,8 +620,9 @@ const lostLine = (ui, actions) =>
|
|
|
600
620
|
);
|
|
601
621
|
|
|
602
622
|
// Today across sessions, shown once another session added to it.
|
|
603
|
-
function todayLines(ui, summary, actions, columns) {
|
|
623
|
+
function todayLines(ui, config, summary, actions, columns) {
|
|
604
624
|
const switches = summary.switches.tier + summary.switches.activity;
|
|
625
|
+
const split = billingSplit(config, summary);
|
|
605
626
|
return [
|
|
606
627
|
ui.line(
|
|
607
628
|
ui.head('TODAY'),
|
|
@@ -611,17 +632,32 @@ function todayLines(ui, summary, actions, columns) {
|
|
|
611
632
|
),
|
|
612
633
|
summary.observed.uncomparedReplies
|
|
613
634
|
? ui.line(
|
|
614
|
-
ui.text(observedUsageText(summary.observed)),
|
|
635
|
+
ui.text(observedUsageText(summary.observed, split)),
|
|
615
636
|
' ',
|
|
616
637
|
ui.Button({ key: 'usage-today', label: 'Usage', onPress: () => actions.usageFor('today') }),
|
|
617
638
|
)
|
|
618
|
-
: answerLine(
|
|
639
|
+
: answerLine(
|
|
640
|
+
ui,
|
|
641
|
+
readout(summary),
|
|
642
|
+
split,
|
|
643
|
+
'each session’s own model',
|
|
644
|
+
() => actions.usageFor('today'),
|
|
645
|
+
'today',
|
|
646
|
+
columns,
|
|
647
|
+
),
|
|
619
648
|
];
|
|
620
649
|
}
|
|
621
650
|
|
|
651
|
+
// The findings that hold within one billing: with plan and credits apart, a part against your model would subtract
|
|
652
|
+
// quota from cash, so only the share of the cost stays.
|
|
653
|
+
const billingInsights = (summary, split) => insights(summary).filter((insight) => !split || insight.kind === 'cost');
|
|
654
|
+
|
|
622
655
|
// Today's first finding from Usage's WORTH A LOOK, with the tab that changes it; nothing when there is none.
|
|
623
|
-
function worthLines(ui, summary, actions, columns) {
|
|
624
|
-
const [first] =
|
|
656
|
+
function worthLines(ui, config, summary, actions, columns) {
|
|
657
|
+
const [first] =
|
|
658
|
+
!summary.observed.uncomparedReplies && summary.replies >= INSIGHT_REPLIES
|
|
659
|
+
? billingInsights(summary, billingSplit(config, summary))
|
|
660
|
+
: [];
|
|
625
661
|
if (!first) return [];
|
|
626
662
|
return [ui.text(' '), ui.line(ui.head('WORTH A LOOK'), ui.dim(' · today')), insightLine(ui, first, actions, columns)];
|
|
627
663
|
}
|
|
@@ -1725,10 +1761,10 @@ function scopeLine(ui, config, view, period, summary, now) {
|
|
|
1725
1761
|
}
|
|
1726
1762
|
|
|
1727
1763
|
// The answer first, in the band's words: "routing −$1.84 (−22%) vs Opus 5.5 · xhigh", or why there is nothing to compare.
|
|
1728
|
-
function headline(ui, config, view, period, r, summary, observed
|
|
1764
|
+
function headline(ui, config, view, period, r, summary, observed, split) {
|
|
1729
1765
|
if (observed.uncomparedReplies)
|
|
1730
1766
|
return [
|
|
1731
|
-
ui.text(observedUsageText(observed), { bold: true }),
|
|
1767
|
+
ui.text(observedUsageText(observed, split), { bold: true }),
|
|
1732
1768
|
ui.dim(
|
|
1733
1769
|
`${observed.uncomparedReplies} of ${observed.replies} replies have no comparison; savings are not estimated for them.`,
|
|
1734
1770
|
),
|
|
@@ -1739,6 +1775,7 @@ function headline(ui, config, view, period, r, summary, observed = summary.obser
|
|
|
1739
1775
|
...answerParts(
|
|
1740
1776
|
ui,
|
|
1741
1777
|
r,
|
|
1778
|
+
split,
|
|
1742
1779
|
period === 'session' ? comparedModel(config, view, summary) : 'each session’s own model',
|
|
1743
1780
|
),
|
|
1744
1781
|
),
|
|
@@ -1761,7 +1798,7 @@ function headline(ui, config, view, period, r, summary, observed = summary.obser
|
|
|
1761
1798
|
const against = period === 'session' ? comparedModel(config, view, summary) : 'each session’s own model';
|
|
1762
1799
|
return [
|
|
1763
1800
|
ui.line(
|
|
1764
|
-
...answerParts(ui, r, against),
|
|
1801
|
+
...answerParts(ui, r, split, against),
|
|
1765
1802
|
r.early ? ui.text(` early sample · ${plural(r.replies, 'reply', 'replies')}`, { color: 'yellow' }) : null,
|
|
1766
1803
|
),
|
|
1767
1804
|
];
|
|
@@ -1769,10 +1806,39 @@ function headline(ui, config, view, period, r, summary, observed = summary.obser
|
|
|
1769
1806
|
|
|
1770
1807
|
const capital = (words) => words[0].toUpperCase() + words.slice(1);
|
|
1771
1808
|
|
|
1772
|
-
// "routing −$1.84 (−22%) vs Opus 5.5 · xhigh", the answer bold in the savings color, as the band says it
|
|
1773
|
-
|
|
1774
|
-
|
|
1809
|
+
// "routing −$1.84 (−22%) vs Opus 5.5 · xhigh", the answer bold in the savings color, as the band says it; per billing
|
|
1810
|
+
// each difference in its own color. A split without one billing for your models compares with nothing.
|
|
1811
|
+
function answerParts(ui, r, split, against) {
|
|
1812
|
+
return [
|
|
1813
|
+
...answerSegments(r, split).map(({ text, value }) =>
|
|
1814
|
+
ui.text(text, { bold: true, ...(savingsColor(value) ? { color: savingsColor(value) } : {}) }),
|
|
1815
|
+
),
|
|
1816
|
+
split && !splitCompared(split) ? null : ` vs ${against}`,
|
|
1817
|
+
].filter(Boolean);
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
// Per billing, what the replies cost, what your model would have, and the difference: plan dollars stand for quota
|
|
1821
|
+
// and credits are paid, so neither is added to the other. `note` says so under the table.
|
|
1822
|
+
function billingLedger(ui, split, note = false) {
|
|
1823
|
+
const amount = (value) => (value === null ? '—' : usd(value)).padStart(BILLING_AMOUNT);
|
|
1824
|
+
return [
|
|
1825
|
+
ui.dim(
|
|
1826
|
+
` ${''.padEnd(LEDGER_LABEL)}${'routed'.padStart(LEDGER_AMOUNT)}${'your model'.padStart(BILLING_AMOUNT)}${'difference'.padStart(BILLING_AMOUNT)}`,
|
|
1827
|
+
),
|
|
1828
|
+
...BILLINGS.map((billing) => {
|
|
1829
|
+
const side = split[billing];
|
|
1830
|
+
return ui.line(
|
|
1831
|
+
' ',
|
|
1832
|
+
ui.cell(LEDGER_LABEL, ui.text(capital(billing))),
|
|
1833
|
+
usd(side.routedUsd).padStart(LEDGER_AMOUNT),
|
|
1834
|
+
amount(side.yoursUsd),
|
|
1835
|
+
side.yoursUsd === null ? amount(null) : differenceText(ui, billingDifference(side), BILLING_AMOUNT),
|
|
1836
|
+
);
|
|
1837
|
+
}),
|
|
1838
|
+
...(note ? [ui.dim(' at list prices; plan dollars stand for quota, credits are paid')] : []),
|
|
1839
|
+
];
|
|
1775
1840
|
}
|
|
1841
|
+
const BILLING_AMOUNT = 13;
|
|
1776
1842
|
|
|
1777
1843
|
// Your model − cheaper models + stronger models + switch cache writes = routed, in whole cents that add up (readout).
|
|
1778
1844
|
function ledger(ui, config, view, { period, r, summary, legacy, columns, compact = false }) {
|
|
@@ -1860,8 +1926,10 @@ const statsLine = (ui, s) =>
|
|
|
1860
1926
|
);
|
|
1861
1927
|
|
|
1862
1928
|
// The period's cost by activity, model or tier, most first; `g` presses the next grouping. A row opens to what it
|
|
1863
|
-
// holds and its cost parts. A narrow pane drops "mostly on" (or the share) before any number.
|
|
1864
|
-
|
|
1929
|
+
// holds and its cost parts. A narrow pane drops "mostly on" (or the share) before any number. With a billing split, a
|
|
1930
|
+
// row whose models are not all billed as your model is names its billing in place of `vs yours` and its parts: that
|
|
1931
|
+
// difference would subtract quota from cash.
|
|
1932
|
+
function breakdownLines(ui, config, view, actions, summary, columns, split) {
|
|
1865
1933
|
const by = GROUPS.some(([id]) => id === view.usageGroup) ? view.usageGroup : 'activity';
|
|
1866
1934
|
const next = GROUPS[(GROUPS.findIndex(([id]) => id === by) + 1) % GROUPS.length][0];
|
|
1867
1935
|
const out = [
|
|
@@ -1891,14 +1959,24 @@ function breakdownLines(ui, view, actions, summary, columns) {
|
|
|
1891
1959
|
` ${''.padEnd(NAME)}${'replies'.padStart(8)}${'cost'.padStart(10)}${'vs yours'.padStart(11)}${tail ? ` ${tailHead}` : ''}`,
|
|
1892
1960
|
),
|
|
1893
1961
|
);
|
|
1894
|
-
const
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1962
|
+
const otherBilling = (rowCells) => {
|
|
1963
|
+
if (!split) return null;
|
|
1964
|
+
const billings = new Set(breakdown(rowCells, 'model').map(({ name }) => billingOf(config, name)));
|
|
1965
|
+
if (billings.size === 1 && billings.has(split.yours)) return null;
|
|
1966
|
+
return billings.size === 1 ? [...billings][0] : 'both';
|
|
1967
|
+
};
|
|
1968
|
+
const numbers = (sums, unavailable, rowCells) => {
|
|
1969
|
+
const other = unavailable ? null : otherBilling(rowCells);
|
|
1970
|
+
return [
|
|
1971
|
+
`${String(sums[0]).padStart(8)}${usd(sums[1]).padStart(10)}`,
|
|
1972
|
+
unavailable || other ? ui.dim((other ?? '—').padStart(11)) : differenceText(ui, sums[1] - sums[2], 11),
|
|
1973
|
+
];
|
|
1974
|
+
};
|
|
1898
1975
|
for (const group of groups) {
|
|
1899
1976
|
const id = `${by}:${group.name}`;
|
|
1900
1977
|
const open = view.usageOpen === id;
|
|
1901
|
-
const
|
|
1978
|
+
const groupCells = cellsWhere(cells, by, group.name);
|
|
1979
|
+
const route = by === 'model' ? null : mostlyOn(groupCells);
|
|
1902
1980
|
out.push(
|
|
1903
1981
|
ui.line(
|
|
1904
1982
|
' ',
|
|
@@ -1910,7 +1988,7 @@ function breakdownLines(ui, view, actions, summary, columns) {
|
|
|
1910
1988
|
}),
|
|
1911
1989
|
' ',
|
|
1912
1990
|
ui.cell(NAME, groupName(ui, by, group.name)),
|
|
1913
|
-
...numbers(group.sums, missing.has(group.name)),
|
|
1991
|
+
...numbers(group.sums, missing.has(group.name), groupCells),
|
|
1914
1992
|
!tail
|
|
1915
1993
|
? null
|
|
1916
1994
|
: by === 'model'
|
|
@@ -1929,16 +2007,20 @@ function breakdownLines(ui, view, actions, summary, columns) {
|
|
|
1929
2007
|
...numbers(
|
|
1930
2008
|
child.sums,
|
|
1931
2009
|
missing.get(group.name)?.children.some((c) => c.name === child.name),
|
|
2010
|
+
cellsWhere(groupCells, CHILD_BY[by], child.name),
|
|
1932
2011
|
),
|
|
1933
2012
|
),
|
|
1934
2013
|
);
|
|
1935
2014
|
const [, , , cheaper, stronger, switched, input, , output] = group.sums;
|
|
2015
|
+
const tokens = `input ${formatTokens(input)} · output ${formatTokens(output)}`;
|
|
1936
2016
|
out.push(
|
|
1937
2017
|
...dimLines(
|
|
1938
2018
|
ui,
|
|
1939
2019
|
missing.has(group.name)
|
|
1940
|
-
? ` comparison unavailable ·
|
|
1941
|
-
:
|
|
2020
|
+
? ` comparison unavailable · ${tokens}`
|
|
2021
|
+
: otherBilling(groupCells)
|
|
2022
|
+
? ` ${tokens}`
|
|
2023
|
+
: ` cheaper ${signedUsd(cents(cheaper))} · stronger ${signedUsd(cents(stronger))} · switch ${signedUsd(cents(switched))} · ${tokens}`,
|
|
1942
2024
|
columns,
|
|
1943
2025
|
),
|
|
1944
2026
|
);
|
|
@@ -1947,8 +2029,9 @@ function breakdownLines(ui, view, actions, summary, columns) {
|
|
|
1947
2029
|
}
|
|
1948
2030
|
|
|
1949
2031
|
// What the period's tokens would cost on each model alone, as your model for every reply (compareModels), beside what
|
|
1950
|
-
// routing spent and your own models; a model some reply had no price on is left out.
|
|
1951
|
-
|
|
2032
|
+
// routing spent and your own models; a model some reply had no price on is left out. With a billing split, a model
|
|
2033
|
+
// billed otherwise than your model names its billing in place of the difference.
|
|
2034
|
+
function compareLines(ui, config, summary, split) {
|
|
1952
2035
|
if (summary.observed.uncomparedReplies)
|
|
1953
2036
|
return [ui.dim('What if unavailable: some replies have no comparable cache history.')];
|
|
1954
2037
|
const yours = Object.keys(summary.yours);
|
|
@@ -1960,6 +2043,7 @@ function compareLines(ui, summary) {
|
|
|
1960
2043
|
value,
|
|
1961
2044
|
routed: false,
|
|
1962
2045
|
yours: model === single,
|
|
2046
|
+
other: split && billingOf(config, model) !== split.yours ? billingOf(config, model) : null,
|
|
1963
2047
|
}));
|
|
1964
2048
|
if (!rows.some((row) => row.yours))
|
|
1965
2049
|
rows.push({
|
|
@@ -1967,8 +2051,9 @@ function compareLines(ui, summary) {
|
|
|
1967
2051
|
value: summary.yoursUsd,
|
|
1968
2052
|
routed: false,
|
|
1969
2053
|
yours: true,
|
|
2054
|
+
other: null,
|
|
1970
2055
|
});
|
|
1971
|
-
rows.push({ label: 'Routed', value: summary.routedUsd, routed: true, yours: false });
|
|
2056
|
+
rows.push({ label: 'Routed', value: summary.routedUsd, routed: true, yours: false, other: null });
|
|
1972
2057
|
rows.sort((a, b) => a.value - b.value);
|
|
1973
2058
|
const max = Math.max(...rows.map((row) => row.value));
|
|
1974
2059
|
return [
|
|
@@ -1980,10 +2065,15 @@ function compareLines(ui, summary) {
|
|
|
1980
2065
|
ui.text('█'.repeat(filled), { color: row.routed ? 'cyan' : 'gray' }),
|
|
1981
2066
|
' '.repeat(BAR - filled),
|
|
1982
2067
|
usd(row.value).padStart(LEDGER_AMOUNT),
|
|
1983
|
-
row.routed
|
|
2068
|
+
row.routed
|
|
2069
|
+
? ''
|
|
2070
|
+
: row.yours || row.other
|
|
2071
|
+
? ui.dim((row.other ?? '—').padStart(11))
|
|
2072
|
+
: differenceText(ui, row.value - summary.yoursUsd, 11),
|
|
1984
2073
|
);
|
|
1985
2074
|
}),
|
|
1986
2075
|
ui.dim(' same tokens and output on each model alone · answer quality not measured'),
|
|
2076
|
+
...(split ? [ui.dim(' Routed adds plan and credits at list prices; plan dollars stand for quota')] : []),
|
|
1987
2077
|
];
|
|
1988
2078
|
}
|
|
1989
2079
|
|
|
@@ -2011,9 +2101,9 @@ function trendLines(ui, view, actions, summary, period, now) {
|
|
|
2011
2101
|
|
|
2012
2102
|
// The evidence worth a look, each with the tab that changes it: the cell that carried most of the cost, the switch
|
|
2013
2103
|
// writes against the saving, the cell that ran above your model. Never which model to use.
|
|
2014
|
-
function insightLines(ui, summary, actions, columns) {
|
|
2104
|
+
function insightLines(ui, summary, actions, columns, split) {
|
|
2015
2105
|
if (summary.observed.uncomparedReplies || summary.replies < INSIGHT_REPLIES) return [];
|
|
2016
|
-
const list =
|
|
2106
|
+
const list = billingInsights(summary, split);
|
|
2017
2107
|
if (!list.length) return [];
|
|
2018
2108
|
return [
|
|
2019
2109
|
ui.text(' '),
|
|
@@ -2085,14 +2175,21 @@ function usageTab(ui, config, view, _usage, actions, _modelOptions, columns, now
|
|
|
2085
2175
|
const kept = period === 'all' ? allTime(record, view.savingsStore) : null;
|
|
2086
2176
|
const legacy = kept?.legacy ?? null;
|
|
2087
2177
|
const r = readout(kept?.totals ?? summary);
|
|
2178
|
+
const split = billingSplit(config, summary);
|
|
2179
|
+
const answerSplit = kept ? keptSplit(config, kept) : split;
|
|
2088
2180
|
const out = [periodRow(ui, period, actions), scopeLine(ui, config, view, period, summary, now), ui.text(' ')];
|
|
2089
|
-
out.push(...headline(ui, config, view, period, r, summary, kept?.observed ?? summary.observed));
|
|
2181
|
+
out.push(...headline(ui, config, view, period, r, summary, kept?.observed ?? summary.observed, answerSplit));
|
|
2090
2182
|
if (r.replies) {
|
|
2091
|
-
out.push(
|
|
2183
|
+
out.push(
|
|
2184
|
+
ui.text(' '),
|
|
2185
|
+
...(answerSplit
|
|
2186
|
+
? billingLedger(ui, answerSplit, true)
|
|
2187
|
+
: ledger(ui, config, view, { period, r, summary, legacy, columns })),
|
|
2188
|
+
);
|
|
2092
2189
|
}
|
|
2093
2190
|
if (summary.observed.replies) out.push(ui.text(' '), statsLine(ui, { ...summary.observed, turns: summary.turns }));
|
|
2094
2191
|
if (summary.observed.replies) {
|
|
2095
|
-
out.push(ui.text(' '), ...breakdownLines(ui, view, actions, summary, columns), ui.text(' '));
|
|
2192
|
+
out.push(ui.text(' '), ...breakdownLines(ui, config, view, actions, summary, columns, split), ui.text(' '));
|
|
2096
2193
|
out.push(
|
|
2097
2194
|
...(view.usageCompare
|
|
2098
2195
|
? [
|
|
@@ -2101,10 +2198,10 @@ function usageTab(ui, config, view, _usage, actions, _modelOptions, columns, now
|
|
|
2101
2198
|
ui.dim(' · the same tokens on one model '),
|
|
2102
2199
|
ui.Button({ key: 'usage-compare', label: 'Trend', hotkey: 'c', onPress: actions.usageCompare }),
|
|
2103
2200
|
),
|
|
2104
|
-
...compareLines(ui, summary),
|
|
2201
|
+
...compareLines(ui, config, summary, split),
|
|
2105
2202
|
]
|
|
2106
2203
|
: trendLines(ui, view, actions, summary, period, now)),
|
|
2107
|
-
...insightLines(ui, summary, actions, columns),
|
|
2204
|
+
...insightLines(ui, summary, actions, columns, split),
|
|
2108
2205
|
);
|
|
2109
2206
|
}
|
|
2110
2207
|
out.push(
|
package/lib/usage.mjs
CHANGED
|
@@ -355,7 +355,7 @@ export function summarize(record, { from, to }) {
|
|
|
355
355
|
const READOUT_SUMS = ['replies', 'routedUsd', 'yoursUsd', 'cheaperUsd', 'strongerUsd', 'switchUsd'];
|
|
356
356
|
|
|
357
357
|
// Every routed reply kept: the usage records' days and the undated savings totals from before them, as `readout`
|
|
358
|
-
// takes them, and since when (ms; null without any).
|
|
358
|
+
// takes them, and since when (ms; null without any); `summary` is the dated days alone.
|
|
359
359
|
export function allTime(usageStore, savingsStore) {
|
|
360
360
|
const record = readUsage(usageStore);
|
|
361
361
|
const summary = summarize(record, { from: null, to: null });
|
|
@@ -369,6 +369,7 @@ export function allTime(usageStore, savingsStore) {
|
|
|
369
369
|
routedUsd: summary.observed.routedUsd + legacy.routedUsd,
|
|
370
370
|
},
|
|
371
371
|
legacy,
|
|
372
|
+
summary,
|
|
372
373
|
};
|
|
373
374
|
}
|
|
374
375
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexeiled/claude-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.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",
|