8 min read · Updated 2026-11-29
How to set a spending limit on your OpenAI API key
Set a monthly spend limit and turn on a hard cap so a leaked key or a chatty app cannot run an unlimited OpenAI bill.
A spending limit is the seatbelt. It does not stop someone from copying a key out of your website, and it does not refund money you already spent. It does stop the meter from running all month once tracked spend hits a number you chose.
OpenAI has two different ceilings. One is the usage limit OpenAI assigns your organization (the Build, Launch, and Grow tiers). The other is the spend limit you set yourself. You want the second one, and you want it to be a hard limit, not only an email.
Set an organization hard limit
You need permission to manage organization settings. The clicks live in the OpenAI dashboard, and the official write-up is the spend limits guide. The shape of the task is:
- Open organization limits in the API platform.
- Under Spend, choose Edit spend limit.
- Enter a monthly amount you can actually lose. For a hobby app, start at something like $20 or $50, not $2,000.
- Turn on Enforce a hard limit. This is the switch that makes requests fail. Without it, the number is a notification and traffic keeps going.
- Save.
- Add a spend alert around half of that amount, so you hear about a spike before the app stops.
Set a project limit too
A project hard limit covers only the traffic billed to that project. An organization hard limit covers every project. If the key that leaked belongs to one project, set both. A loose org limit does not protect you from a single project going wild, and a project limit does not protect the other projects.
- Open the project, then Limits.
- Under Spend, edit the monthly spend limit.
- Turn on Enforce a hard limit if you want calls to stop.
- Add an alert below 100% so you are not surprised by the stop.
What a limit does not do
- It does not revoke a key. If the key is in your JavaScript, rotate it in the API keys page the same day. The old key keeps working until you revoke it, cap or not.
- It does not hide the key. Visitors can still copy it. They just hit your ceiling instead of an unlimited one.
- It is not a per-user cap inside your app. One noisy user can still consume the whole monthly budget. That cap belongs in your server route.
- A spend alert alone does not stop traffic. The alert is an email. The hard limit is the brake.
The current steps and the exact error codes are in OpenAI's spend limits guide: https://developers.openai.com/api/docs/guides/spend-limits — if the dashboard labels move, trust that page over a screenshot.
Then get the key out of the browser
The limit is the backstop. The real fix is that the browser never sees the key. Run the free BrakeKey scan on your public URL, and if the grade is bad, paste the fix prompt it gives you into Lovable, Bolt, or Cursor.