feat(codex): forward quota telemetry to the client - #127
Open
rikbrown wants to merge 2 commits into
Open
Conversation
added 2 commits
August 31, 2026 09:28
Codex reports how much of a ChatGPT subscription is spent twice: as `x-codex-*` headers on an HTTP response, and as a `codex.rate_limits` event on the WebSocket transport. The proxy answers in Anthropic's format, which has no equivalent field, so neither reaches the client and a tool in front of the proxy — a rotating multi-account gateway, a quota readout — cannot see the limit it is about to hit. Keep the newest snapshot and stamp it onto every Codex response under the header names Codex itself uses, so a client that already reads them needs no second format. The event precedes the first generated output on both transports and the response head is built from that output, so a response normally carries the numbers of the request it answers. Only quota headers are forwarded: `x-codex-turn-state` is continuation state, and a large opaque blob to put on every response.
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.
Problem
Codex reports how much of a ChatGPT subscription is spent in two places:
x-codex-*headers on an HTTP response, and acodex.rate_limitsevent on the WebSocket transport. Neither reaches the client. The proxy answers in Anthropic's format, which has no equivalent field, so the event is classified as control and becomes aping, and the response headers are dropped.That leaves anything sitting in front of the proxy — a rotating multi-account gateway, a quota readout — unable to see the limit it is about to hit. The first sign of a spent window is a 429.
Change
A new
providers/codex/rate_limits.rskeeps the newest snapshot and stamps it onto every Codex/v1/messagesresponse, under the header names Codex itself uses, so a client that already parses them needs no second format. Both transports feed it: the HTTP response head, and thecodex.rate_limitsevent.Only quota headers are forwarded.
x-codex-turn-stateis continuation state, and a large opaque blob to put on every response.Codex sends the event ahead of the first generated output and the response head is built from that output, so a response normally carries the numbers of the request it answers. One that arrives before any telemetry does carries the previous snapshot, or none.
Which window is which is left to the client, because it varies: a ChatGPT Pro subscription reports its weekly limit as
primaryand meters no secondary window at all, so the-window-minutesheader is what identifies a bucket, not the position.Testing
cargo test— 1033 pass.cargo clippy --all-targetsandcargo fmt --checkclean.The HTTP API reference gains a paragraph describing the headers.
🤖 Generated with Claude Code
https://claude.ai/code/session_01S3HCmE8ZPT1o59UCGaoEeV