Skip to content

feat(models): carry the billing route on the call; key every model row on it - #1448

Merged
iamtoruk merged 3 commits into
getagentseal:mainfrom
ulises-c:feat/model-route-bedrock
Sep 17, 2026
Merged

iamtoruk merged 3 commits into
getagentseal:mainfrom
ulises-c:feat/model-route-bedrock

Conversation

@ulises-c

@ulises-c ulises-c commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1449, closes #1450. Reworked in place after the reviews below: the route is a field on the call first, rendered second, with one row key across every surface. Series: this → #1451 (--route filters, payload fields, "By billing" grouping, and the per-call metered / subscription split).

  • The billing route rides on the call. ParsedProviderCall.route, threaded through ParsedApiCall and CachedCall. Two sources feed it: the model id when the door renames the model (getModelRoute — Bedrock's <vendor>.<model>[-vN:M] with an optional us./eu./global. profile prefix, vendors anthropic and openai only, the shapes on disk and nothing wider), and the provider's own column when it does not (routeFromProviderField — Hermes billing_provider). Direct doors map to no route: the unsuffixed row is the direct row.
  • One row key, everywhere. modelRowKey(model, route) = short name + door label. The cross-region profile is a dearer SKU and keeps its own row, (Bedrock us) (fix(models): resolve and merge raw ids in models report #1053). Idempotent, so a display-keyed daily row re-keys to itself. Called from every site that used to key or label rows its own way — parser.ts modelBreakdown, day-aggregator (day and provider-slice models), usage-aggregator, menubar-json, model-breakdown, models-report, session-output, model-efficiency, overview, sessions-report, telemetry-snapshot, compare-cohorts, compare-stats, live-sessions. getShortModelName is untouched.
  • models-report folds on the row key, not the route id. The fold identity is the alias-resolved id plus the row key's own door suffix (modelFoldKey). Two route ids that render one label — one door with two endpoint names — therefore land on one row instead of two rows the reader cannot tell apart, which is what the second review caught.
  • Daily cache v33. day.models is keyed by the row key, so a column-sourced route survives into the finalized day (the raw id alone cannot carry it). hermes joins PENDING_REDERIVE_PROVIDER_VERSIONS at 33; ladder entry added. Parse version billing-route-v1 re-parses cached Hermes sessions once.
  • Pricing never consults the route: getModelCosts runs on the raw id.

Registered routes: bedrock only. openrouter and bedrock-mantle are real Hermes billing_provider values, but nobody has sessions for them yet, so they are held back under the same rule the id shapes were cut by last round. They map to no route today, exactly like an unknown door.

One surface deliberately disagrees. granular-history.ts still keys its buckets on the raw model id, so the desktop Trend timeline is the only place where a Bedrock id and its direct sibling are not named the way every other surface names them. Left as is; noted here so it is a known gap and not a surprise.

Why this shape

On the first review: the first cut put the route in a display string that three surfaces keyed differently (models-report on resolveCanonicalModelId, the rest on getShortModelName) and shipped two same-label rows next to one blended row. This PR makes the route a field first and gives every surface one key function. On the second review: folding on the route id reintroduced the twin-row defect in a narrower form, so the fold now carries the row key's suffix and never the id.

Testing

  • Tested locally against real data (not just unit tests)
  • npm test — 4203 passed / 5 skipped; npm run test:locks (36); npx tsc --noEmit clean; npm run build
  • Merged current main; no conflicts left

The test the first cut lacked. tests/cli-route-surfaces.test.ts runs the real CLI (tsx src/cli.ts) over the three Claude sessions the review seeded — direct, anthropic.…-v1:0, us.anthropic.…-v1:0 — and asserts models --format json, status --format menubar-json (current.topModels and history.daily[].topModels) and the on-disk daily-cache.v33.json carry the same three rows: Haiku 4.5, Haiku 4.5 (Bedrock), Haiku 4.5 (Bedrock us), at the prices main showed for the raw ids (bare Bedrock = direct; us. profile above both).

The fold. tests/model-routes.test.ts pins modelFoldKey to the row key: the key carries (Bedrock) and never the route id, so a second door added under an existing label folds instead of twinning. tests/day-aggregator.test.ts asserts a column-routed call and an id-shaped one of the same SKU land on one row in the finalized day, with the cross-region profile still apart.

Real data. On a copy of a real 496 MB cache, report --period lifetime --format json and models --format json on main and on this branch: all 142 finalized days match, $37,898.851498 and 272,985 calls on both sides; 38 lifetime model rows, identical names and costs. Only today moves, in both directions between two consecutive main runs — live sessions appending. No Bedrock or column-sourced route exists in that cache, so no row folded or changed name there. The menubar history rows that the v33 bump re-derives (stale v32 days written before the Grok Bot provider landed) were checked against main with only DAILY_CACHE_VERSION bumped and none of this code: identical, 0 day mismatches.

Not proven with real data: any route other than Bedrock, which is why only bedrock is registered.

Affiliation: none. I run Bedrock through an employer AWS account alongside Claude Max and ChatGPT plans and wanted the metered share.

@iamtoruk iamtoruk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Direction is fine, mechanism is not yet.

Seeded three Claude sessions on one machine: direct, anthropic.claude-haiku-4-5-20251001-v1:0, and us.anthropic.claude-haiku-4-5-20251001-v1:0. codeburn models prints two rows both called Haiku 4.5 (Bedrock), $1.65 and $1.50, with nothing to tell them apart. status --format menubar-json prints one row at $3.15. Before this PR both surfaces showed three distinct rows. So "every Bedrock spelling folds to one row" and "desktop and codeburn models agree without further work" are not true: models-report keys on resolveCanonicalModelId, everything else keys on getShortModelName.

The merged row is also the thing you cite #1053 against. us. prices 10% above the bare id. Blending them under one label is two SKUs in one row.

The id shapes you can show on disk are <vendor>.<model> and -v1:0. #1449 says Claude Code drops the profile prefix. So drop the ARN regex, the bedrock/ prefix, the :300k tag, and cut the vendor table to what you have sessions for. Stability and TwelveLabs do not write coding transcripts.

The looksLikeLocalModel fix is right and is the only bug in here. It does not need the route machinery; -v\d+:\d+$ is a version, not a tag. Happy to take that on its own today as a separate small PR.

On the rest: a display suffix puts billing into a string that three surfaces key differently. Put the route on the call as a field first, then render it. That is #1450. Land that shape, and this becomes small.

One correction for later: the daily cache stores the display key, not raw ids. No bump is needed here only because getShortModelName is idempotent and the old key happened to be the raw id. Do not carry that assumption into #1450.

Checked: 46 adversarial ids incl. Vertex, Azure, OpenRouter and Ollama tags, zero misclassified; direct ids unchanged; pricing still on the full id; OTLP wire untouched; tsc clean; 4,126 tests pass.

@ulises-c

Copy link
Copy Markdown
Contributor Author

Reproduced with three seeded Claude sessions (direct, anthropic.…-v1:0, us.anthropic.…-v1:0): two identical Haiku 4.5 (Bedrock) rows in models, one blended $3.15 row in the menubar payload, three distinct rows on main. models-report keys on resolveCanonicalModelId, everything else on getShortModelName, and I only changed the latter — so the #1053 point stands against this PR. I tested each surface's output but never the same ids side by side across surfaces; that is on me.

Taking your split:

Thanks for the adversarial-id pass.

@ulises-c
ulises-c marked this pull request as draft September 16, 2026 22:26
…w on it

The same model billed through a different door is a different invoice, and
the door decides whether the spend is metered. Claude Code and Codex on
fixed-fee plans plus API usage on top (Bedrock, OpenRouter) is one machine's
month; "how much of it was metered?" had no answer because every surface
keyed model rows on the display name alone, and the surfaces did not even
agree on that key: models-report folded on resolveCanonicalModelId, the
rest on getShortModelName. getagentseal#1448's first cut changed one of them and shipped
two same-label rows in `models` next to one blended row in the menubar.

Route as a field, one row key:

- `ParsedProviderCall.route` / `.billing`, threaded through ParsedApiCall and
  CachedCall (validator, four spread sites). Two sources feed it: the model id
  when the door renames the model (`getModelRoute`: Bedrock
  `<vendor>.<model>[-vN:M]`, optional `us.`/`eu.`/`global.` profile prefix,
  vendors anthropic/openai — the shapes on disk, nothing wider), and the
  provider's own column when it does not (`routeFromProviderField`: Hermes
  `billing_provider` bedrock / bedrock-mantle / openrouter, incl. path and
  colon spellings). Direct doors map to no route: the unsuffixed row is the
  direct row.
- `modelRowKey(model, route)`: short name plus the door label. A cross-region
  profile is a dearer SKU and keeps its own row, "(Bedrock us)" (getagentseal#1053).
  Idempotent, so a display-keyed daily row re-keys to itself. Called from
  parser.ts modelBreakdown, day-aggregator (day and slice models),
  usage-aggregator, menubar-json, model-breakdown, models-report (fold on
  canonical id + route; `route` on the row and in JSON), session-output,
  model-efficiency, overview, sessions-report, telemetry-snapshot,
  compare-cohorts, compare-stats, live-sessions.
- Hermes forwards billing_provider -> route and cost_status -> billing:
  `included` is subscription, `actual` or a metered door is metered, an
  `unknown` direct session asserts neither (Claude Max and an API key look
  the same to Hermes). Parse version `billing-route-v1` re-parses once.
- DAILY_CACHE_VERSION 32 -> 33: day.models keyed by the row key, so a
  column-sourced route survives into the finalized day; hermes joins the
  pending-rederive table at 33.

Pricing is untouched: getModelCosts runs on the raw id. getShortModelName is
untouched.

Tests: model-routes (id shape, column, key, idempotence, no dollar moves);
hermes route/billing per billing_provider x cost_status; day-aggregator v33
keys incl. a column-sourced route; cli-route-surfaces runs the real CLI over
the three sessions the getagentseal#1448 review seeded and asserts models, menubar
current + history, and the daily cache carry the same three rows at the
prices main showed.

Closes getagentseal#1450
@ulises-c
ulises-c force-pushed the feat/model-route-bedrock branch from 4c5591a to d5d6a91 Compare September 16, 2026 23:33
@ulises-c ulises-c changed the title feat(models): keep a Bedrock-routed model in its own row feat(models): carry the billing route on the call; key every model row on it Sep 16, 2026
@ulises-c

Copy link
Copy Markdown
Contributor Author

Reworked in place per the review: the route is now a field on the call (route / billing), fed by the id shape or the provider's own column (Hermes billing_provider), and every surface keys model rows on one modelRowKey. The branch is a single new commit on current main (d5d6a91); the display-suffix commit is gone. Body rewritten to match. The cross-surface test that was missing is tests/cli-route-surfaces.test.ts: your three seeded sessions, asserted identical in models, the menubar payload and the daily cache, at the prices main showed. Daily cache v33 with hermes in the pending-rederive table, per your correction on the display key.

@iamtoruk iamtoruk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numbers check out. On a copy of my real cache, all 142 finalized days match main to the twelfth decimal, 272,985 calls both sides, $37,898.85 both sides. Only today moves, and it moves in both directions between two main runs, so that is drift. Cold rederive costs 3.3 s once.

One thing to know: preserved-from-expired-logs goes from $23,554.65 to $24,839.95. Two days, 15 and 16 Aug, flip to carried, same cost and calls on both sides. I bumped DAILY_CACHE_VERSION to 33 on main with none of your code and got the identical $24,839.95, so it is the version bump, not you. Nothing lost.

The three seeded sessions now agree on models, the menubar payload, the daily cache, overview, sessions, telemetry, live sessions and compare, at the prices main showed. That is what I asked for.

One defect left, and it is the one I rejected the first time in a narrower form. bedrock and bedrock-mantle are two route ids with one label. models-report folds on the route id, everything else keys on the label. A Hermes user with both doors for one model gets two rows in models both called GPT-5.6 Sol (Bedrock) with nothing to tell them apart, and one merged row in the menubar. Reproduced through aggregateModels. Fold on the row key, not the route id.

Two cuts while you are in there. billing has no readers at all, so hold it for #1451 with the rest. Drop openrouter and bedrock-mantle until someone has sessions, the same way the id shapes went last time. Also granular-history still keys on the raw id, so the desktop timeline will be the only surface disagreeing; fine to leave, but say so in the body.

Rest is verified: 4,163 tests, locks 36, tsc clean, merges clean.

# Conflicts:
#	CHANGELOG.md
#	src/providers/hermes.ts
@iamtoruk

Copy link
Copy Markdown
Member

Applied all four.

The fold in models-report now keys on the row key, not the route id: the identity is the alias-resolved id plus the row key's own door suffix, so two route ids that render one label land on one row. tests/model-routes.test.ts pins that the fold key carries (Bedrock) and never the route id, so the next door added under an existing label cannot reintroduce the twin rows.

billing is gone — the field on the call, the type, and the route's own billing property, none of which had a reader. It comes back with #1451. openrouter and bedrock-mantle are dropped until someone has sessions, along with the aws-bedrock / amazon-bedrock column spellings and the openrouter/ and openrouter: path forms, which existed only for them. bedrock is the one registered route. granular-history still keys on the raw id, so the desktop timeline stays the one surface that disagrees; that is now stated in the body.

Also cut an unrelated line in telemetry-snapshot that the rework had touched.

Real cache, 496 MB copy, main vs branch: all 142 finalized days match, $37,898.851498 and 272,985 calls on both sides, 38 lifetime model rows identical in name and cost. Only today moves, and it moves between two consecutive main runs too. No Bedrock or column-sourced route exists in that cache, so nothing folded or renamed there. The menubar history rows the v33 bump re-derives — stale v32 days written before Grok Bot landed — match main with only DAILY_CACHE_VERSION bumped and none of this code, 0 day mismatches.

4203 tests, locks 36, tsc clean, main merged.

@iamtoruk
iamtoruk marked this pull request as ready for review September 17, 2026 11:22
@iamtoruk
iamtoruk merged commit 724b9f3 into getagentseal:main Sep 17, 2026
20 checks passed
iamtoruk added a commit to ozymandiashh/codeburn that referenced this pull request Sep 17, 2026
Conflicts kept both sides: menubar buildTopModels merges on modelRowKey (getagentseal#1448)
while staying uncapped and carrying per-model counts; Overview.tsx keeps main's
chart bucketing next to the topModels-sourced model table; usage-aggregator
takes both import sets; snapshot render version renumbered to 9 over main's v8
(streak/periodTotals), with the changelog revisions updated to match.
@ulises-c
ulises-c deleted the feat/model-route-bedrock branch September 18, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants