Ideas discussion
https://github.com/Twigpine/zero/discussions/1119 (Ideas, opened 2026-10-05, no replies yet). I am filing this tracking issue so the proposal has a place to be reviewed. I will not open a PR before this issue is reviewed and marked issue-approved, as CONTRIBUTING.md asks.
Problem
With OpenAI-compatible routers and aliases (OpenRouter auto, LiteLLM aliases, local gateways), the model Zero requested is often not the model that served the request. The provider says which one did: the chat stream carries model, and Codex Responses carries response.model. Zero drops that value, so zero usage report and the session log can only say "requested auto", never which model actually answered or how usage split across models over time.
Requested behavior
- Decode the provider-reported model into
Usage.ResolvedModelwhen the stream provides it (OpenAI-compatible chunks and Codexresponse.model). When usage arrives across several chunks, the last non-empty value wins. - Persist it as an optional
resolvedModelkey onusageevents, through the existing single writerusage.EventUsagePayload. It is omitted when empty, so older readers and existing payloads are unaffected. - No change to pricing or to the existing
modelkey. Cost keeps coming from the session's configured model through the registry.resolvedModelis attribution, not billing.
Why it belongs in Zero
Zero already persists usage for local accounting. This makes that record truthful when a router is involved, at no cost when it is not. It is provider-agnostic: any router that echoes model benefits, and nothing is provider-specific.
Alternatives or workarounds considered
- Replacing
modelwith the resolved value would change pricing and break escalation attribution, so it is a separate key. - Logging it only in debug output would leave
zero usage reportunable to use it.
Examples, screenshots, or prior discussion
A working implementation exists on my fork, FabioLeitao/zero: commit 9bfb22f7 (merged into the fork's main through fork PR #5, branch feat/resolved-model-provider-usage). It touches 11 files, +129/-1, most of it tests: internal/providers/openai (codex_responses.go, provider.go, tool_state.go, types.go), internal/zeroruntime (types.go, helpers.go), internal/usage/report.go, plus tests.
Happy to adjust the key name, the merge rule, or the scope to whatever the maintainers prefer before anything is proposed as a PR.
Activity
2A note on scope, so it is recorded here and not only in the review of #1234.
"When usage arrives across several chunks, the last non-empty value wins" means this: each usage chunk is recorded with the last model the provider had reported by the time that chunk arrived, and when a response sends several usage chunks the latest one wins. That is what #1234 does.
It does not mean holding a usage event back in case the model id changes after the last usage chunk. I asked for that to be taken out of #1234, because it changed how usage is delivered for every provider to cover a case no provider is known to produce. If a provider turns up that reports a different model after its final usage chunk, that is a new issue, with a captured stream attached.
This reads well, and keeping it a separate attribution-only key, with
modeland pricing untouched, is the right split. Approving it, with one condition and two small asks for the PR:zero usage reportprints it to a terminal. Strip control and format characters and cap the length (a couple of hundred bytes is plenty for a model id) before it's stored. Please include a test with an escape sequence and an oversized value in the stream.resolvedModelmean "a router picked something else".response.modelas you describe is fine for the first PR. Other providers that report a model can follow later.Marking this approved.