Repository navigation
feat(gateway): record per-upstream billing evidence - #8337
Merged
Merged
Conversation
t0saki
approved these changes
Nov 24, 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.
Summary
Record provider-reported accounting evidence for each Gateway upstream request, including the initial model request, compaction summaries, and hidden-tool continuations. Each entry keeps allowlisted token counters, response ID, actual model, service tier, timing, upstream HTTP status, completion state, and failure reason.
Streaming and non-streaming requests use the same raw protocol evidence. Missing counters remain absent, Anthropic input counters retain the provider's meaning, and metadata is recorded only when explicitly supplied. Usage details are parsed to a bounded depth.
Each hidden-tool round closes its own accounting entry, including rate limits, body-read failures, cancellation, and stream error events. Summary completion follows protocol validation. Non-generation passthrough requests are labeled separately. Entries correlate with the existing Gateway request ID and omit prompts and credentials.
Responses truncation preserves the provider status and incomplete reason with consistent completion semantics on both forwarding and hidden-tool paths. Tool-loop timeout attribution is recorded after the loop classifies the failure, retaining the actual upstream HTTP status. Both response-header and response-body timeouts use the tool loop classification, with a null HTTP status when no response was received. Responses failure events retain final provider metadata for reconciliation.
Verification