Skip to content
prune.

Can you set a spending limit on one OpenAI or Claude API key?

What the providers cap, what they do not, and why a budget you set may still let requests through.

Quick answer

Not per key. OpenAI hard spend limits apply to a project or organization; Anthropic spend limits apply to an organization or workspace. Both are monthly and both can overshoot slightly. The closest native setup is one OpenAI project (or Anthropic workspace) per key. For a daily cap on an individual key, put a gateway in front.

OpenAI: project and organization limits

OpenAI has two spend controls. A spend alert emails you and lets traffic continue. A hard spend limit makes requests fail with 429 once tracked spend reaches the amount. You set both under Organization limits or Project settings, Limits, Edit spend limit, and the hard limit only applies when Enforce a hard limit is switched on.

project limit reached
{
  "error": {
    "type": "insufficient_quota",
    "code": "project_spend_limit_exceeded",
    "message": "..."
  }
}

The code tells you which limit tripped: project_spend_limit_exceeded, organization_spend_limit_exceeded, credit_balance_exhausted (prepaid balance is empty) or organization_usage_limit_exceeded (the limit OpenAI set for your tier). Retrying does not help with any of them.

Why your OpenAI budget is not stopping requests

  • It is an alert, not a hard limit. The most common cause. Open the project's Limits page and check that Enforce a hard limit is on.
  • The traffic is billed somewhere else. A project limit only covers traffic billed to that project. A key from another project, or an organization key, is not affected.
  • Enforcement lags. OpenAI says changes and enforcement are not instantaneous, so recorded spend can slightly exceed the limit.
  • You are looking at ChatGPT, not the API. ChatGPT projects and API platform projects are different things.

Anthropic: organization and workspace limits

Every Anthropic usage tier carries a monthly spend cap for the organization. You can set your own lower limit in the Claude Console under Settings, Billing, Spend limits, and a separate lower limit for each workspace (not the default workspace). When your own limit is hit, requests return 400 invalid_request_error with a message starting "You have reached your specified API usage limits". When the tier cap is hit, requests return 429 with enforced_spend_limit_reached and no retry-after, so automatic SDK retries just fail again.

Some AI answers still say Claude has no monthly budget setting. It does; it moved to the Billing page.

Getting a per-key limit anyway

  • One project or workspace per key. Works for a few services. Each needs its own limit, and the limit is monthly, so a leaked key can still spend the whole month in a night.
  • Your own meter. Record cost per key from the usage field of each response and stop calling when it crosses a number. It only protects code paths that remember to check.
  • A gateway. Every call passes through one place that knows which key made it, so the cap cannot be skipped.

Doing this with Prune

Prune is an AI gateway. Create one Prune key per service, and Shield gives each key its own daily spend cap (resets at 00:00 UTC), spike detection, rate limit, IP allowlist and allowed models. The cap counts input and output tokens at list price and is checked before the call reaches the provider. A key that hits it gets 429 with X-Prune-Shield-Code: spend_cap; nothing else stops. New accounts start on Balanced ($200 a day); Locked down is $50 a day.

client.py
import os
from openai import OpenAI

# One Prune key per service. Each gets its own daily cap in Shield.
client = OpenAI(
    base_url="https://api.withprune.com/v1",
    api_key=os.environ["PRUNE_API_KEY"],   # OpenAI key stays in the Prune vault
)

Keep the provider's monthly hard limit on as well. Two independent limits are better than one. For limits per end user rather than per key, see per-user budgets.

With a single line of code, Prune cuts your AI bill and protects your team from runaway spend, leaked keys and dangerous calls.

Related

Have an account? Sign in · PyPI.