Repository navigation
Move the quota reader to tw-wire, and stop rebuilding header maps - #127
Merged
Merged
Conversation
…r maps `quota` reads the subscription window straight out of response headers — Anthropic puts it on every response, Codex has the same shape in another set. It costs nothing: no extra request, no extra scope, no spending the user's own quota. It has no `tw-*` dependency and nothing about it is specific to this gateway, so it belongs next to the other sideband readers. The enterprise gateway has no equivalent and needs one as soon as it fronts a subscription account. `from_headers_reqwest` goes away. It rebuilt the entire header map entry by entry on the premise that "reqwest and axum each have their own HeaderMap" — which has not been true for some time. reqwest 0.13 and axum 0.8 both re-export http 1.5.0, so the two arguments were already the same type and every response paid for a copy that changed nothing. (The one http 0.2 in the tree comes in under aws-sigv4, i.e. the Bedrock provider.) Calling `from_headers` directly compiles, which is the proof. The crate now depends on `http` rather than reaching through axum: a shared layer should not dictate which HTTP framework its consumers run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
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.
Follows #126.
What moves
quota.rs(455 lines) joinsusageandbodiesintw-wire.It reads the subscription window straight out of response headers — Anthropic puts it on every response, Codex has the same shape in another set. No extra request, no extra scope, no spending the user's own quota. Zero
tw-*dependencies, and nothing in it is specific to this gateway.The enterprise gateway has no equivalent and will need one the moment it fronts a subscription account.
What gets fixed on the way
from_headers_reqwestis deleted. It rebuilt the whole header map entry by entry:Its doc comment explained the premise: "reqwest 和 axum 各有各的
HeaderMap". That stopped being true at some point — reqwest 0.13.4 and axum 0.8.9 both re-exporthttp 1.5.0, so the two arguments were already the same type, and every single response paid for a copy that changed nothing. Callingfrom_headersdirectly compiles, which is the proof.(The one
http 0.2.12left in the tree arrives underaws-sigv4— the Bedrock provider.)Dependency note
The crate now depends on
httpdirectly instead of reaching throughaxum::http. A shared layer should not dictate which HTTP framework its consumers run; both of the maps it was juggling were this crate's type all along.cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings, and the full test suite (28 suites) are green.🤖 Generated with Claude Code