Repository navigation
feat(agents): Claude Code, Gemini, OpenCode, Letta Code and the proxy give each turn's counts by model - #893
Merged
Conversation
… give each turn's counts by model Usage.models from what each already counts: Claude Code from the CLI's modelUsage tally (with the CLI's own cost per model), Gemini from its proxy's per-call records, OpenCode and Letta Code from the shared model relay, which now reads each request's model, and the proxy from the model each recorded call names. A call that named no model counts as the turn's configured one. Claude Code's and Gemini's per-model counts leave provider_details. The four agents' protocol floor is 0.1.640, the first with Usage.models; the sandboxed proxy takes it from the next release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reported one; tests take the new floor As the host's rule since #887: a sum of some calls' figures isn't the model's cost, so the host prices it from the map. The agents' image-contract tests and the proxy usage integration test take the 0.1.640 floor and the turn's rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
marked this pull request as ready for review
November 23, 2026 18:44
…cache flag is its counted calls' The proxy has no configured model to count an unnamed call under, and the last model the turn named isn't it. A call without usage no longer leaves its model's includes-cache flag unknown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h call keeps its model beside its usage The rule for a model's row (counts summed over the calls that gave them, the cost only when every call reported one, the flag the counted calls agree on) is the protocol's ModelUsage.of, which the proxy uses; the relay and Gemini take it once their floor is the release that has it. The relay's Calls and the proxy's turn keep (model, usage) pairs rather than two lists in step, and Gemini stops at the first unnamed call when no model is configured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
The second half of P16 (FD-6744): the agents fill
Usage.models(#887), so each model a turn used is priced at its own rate.modelUsagetally for the turn, with the CLI's own cost for that model. A Haiku subagent under a Sonnet solver is priced at Haiku's rate. The rows come only when the tally is used (it covers every call). On the fallback path, a resumed session this process hasn't run, the turn has no rows and is priced at the role's model, as before.Callskeeps it beside the call's usage, andCalls.usage(tool_calls, model)gives the rows. Both bridges pass their configured model.ModelUsage.of(model, usages)(protocol): one model's row from the usages of its calls. Each count is summed over the calls that gave it. The cost is set only when every call reported one, as the host requires since feat(protocol): Usage gives a turn's counts by model, and the host prices each model at its own rate #887. The includes-cache flag is the one the calls with input counts agree on.ModelUsage.of. The proxy has no configured model, so a turn with a call that named none gives no rows and is priced at the role's model. The in-process proxy, which an episode uses when the task runs no agent sandbox, has it now. The sandboxed proxy installs the protocol from PyPI, so it takes this from the next release, once its floor is raised.provider_details.models, which Claude Code and Gemini kept before, is gone; the typed rows replace it.Usage.models.Decisions (made with Edgar, 2026-11-23)
modelswhenever it knows each call's model, on every turn, with no condition. That also prices a whole turn a CLI ran on another model at that model's rate. The cost: these agents' entries always carry per-model rows, so they have no entry-levelunit_prices. The protocol README,Usage's docstring andagents/AGENTS.mdnow say so.ModelUsage.ofthere too, once their protocol floor is the release that has it. Hermes' main and aux calls come from a usage file that names no model, and Codex's subagents' models need each rollout'sturn_context.Tests
tst/unit/utils/model_relay_models_test.py: the relay's rows by the model each request named, an unnamed call counted as the configured model's, no rows when neither is known, and the request body's model read.tst/unit/agents/claude_code/test_usage.py: a Sonnet turn with a Haiku subagent gives each model's counts and the CLI's cost per model.tst/unit/agents/gemini/test_usage.py: rows by model, and a call that named no model counted as the configured model's.packages/agentenv-protocol/tests/test_usage_models.py:ModelUsage.ofsums what the calls gave, takes their cost only when every call reported one, and takes the flag the counted calls agree on.packages/agentenv-protocol/tests/test_a2a_proxy.py: a turn's recorded calls given by the model each named, and a model's cost only when every call reported one.tst/integration/agent/proxy_usage_local_test.py: an episode's recorded calls reach the host with their row.E2E against the real proxy
On an admin host, through a logging pass-through in front of the real proxy, each run's solver entry was compared row by row with the proxy's own count for each model its calls named: the row's counts, its cost against the map's price of the proxy's counts, and, for Claude Code, against the CLI's own cost for that model.
ANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU,FABLE}_MODEL,CLAUDE_CODE_SUBAGENT_MODEL) to the run's model, unless the agent's environment sets one. A gateway may serve no other model, so by default a Claude Code turn runs every call, subagents and WebFetch included, on the run's model. Its rows then have one model, which is right. The two-model runs above setCLAUDE_CODE_SUBAGENT_MODELandANTHROPIC_DEFAULT_HAIKU_MODELin the deploy step'senv_vars.Model spend: about $2.74 at list prices.
Docs
For FD-6263 and FD-6442: which agents give their counts by model (Claude Code, Gemini, OpenCode, Letta Code, the in-process proxy; the sandboxed proxy from the next release; Hermes and Codex next), that their entries carry a row per model, and that
provider_details.modelsmoved toUsage.models.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
Adds per-model counts to
Usage.modelsfor Claude Code, Gemini, OpenCode, Letta Code, and the in-process proxy.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Agent calls or CLI tally] --> B[Group counts by model] B --> C[Usage.models] C --> D[Host prices each model] A --> E[Model cannot be determined] E --> F[No model rows] F --> G[Host uses role model]Reviews (7) · Last reviewed commit: "refactor(agents): one model's row is Mod..." · Reviewed by Greptile