Skip to content

feat(gateway): record per-upstream billing evidence - #8337

Merged
CaucherWang merged 5 commits into
volcengine:mainfrom
CaucherWang:codex/gateway-billing
Nov 25, 2026
Merged

CaucherWang merged 5 commits into
volcengine:mainfrom
CaucherWang:codex/gateway-billing

Conversation

@CaucherWang

@CaucherWang CaucherWang commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Complete Gateway suite: 1272 passed, 86 skipped, 13 deselected. Redis services and other optional integrations were not configured for skipped cases.
  • Regression coverage includes streaming and non-streaming continuations, both before and after response headers, with separate tool-total and upstream-wait timeouts; final response.failed metadata; truncated responses with and without tools; raw multi-protocol usage; rate limits; body-read failures; cancellation; and summary timeouts.
  • Ruff and whitespace checks passed.

Comment thread tests/gateway/test_billing_evidence.py Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants