Skip to content
Billfuse

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

  1. Open the project, then go to Project settings → Limits.
  2. Under Spend, click Edit spend limit and enter a monthly spend limit.
  3. 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?

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

  1. Open the project, then go to Project settings → Limits.
  2. Under Spend, click Edit spend limit.
  3. Enter a monthly spend limit.
  4. Turn on Enforce a hard limit, so requests fail once the limit is reached.
  5. Click Save.

You need permission to manage the project's settings.

Set a limit on the whole organization

  1. Go to Organization limits.
  2. Under Spend, click Edit spend limit.
  3. 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.

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:

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 429, as reported
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”

Error 429, as reported
{'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:

Python
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"
    )
TypeScript
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

Where Billfuse fits

Billfuse is the tool we built for these gaps. It doesn't replace OpenAI's hard limit. Keep it on.

More guides

It's free while Billfuse is in early access. You can try it with sample data first, no sign-up needed.