OpenAI integration

OpenAI spend alerts and brakes

Costbrake reads your OpenAI usage and costs with a Read only Admin key every 5 minutes on Pro and Team, and every 2 minutes for 2 hours after a spike alert. Its brake sets a project's or the organization's monthly hard spend limit to $0.01, so paid requests fail with a 429 once OpenAI enforces it, and Undo puts the old limit back.

The Free plan checks hourly and alerts by email. Brakes come with Pro at $12 a month and Team at $39 a month (see pricing), and an admin starts every brake by hand.

OpenAI at a glance

Reads
Usage API per hour, priced at list prices, then the Costs API's billed dollars per day
Key
Admin key set to Read only, plus a second Admin key with All permissions for brakes
Setup
Paste the Admin key on the connect page, or on the page your coding agent sends; add the brake key in the dashboard
Free plan
Checks every hour, email alerts, no brakes
Pro and Team
Checks every 5 minutes, Slack, Discord and webhook alerts, brakes
Spike checks
Every 2 minutes for 2 hours after a spike alert
Brakes
Freeze project spend, Freeze organization spend

Brakes

2 brakes for OpenAI

An admin picks a brake, confirms it, and can undo it later. Brakes come with Pro and Team.

  • Admin confirms

    Freeze project spend

    Sets the project's monthly hard spend limit to $0.01, so every paid request in that project fails with 429 project_spend_limit_exceeded once OpenAI enforces it.

    UndoRestores the project's previous spend limit, or removes the limit if it had none.

    OpenAI says enforcement is not instantaneous, so a little more usage can land before requests fail; other projects keep working.

  • Admin confirms

    Freeze organization spend

    Sets the organization's monthly hard spend limit to $0.01, so every paid request in every project fails with 429 organization_spend_limit_exceeded once OpenAI enforces it.

    UndoRestores the organization's previous spend limit, or removes the limit if it had none.

    This stops all paid API traffic in the organization, production included, until Undo and OpenAI's update propagate.

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.

ControlWhat it doesStops requests?Gap
OpenAI spend alertSends a notification at an amount you setNo, traffic continuesSpend keeps running until someone acts
OpenAI hard spend limitReturns 429 once tracked spend reaches the monthly amountYes, per project or organizationSet at your budget, so a leak can spend the whole budget first
Costbrake spike alertAlerts when an hour costs over 3 times its 7-day usual and at least $5 moreNoNeeds 24 hours of history first
Costbrake brakeDrops the project or organization limit to $0.01Yes, once OpenAI enforces itWaits 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

  1. An admin turns on the killswitch for the OpenAI connection and adds the All permissions Admin key.
  2. 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.
  3. Costbrake sets that hard spend limit to $0.01. Once OpenAI enforces it, paid requests return 429 with the project or organization code.
  4. 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

Start with 14 days of Pro, free

Catch the next OpenAI spike before the invoice.

14 days of Pro, then Free for 2 accounts. No card needed.