Repository navigation
fix(bridge): preserve NVIDIA Build token usage - #578
Merged
Merged
Conversation
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
chrisknvidia
requested review from
mosheabr,
rmalani-nv and
rng1995
as code owners
November 14, 2026 23:18
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
1 task done
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
When Codex or Claude Code ran through the NVIDIA Build bridge, Tier 3 recorded no token usage even though every bridged request succeeded: Codex usage was
nulland Claude Code usage was0. The bridge dropped the upstream chat-completionusage. Responses API replies set"usage": None, and Anthropic Messages events hardcodedinput_tokens: 0, output_tokens: 0.The bridge now maps reported prompt, completion and cached tokens into each API's own usage shape:
response.completed:input_tokens,output_tokens,input_tokens_details.cached_tokens.message_start/message_delta:input_tokensexcluding cache reads,cache_read_input_tokens,output_tokens.Responses usage stays null when upstream reports none. Anthropic usage is always schema-valid: missing
input_tokens/output_tokensdefault to 0, and uncached input is clamped at 0. The bridge also returns a plain JSON Messages reply when a client asks for non-streaming output.Real Docker run after the change (one case,
--skip-baseline), fromresult.jsontoken_usage.agents.<agent>.with_skill.totals:Before the change, the same configuration recorded null (codex) and 0 (claude-code).
Verification
tests/test_nvidia_build_bridge.py: measured, missing, completion-only, invalid and cache-exceeds-prompt usage, with strict Anthropic SDK validation of streaming and non-streaming replies)ruff check/ruff format --checkon changed filespytest tests/test_nvidia_build_bridge.py(145 passed)make buildRelease Impact
CHANGELOG.md