Credentials. The script will need an API key, so load it from an environment variable and never hard-code it.
Who it is forA developer or operations engineer who runs scripts or agents that need to check how much quota an API key has left before starting work.
The problemClients cannot see how close an API key is to its window limits, so jobs fail mid-run when a limit is hit.
The outcomeA script that reads /v1/usage and reports the same quota source the Codex headers use.
What you need first
- Docker installed and running, or uv installed for running from source
- Upstream ChatGPT accounts you are authorized to use, to add in the dashboard
- A browser to open the dashboard at localhost:2455
- Codex CLI, desktop, or IDE integration, or another OpenAI-compatible client, if you plan to connect one
Steps
- Configure 5h, daily, 7d, weekly, or monthly windows for an API key in the dashboard, using credits, tokens, or cost limits.
- Enable Codex quota emulation and choose API-key limits or pooled-account estimates as the display source.
- Send an authenticated GET request to the /v1/usage endpoint with your API key.
- Parse the JSON response and compare the remaining amounts with the window limits you set. (inferred, check the README)
- Make your script stop or wait when remaining usage falls below your threshold.
Prompt for your agent
In the aafqaq/codex-lb-enhanced repo, write a small script that calls /v1/usage on <gateway URL> with the API key in <env var name>. Output the remaining usage per window as JSON. Verify that the output matches the usage limits shown in the dashboard for that key.
Caveat. The README says model-specific limits do not become the default Codex window, so check model-level limits in the dashboard separately.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for aafqaq/codex-lb-enhanced and "Read API-key quota usage from /v1/usage in scripts"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer