Guide · OpenAI
A per-key spend limit OpenAI will not set for you
Project budgets are a monthly ceiling for a whole project. A research agent and a support bot on the same project share it. A loop at 2 a.m. does not wait for the budget email.
What the dashboard actually gives you
OpenAI can show organization usage and a project budget. The budget is not a per-key hard stop that fires in minutes. Usage grouped by API key exists in the admin API, which is the useful part: each key has an id, and completions can be bucketed by minute.
The admin key, not the inference key
The key in your agent is a project key. It can call the model. It cannot list organization usage. For a spend guard you create an organization admin key in the OpenAI platform, under organization settings, and you keep it out of the agent. BillCurfew asks for that admin key and nothing else.
Two endpoints, two jobs
- GET /v1/organization/usage/completions with bucket_width 1m, grouped by api_key_id, project_id, and model, is how a spike shows up. The response is tokens. We turn tokens into dollars with a maintained price table.
- GET /v1/organization/costs with bucket_width 1d, grouped by api_key_id, is the provider’s own dollar figure. Daily caps use this number when it is present, so a price-table miss does not decide the bedtime.
Killing the key
DELETE /v1/organization/projects/{project_id}/api_keys/{api_key_id} removes the key. Agents using it fail on the next call. OpenAI does not offer an undo. Treat auto-kill as a loaded switch: leave it off until you have typed the warning and meant it. A manual kill in BillCurfew makes you type DELETE.
A practical bedtime
Start with a daily cap near the key’s normal afternoon total, not the number you hope to hit on a bad day. Add a spike rule around 8× over 10 minutes. A healthy agent does not 8× its recent baseline in ten minutes. A loop does.
Let BillCurfew watch the key
Paste the admin key, set a daily cap and a spike rule, and get email before the invoice does. Prompts stay with the provider.
Start on the free tier