Surface Codex reasoning tokens and rate limits in Anthropic usage - #149
Open
sommaht wants to merge 1 commit into
Open
Surface Codex reasoning tokens and rate limits in Anthropic usage#149sommaht wants to merge 1 commit into
sommaht wants to merge 1 commit into
Conversation
The Codex translators already parse output_tokens_details.reasoning_tokens
into CodexUsage but dropped it when mapping to the Anthropic usage block,
so clients saw output_tokens with no reasoning breakdown. Emit it as
output_tokens_details.{reasoning_tokens,thinking_tokens}; the second name
matches what Claude Code records for Anthropic models so per-turn
accounting stays comparable across providers.
The codex.rate_limits stream event was only turned into a progress ping.
Codex sends it before any usage exists, so both translators (the buffered
reducer and the live-stream translator) now keep the latest snapshot and
attach it to the CodexUsage they build from response.completed. The
mapper turns it into a typed codex_rate_limits field (plan, limit_reached,
primary/secondary used_percent, window, reset) on the terminal
message_delta usage, so a client or proxy can observe the subscription
meter per response. Both paths get it through the one mapper.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
sommaht
force-pushed
the
usage-visibility
branch
from
September 11, 2026 23:31
a45d196 to
95f76c0
Compare
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.
Summary
Two small additions to the Codex → Anthropic usage mapping so clients can account for what a Codex turn actually cost.
parse_codex_usagealready readsoutput_tokens_details.reasoning_tokensintoCodexUsage, butmap_codex_usage_to_anthropicdropped it. It is now emitted asoutput_tokens_details.{reasoning_tokens, thinking_tokens}. The second name is what Claude Code records for Anthropic models, so per-turn accounting in its transcripts becomes comparable across providers (verified: Claude Code keepsthinking_tokensin the transcript usage block; before this it was always 0 for Codex models).codex.rate_limitsstream event was only converted into a progress ping. Codex sends it before any usage exists, so both translators (buffered reducer and live-stream) keep the latest snapshot and attach it to theCodexUsagebuilt fromresponse.completed. The mapper emits it as a typedcodex_rate_limitsfield (plan_type,limit_reached, primary/secondaryused_percent,window_minutes,reset_at) on the terminalmessage_deltausage. Downstream proxies can log the subscription meter per response; Claude Code itself ignores the unknown key.Example terminal usage after the change:
{"input_tokens":23,"output_tokens":24,"cache_read_input_tokens":0,"cache_creation_input_tokens":0, "output_tokens_details":{"reasoning_tokens":17,"thinking_tokens":17}, "codex_rate_limits":{"plan_type":"prolite","limit_reached":false, "primary":{"used_percent":8.0,"window_minutes":10080,"reset_at":1789765755}}}Test plan
cargo test --release: all suites pass; adds a mapper test for reasoning + rate limits, extends the reducer and live-streamcodex.rate_limitstests to assert the snapshot reaches the finish usage.cargo fmt --checkclean./v1/messagesagainstgpt-5.6-terraatxhigheffort reports 390 reasoning of 566 output tokens; a request through Claude Code showsthinking_tokenspopulated in the session transcript.🤖 Generated with Claude Code