Repository navigation
Description
Area
Provider adapters
What are you trying to accomplish?
For API-key providers that have no balance endpoint usable with an inference key, see current rate-limit headroom (remaining requests and tokens in the current window and when it resets) in the quota bar, without OpenCodex making extra upstream calls.
What prevents this today?
OpenCodex already sees these headers on every proxied response but only uses some of them for retry classification or the Claude OAuth subscription windows. For OpenAI sk- project keys, Anthropic API keys, xAI, Groq and Mistral, the dashboard shows nothing about remaining limits, and a missing reading cannot be told apart from "no limit".
What should OpenCodex do?
Record the last seen rate-limit headers per (provider, key account, model) from responses OpenCodex already proxies and expose them as passive, timestamped quota windows:
- OpenAI:
x-ratelimit-limit/remaining/reset-requestsand-tokens(reset values are durations such as6m0s; convert to absolute time). - Anthropic API key:
anthropic-ratelimit-requests-*,-input-tokens-*,-output-tokens-*,-tokens-*(RFC 3339 resets). Reuse the existing Anthropic header parsing where possible. - xAI and Groq: the OpenAI-shaped
x-ratelimit-*family (Groq requests = per day, tokens = per minute), read defensively. - Mistral:
x-ratelimit-*-minute/-monthalready parsed insrc/providers/mistral-transport.ts.
Show each window with its age ("as of 2 min ago") and mark it stale after the reset time passes. An absent header renders as unknown, never as 0 remaining. No header values containing identifiers are logged.
Example usage or interface
Quota bar: OpenAI API req 4,980/5,000 · tok 1.9M/2M (resets 6m) · 1 min ago.
Alternatives or workarounds
Balance/spend endpoints exist but need a different credential: OpenAI Usage/Costs API (sk-admin- key), Anthropic Admin API (organization admin key, unavailable to individual accounts), xAI management key (/v1/billing/teams/{team_id}/prepaid/balance). These could be an explicit opt-in later; this issue covers the zero-credential passive signal only. Gemini API keys expose no remaining-quota header or endpoint at all (only Cloud Monitoring with GCP IAM), so Gemini stays "unknown" by design.
Additional context
Docs: OpenAI rate limits (https://platform.openai.com/docs/guides/rate-limits), Anthropic rate limits (https://docs.anthropic.com/en/api/rate-limits), Groq rate limits (https://console.groq.com/docs/rate-limits). Prior-art rule from CLIProxyAPI, CodexBar and claude-code-router: header first, endpoint second; never let a missing reading become zero.
Activity
Show passive API-key rate-limit headroom (lidge-jun#8297)