Repository navigation
Description
The problem, in your words
The question behind this series (#1449): with Claude Code and Codex on fixed-fee subscriptions and API usage on top (Bedrock, OpenRouter), how much metered spend am I incurring this month? The route a call took is what decides that — Bedrock and OpenRouter are always metered; a Claude Max or ChatGPT session is covered by the flat fee — so the route has to be a first-class fact about the call, and it has to carry its billing mode.
#1448 makes the billing route visible for one endpoint, Bedrock, by recognising the id shape tools write for it (anthropic.claude-…-v1:0). That covers Bedrock because Bedrock renames the model. Most other billing endpoints do not: a call billed through OpenRouter is recorded as the plain vendor id (claude-sonnet-4-5, or anthropic/claude-sonnet-4.5), so no id-shape rule can tell it from a direct Anthropic call, and its spend merges into the direct row.
The route is on disk, just in a different column than the model:
| Tool | Where the endpoint is recorded | Example |
|---|---|---|
| Hermes | sessions.billing_provider (+ billing_base_url) in state.db |
openrouter, anthropic, bedrock, openai-codex, bedrock-mantle — all seen on one machine this week; src/providers/hermes.ts already SELECTs the column and drops it |
| OpenCode / ZCode | session model JSON { providerID, id }; sqlite-session-parser.ts:58 folds it into providerID/id and the known-namespace strip then discards it |
openrouter/anthropic/claude-sonnet-4-5 |
| Zerostack | OpenRouter-prefixed model ids (zerostack.ts:128) |
deepseek/deepseek-v4-pro |
| Mux | provider:model prefix, stripped at mux.ts:199 |
openrouter:… |
| Cline / Roo / Kilo | apiProvider in the task's API configuration (not read today) |
openrouter, bedrock, vertex, anthropic |
So today two things are lost: the OpenRouter route entirely, and any Bedrock/Vertex route on a tool that records the endpoint in a column rather than the id.
What you tried
- The feat(models): carry the billing route on the call; key every model row on it #1448 mechanism (
getModelRouteon the id) — cannot work for OpenRouter by construction; the id is the vendor's. codeburn model-alias— has no notion of a route; aliasing merges rows, the opposite of what is wanted.- Reading
billing_providerout ofstate.dbby hand.
Proposed change
Give the route a second source — the provider's own endpoint column — feeding the same ModelRoute that #1448 introduced, with OpenRouter as the first route that only that source can supply.
- Registry of routes, replacing the Bedrock-only branch in
getModelRoute:{ id, label, billing: 'metered' | 'subscription', detect?(modelId), fromProviderField?(value) }.bedrockkeeps its id-shape detector, trimmed to what is on disk —<vendor>.<model>with an optional-vN:Mversion, vendorsanthropicandopenai(the two with coding sessions); ARN /bedrock//:300kspellings and the wider vendor table from the first cut of feat(models): carry the billing route on the call; key every model row on it #1448 are dropped until a provider is shown to write them;openrouterhas none and is recognised from the provider field (openrouter,openrouter/…,openrouter:…, base URLopenrouter.ai). Both aremetered. Subscription doors get entries too —openai-codex(ChatGPT plan; Hermes writes it asbilling_provider),claude-max/anthropic-oauthwhere a harness can tell OAuth from an API key — assubscription. A provider that already records the mode per session (Hermescost_status = included, Copilot's rated/unrated credits) overrides the route's default. Display convention:Sonnet 4.5 (OpenRouter),Sonnet 4.5 (Bedrock),Sonnet 4.5for direct. - Carry the field.
ParsedProviderCall.route?: stringandbilling?: 'metered' | 'subscription'(resolved from the route's default unless the provider states it). Providers set it where they have it: Hermes frombilling_provider, OpenCode/ZCode fromproviderIDbefore the namespace strip, Mux from the colon prefix before it is dropped, Cline-family fromapiProvider. Where absent,getModelRoute(model)?.idfills it.parser.tskeysmodelBreakdownonroute ? "<name> (<label>)" : name, so the column-sourced route and the id-sourced route land in the same row shape. Persist onCachedCall(bumpCACHE_VERSION). The daily cache stores the display key, not raw ids (maintainer correction on feat(models): carry the billing route on the call; key every model row on it #1448):day.modelsis keyed by the stringgetShortModelNameproduced at aggregation time, and feat(models): carry the billing route on the call; key every model row on it #1448 needed no bump only because that function was idempotent on the old key. Once the row key becomes(name, route), finalized days must re-derive —DAILY_CACHE_VERSIONbumps, and the migration ladder at the top ofdaily-cache.tsgets its entry. Every surface must key rows the same way:parser.tsmodelBreakdown,usage-aggregatormergeDayModelsByDisplayName,menubar-jsonbuildTopModels,model-breakdownaggregateModelTotals, andmodels-report(which today keys onresolveCanonicalModelId— the mismatch that produced two same-label rows in feat(models): carry the billing route on the call; key every model row on it #1448). One key function, called from all of them. This is the store-at-parse / apply-at-read pattern Cost modes: reconcile displayed cost with the source's own reported cost (auto/calculate/display) #890 lays out for reported-vs-computed cost (both are provenance about a call the caches must carry, not recompute). - Pricing stays on the raw id. LiteLLM already carries
openrouter/…(103 rows),bedrock/…,vertex_ai/…(115),azure/…(187). A route never changes what a call costs; it changes which row the cost lands on.
Routes others can add after this lands, each a registry entry plus the provider field that names it (id-shape detector only where the endpoint renames the model):
| Route | Id shape? | Provider field | Notes |
|---|---|---|---|
openrouter |
no | Hermes billing_provider, OpenCode providerID, Cline apiProvider, Mux prefix |
this issue |
vertex |
yes: claude-…@20251001, vertex_ai/… |
Cline apiProvider = vertex |
@date is stripped today and merges with direct — docs/providers/claude.md |
azure / azure-ai |
yes: azure/…, azure_ai/… deployment names |
Cline apiProvider |
deployment names are user-chosen; alias support matters |
bedrock-mantle |
partly (bedrock-mantle.<region>.api.aws) |
Hermes billing_provider = bedrock-mantle |
Bedrock's OpenAI-compatible endpoint; seen on disk already |
openai-codex (ChatGPT subscription) vs openai (API) |
no | Hermes billing_provider (60 sessions on one machine, all cost_status = included), Codex auth mode |
the subscription side of the split; without it "metered" cannot be computed as a share |
claude-max / Anthropic OAuth vs API key |
no | Claude Code transcripts carry no auth marker; Hermes billing_provider = anthropic covers both |
the biggest gap for the subscription side — may need codeburn plan as the tie-break |
copilot, cline-pass, kimi-for-coding, … |
some (cp/, cline-pass/ prefixes already peeled in models.ts) |
provider-specific | today these peel to the bare model and lose the door |
ollama / local |
yes (:tag) |
— | already handled as "free"; would just gain a label |
Related: #1241's rawModels already exposes which raw ids fed a display row; once route exists, a row's routes can be listed the same way for consumers that want the merged view. #1420 (unpriced usage hidden) benefits too — a route-tagged unpriced row says which account is missing a price.
Not in scope: filtering/drill-through and the desktop / menubar / web surfaces that show the split — #1451. Pricing changes — none needed.
Depends on #1448 (ModelRoute, getModelRoute).
Activity
feat(models): keep a Bedrock-routed model in its own row
[-]Filter and drill into spend by billing route (Bedrock first, then OpenRouter via Hermes billing_provider)[/-][+]Add OpenRouter as a billing route: read the endpoint from the provider's own column, not the model id (and a list of routes to follow)[/+][-]Add OpenRouter as a billing route: read the endpoint from the provider's own column, not the model id (and a list of routes to follow)[/-][+]Add OpenRouter as a billing route and carry metered/subscription on each call: read the endpoint from the provider's own column, not the model id (with a list of routes to follow)[/+]ulises-c commentedon Sep 16, 2026
Plan before code (over the 300-line first-contributor threshold, per CONTRIBUTING). Findings from the checkout that revise the text above:
day-aggregator.ts:208writesday.models[call.model]— the raw id (confirmed in a livedaily-cache.v32.json:anthropic.claude-haiku-4-5-20251001-v1:0,openai.gpt-5.6-luna). The display-keyed shape isSessionSummary.modelBreakdown(parser.ts:1789), rolled up byusage-aggregator.ts:137,1026;mergeDayModelsByDisplayName(fix(models): group Trend rows and the models command by the same display name #1241) reconciles the two at read time. A route re-derivable from the raw id needs no daily bump; a route sourced from a provider column (Hermesbilling_provider) has no home inday.modelsand does — soDAILY_CACHE_VERSIONbumps for the case that matters, exactly as the feat(models): carry the billing route on the call; key every model row on it #1448 review warned.parser.ts:1789(+ the Devin raw-id exception repeated insession-output.ts:18,model-efficiency.ts:23),usage-aggregator.ts:323,1747,menubar-json.ts:505,model-breakdown.ts:26,models-report.ts:172,190(canonical id — the odd one),overview.ts:315,384,sessions-report.ts:926,audit-report.ts:119,telemetry-snapshot.ts:146,compare-cohorts.ts:309,399,live-sessions.ts:184. OnemodelRowKey(model, route?)inmodels.ts, called from all of them.nanoAiu:ParsedProviderCall→ParsedApiCall→CachedCall(validator atsession-cache.ts:749, four spread sites inparser.ts). Cached rows re-parse via aPROVIDER_PARSE_VERSIONSsuffix onhermes, not aCACHE_VERSIONbump — correcting item 2 above; shard layout is untouched.costBasis(hermes.ts:466-497:included/actual/estimated/calculated) and drops it;billing_provideris SELECTed and dropped. Both are one-line forwards. On one machine:openai-codex60 sessions allincluded;anthropic36 allunknown— Claude Max vs Anthropic API is not recoverable from Hermes data, so that split needscodeburn planas the tie-break, later.billing_provider = openrouter; the Bedrock route and thebedrock/openai-codex/anthropiccolumn values are what real data proves. Labelled as such in the PR.Slice I am implementing now:
models.ts: route registry (bedrockid-shape detector trimmed to<vendor>.<model>[-vN:M], vendorsanthropic/openai;openrouter,openai-codex,anthropic,bedrock-mantleas column-only entries, each with abillingdefault) andmodelRowKey.getShortModelNameunchanged.route?/billing?on the three call types, validator, spread sites,hermesparse-version suffix.hermes.ts:billing_provider→ route;costBasis === 'included'→billing: 'subscription'. Id shape fills the route where the column is absent (Claude Code).modelRowKey;day.modelskeyed on it too;DAILY_CACHE_VERSION32 → 33 with a ladder entry.models, menubar payload and overview (the test feat(models): carry the billing route on the call; key every model row on it #1448 lacked); Hermes fixture withbilling_providervalues; direct ids byte-identical.Out of this slice:
--route/--billingfilters, payload fields, GUI (#1451); Vertex / Azure.ulises-c commentedon Sep 16, 2026
Implementation: #1448, reworked in place after review. Real-data proof for Bedrock via Claude Code and Hermes; OpenRouter exercised by fixture only — no sessions on this machine.