Can you set a hard spending limit on the OpenAI API?
Yes. OpenAI lets you set a monthly spend limit for the organization and for each project, and turn on Enforce a hard limit. When tracked spend reaches it, affected requests return a 429 error with the code organization_spend_limit_exceeded or project_spend_limit_exceeded. A spend alert is different: it sends a notification and API traffic continues.
Two gaps remain. OpenAI says enforcement is not instantaneous, so recorded spend can slightly exceed the limit. And a monthly limit only stops spend at the number you picked: if it sits at your normal monthly budget, a leaked key or a runaway loop can burn that whole budget before anything stops. How to set a hard spending limit on the OpenAI API walks through both settings.
What Costbrake reads from OpenAI
Costbrake calls OpenAI's Usage API in hourly buckets for completions, embeddings, speech, transcription, web search, file search and code interpreter sessions. It prices those token and call counts at OpenAI's list prices to estimate live spend. The Costs API's billed dollars then replace the estimate one day at a time; Costbrake refreshes them every 4 hours.
Realtime, GPT-Live, video, image generation and fine-tuning only appear in the daily billed costs, so a spike there shows up once OpenAI bills the day. For the endpoints themselves, see How to track OpenAI API costs with the Usage and Costs APIs.
| Control | What it does | Stops requests? | Gap |
|---|---|---|---|
| OpenAI spend alert | Sends a notification at an amount you set | No, traffic continues | Spend keeps running until someone acts |
| OpenAI hard spend limit | Returns 429 once tracked spend reaches the monthly amount | Yes, per project or organization | Set at your budget, so a leak can spend the whole budget first |
| Costbrake spike alert | Alerts when an hour costs over 3 times its 7-day usual and at least $5 more | No | Needs 24 hours of history first |
| Costbrake brake | Drops the project or organization limit to $0.01 | Yes, once OpenAI enforces it | Waits for an admin to confirm |
Which OpenAI key does Costbrake need?
An Admin key. OpenAI Admin API keys only work on administration endpoints, so they cannot call models. In OpenAI's permissions table, managing admin API keys belongs to Organization Admin, which only the organization owner role includes. Create the key under Settings, Organization, Admin keys, choose Read only, and paste it on the connect page. Costbrake only accepts keys that start with sk-admin-.
Brakes need a second Admin key with All permissions. You add it in the Costbrake dashboard when you turn on the killswitch for the connection. If a coding agent sets up Costbrake through agent setup, it sends you a connect page and you paste the OpenAI key there yourself; the agent never gets brake credentials.
How the OpenAI brake works
- An admin turns on the killswitch for the OpenAI connection and adds the All permissions Admin key.
- When an alert comes in, the admin opens the connection, picks one project or the whole organization, and types the connection's name to confirm.
- Costbrake sets that hard spend limit to $0.01. Once OpenAI enforces it, paid requests return 429 with the project or organization code.
- Undo puts back the previous limit, or deletes the limit if there was none. OpenAI resumes traffic after the update propagates.
Costbrake refuses to freeze a project or organization that is already at $0.01, and it never deletes a project or a key. Undo keeps working after a downgrade from Pro, so a braked project never gets stuck.
What Costbrake can't do on OpenAI
- Stop spend on its own. Alerts are automatic; a brake always waits for an admin.
- Freeze a single API key. OpenAI's hard limits work per project and per organization, so the brake freezes a whole project.
- See Realtime, video, image generation or fine-tuning spend before OpenAI bills the day.
- Take back usage OpenAI recorded before the limit took effect.
If a key has already leaked, freeze the project first, then rotate the key. What to do in the first hour after an API key leaks has the full order.
Questions and answers
Does Costbrake stop OpenAI spend automatically?
No. Costbrake sends alerts automatically, but a brake only runs when an admin of your Costbrake workspace starts it and types the connection name to confirm. The brake then sets the project or organization hard spend limit to $0.01.
What error do OpenAI requests return after the brake?
HTTP 429 with the code project_spend_limit_exceeded for a frozen project, or organization_spend_limit_exceeded for a frozen organization. Running out of prepaid credits returns a different code, credit_balance_exhausted.
How quickly does Costbrake see OpenAI spend?
Costbrake checks every 5 minutes on Pro and Team, every 2 minutes for 2 hours after a spike alert, and every hour on Free. Live spend is an estimate from token and call counts until OpenAI's billed costs for the day replace it.
Can I connect a normal OpenAI API key instead of an Admin key?
No. The Usage and Costs endpoints need an Admin key, and an Admin key cannot call models. Choose Read only for monitoring and keep the All permissions key for brakes only.
Does the OpenAI brake delete anything?
No. It only changes a spend limit. Undo restores the previous limit, or removes it if there was none, and nothing in your OpenAI projects is deleted.
Sources
Updated