How to set a hard spending limit on the OpenAI API
Last updated
OpenAI lets you set a monthly spend limit on each project and on your whole organization. To make requests fail at the limit, you also turn on Enforce a hard limit. This page shows where to set it, what your app sees when it's reached, and what it doesn't cover.
Everything here was checked against OpenAI's docs and its official SDKs on November 11, 2026. The two reported error messages and the note on API keys were added and checked on November 13, 2026. The sources are linked under the sections they back up.
The short version
- Open the project, then go to Project settings → Limits.
- Under Spend, click Edit spend limit and enter a monthly spend limit.
- Turn on Enforce a hard limit, then click Save.
Do the same under Organization limits to cap all projects together.
Project limit or organization limit?
- An organization limit is one total for API traffic across all your projects.
- A project limit covers only the traffic billed to that project. When one project reaches its limit, other projects can continue, unless they reach their own limit or the organization limit is reached too.
You can use both: a small limit on each project that runs agents or experiments, and an organization limit set to the most you could stand to lose in one month.
OpenAI's docs don't describe a spend limit for a single API key, only for an organization and for a project. OpenAI says separate projects can isolate usage for different applications or environments.
Sources: OpenAI, Spend limits, OpenAI, Error codes, OpenAI, API keys and service accounts
Set a limit on one project
- Open the project, then go to Project settings → Limits.
- Under Spend, click Edit spend limit.
- Enter a monthly spend limit.
- Turn on Enforce a hard limit, so requests fail once the limit is reached.
- Click Save.
You need permission to manage the project's settings.
Set a limit on the whole organization
- Go to Organization limits.
- Under Spend, click Edit spend limit.
- Enter a monthly spend limit, turn on Enforce a hard limit, and click Save.
You need permission to manage the organization's settings.
Source: OpenAI, Spend limits
What happens when you reach it
Requests fail with error 429. The error code says which limit was reached: project_spend_limit_exceeded or organization_spend_limit_exceeded.
- It isn't instant. OpenAI says recorded spend can slightly exceed the amount you set.
- Requests work again once you raise or remove the limit and the change takes effect, or when the next monthly cycle starts.
Source: OpenAI, Spend limits
Four 429 errors that retrying won't fix
A spend limit isn't the only 429 that retrying won't fix. Each one has its own error code:
project_spend_limit_exceeded: the project reached its hard limit. Raise or remove the project's limit, or wait for the monthly reset.organization_spend_limit_exceeded: the organization reached its hard limit, which applies to every project. Raise or remove the organization limit, or wait for the monthly reset.organization_usage_limit_exceeded: the organization reached the usage limit OpenAI assigned to it, which is separate from the limits you set. Ask OpenAI for a higher approved usage limit.credit_balance_exhausted: no prepaid credits are left. Add credits in your billing settings.
Ordinary rate limits are different. When you send requests too quickly, OpenAI says to follow the Retry-After header when it's there, or else back off and retry.
“You have no credits remaining”
Error code: 429 - {'error': {'message': 'You have no credits remaining. Add credits to continue using the API at https://platform.openai.com/settings/organization/billing/.', 'type': 'insufficient_quota', 'param': None, 'code': 'credit_balance_exhausted'}}This is the credit_balance_exhausted error from the list above. Add credits; OpenAI says the new balance may take a few minutes to appear. The check in the next section doesn't retry this error. OpenAI's docs give the code but not this message: the text is from a GitHub issue dated November 12, 2026.
“You exceeded your current quota, please check your plan and billing details”
{'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}If you get this one, check your credit balance and your organization and project limits. The check in the next section doesn't retry it either.
OpenAI's error codes page no longer lists this message. An archived copy from July 23, 2026 lists it as a 429 for an organization that used up its prepaid credits or reached a usage or spend limit. The text above is from a log in a GitHub issue opened on August 21, 2026: api.openai.com answers 429 with it on August 20. The newest log of it we found was posted on GitHub on August 27, 2026. We don't know whether the API still sends it.
For what each of these errors means and how to fix it, including when you pay for ChatGPT or just added credits, see our guide to OpenAI's insufficient_quota error.
Sources: OpenAI, Error codes, OpenAI Help Center, Troubleshooting API usage and spend limits
Stop your code from retrying a limit
All of these come back as 429, the same status as a rate limit. OpenAI's official Python and Node SDKs retry 429 errors 2 times by default. If your own code retries too, those retries add up. Check the error code before you retry:
from openai import OpenAI, RateLimitError
# 429 errors that retrying won't fix
DONT_RETRY = {
"project_spend_limit_exceeded",
"organization_spend_limit_exceeded",
"organization_usage_limit_exceeded",
"credit_balance_exhausted",
}
# Your own retry loop decides, so turn off the SDK's 2 automatic retries
client = OpenAI(max_retries=0)
def is_retryable_rate_limit(error: Exception) -> bool:
"""True only for a real rate limit. False for a spend, usage or credit limit."""
return (
isinstance(error, RateLimitError)
and error.code not in DONT_RETRY
and error.type != "insufficient_quota"
)import OpenAI from "openai";
// 429 errors that retrying won't fix
const DONT_RETRY = new Set([
"project_spend_limit_exceeded",
"organization_spend_limit_exceeded",
"organization_usage_limit_exceeded",
"credit_balance_exhausted",
]);
// Your own retry loop decides, so turn off the SDK's 2 automatic retries
const client = new OpenAI({ maxRetries: 0 });
// True only for a real rate limit. False for a spend, usage or credit limit.
function isRetryableRateLimit(error: unknown): boolean {
return (
error instanceof OpenAI.RateLimitError &&
!DONT_RETRY.has(error.code ?? "") &&
error.type !== "insufficient_quota"
);
}Call the check in your retry loop. When it says yes, wait as long as the Retry-After header says, or back off if there's no header. When it says no, stop and tell someone: the request will keep failing until the limit or the credits change.
Both SDKs put the code from OpenAI's response on the error as code, and its type as type. OpenAI says billing errors can also have the type insufficient_quota, which is why the check looks at that too.
Sources: OpenAI, Error codes, openai-python, Retries, openai-node, Retries, openai-python errors, openai-node errors
Spend alerts don't block anything
OpenAI's spend alerts only send a notification. They don't stop traffic. You can keep them on next to a hard limit, so you get a warning before requests start failing.
Source: OpenAI, Spend limits
What the limit doesn't cover
- It's monthly. A loop can spend the whole month's limit in one night, and the project stays blocked until you raise or remove the limit, or the month resets.
- It only acts at the end. Without alerts, you find out when your app stops working.
- It only sees OpenAI. Anthropic, Gemini and OpenRouter each have their own cap. This guide covers all four.
Where Billfuse fits
Billfuse is the tool we built for these gaps. It doesn't replace OpenAI's hard limit. Keep it on.
- One budget across OpenAI and your other providers. Billfuse connects with an OpenAI admin key, checks your spend every hour and emails you at 50%, 80% and 100% of the budget. It can post to Slack too.
- Spike alerts, with no budget needed. When one provider's day reaches 3 times a normal day, and at least $10 more, you get an email, and a Slack message if you added one.
- Pausing, if you turn it on. When your total budget or your OpenAI budget reaches 100%, Billfuse sets each active OpenAI project's spend limit to $0.01. Resume puts back each project's earlier limit, unless you changed it while it was paused.
- What it can't do. It checks hourly, so it's slower than OpenAI's own limit. It reads what you spent, not your prepaid credit balance, so it doesn't warn you when credits are about to run out.
More guides
- How to put a hard spending cap on OpenAI, Anthropic, Gemini and OpenRouter
- How to set a spending limit on the Anthropic API
- How to set a spending limit on the Gemini API
- How to set a spending limit on the OpenRouter API
- Billing error or rate limit? AI API errors from OpenAI, Anthropic, Gemini and OpenRouter
- Leaked AI API key: what to do first
- Fix "Your credit balance is too low to access the Anthropic API"
- Gemini API error 402: "Your prepayment credits are depleted"
- OpenAI error 429 insufficient_quota: "You exceeded your current quota"
- OpenRouter 402: "This request requires more credits, or fewer max_tokens"
It's free while Billfuse is in early access. You can try it with sample data first, no sign-up needed.