Symptoms
- Every request from every app using one OpenAI organization or project fails at the same moment.
- HTTP
429with a body like:
{
"error": {
"message": "You exceeded your current quota, please check your plan and billing details.",
"type": "insufficient_quota",
"code": "insufficient_quota"
}
}
- Lowering traffic does not help. Errors continue at 1 request per minute.
- Latency on failed calls is higher than normal because the SDK retries the 429 before giving up.
This is not a rate limit. A rate limit (rate_limit_exceeded) clears within seconds or minutes. insufficient_quota means the organization or project cannot be billed any more: prepaid credit ran out, a monthly spend limit was reached, or a payment failed. It stays that way until someone with billing rights fixes it.
Step 1: confirm it is billing, not throughput (2 minutes)
Send one small request with the same key the app uses and read the error code:
curl -s -i https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"<a model your project uses>","messages":[{"role":"user","content":"ping"}],"max_tokens":5}' \
| grep -Ei "^HTTP|openai-organization|x-ratelimit-remaining|\"code\""
| What you see | Meaning | Go to |
|---|---|---|
"code": "insufficient_quota" | Billing or spend limit | Step 2 |
"code": "rate_limit_exceeded", x-ratelimit-remaining-tokens: 0 | Real rate limit (TPM/RPM) | Back off, spread load, request a higher tier |
401 invalid_api_key | Key revoked or rotated | Key rotation runbook |
| Works from your laptop, fails in prod | Prod uses a different key, org or project | Compare openai-organization header and project of each key |
Tip
The
openai-organizationresponse header tells you which organization the key actually bills to. Teams often find the production key belongs to an old personal or trial organization.
Step 2: restore service
You have two routes. Start both: one person on billing, one on failover.
Fix billing (needs an Owner of the OpenAI organization)
- Open the billing overview for the organization (
Settings > Billing) and check the credit balance and any failed payment. - Add credit, or fix the payment method. If auto-recharge was configured, check whether it failed or its threshold was too low.
- Check
Settings > Limitsfor an organization-level monthly budget or a project budget that was reached, and raise it if the spend was legitimate. - Send the Step 1 request again. Recovery can take a few minutes after credit is added. Don't redeploy anything while you wait.
Warning
Before raising a limit, spend two minutes on Step 4. If the spend came from a leaked key or a runaway job, more credit just funds the abuse. Revoke the key or stop the job first.
Fail over
If your gateway (LiteLLM, APIM or your own router) has a second provider such as Azure OpenAI, Bedrock or a second OpenAI organization, switch the route now. If it doesn't, put the feature into a degraded mode (cached answers, a "temporarily unavailable" message) so users get a clear response and not a slow timeout.
Step 3: stop retrying a billing error
The openai Python SDK retries 429 responses automatically (max_retries, default 2), and it doesn't tell insufficient_quota apart from a rate limit. Your own retry loop may add more attempts on top. Each failed call then takes several seconds and holds a worker.
Treat insufficient_quota as a non-retryable error and open a circuit:
import time
from openai import OpenAI, RateLimitError
client = OpenAI(max_retries=2, timeout=30)
_billing_block_until = 0.0
def chat(messages, model):
global _billing_block_until
if time.time() < _billing_block_until:
raise RuntimeError("LLM provider unavailable: billing quota exhausted")
try:
return client.chat.completions.create(model=model, messages=messages)
except RateLimitError as e:
if getattr(e, "code", None) == "insufficient_quota":
_billing_block_until = time.time() + 300 # stop calling for 5 minutes
raise RuntimeError("LLM provider unavailable: billing quota exhausted") from e
raise
Do the same in the gateway if it supports conditional retries: retry on rate_limit_exceeded, never on insufficient_quota.
Step 4: find what burned the spend
With an organization admin key (not a normal project key), the Usage and Costs APIs show where the money went. Group by project and model:
START=$(date -d '3 days ago' +%s)
curl -s "https://api.openai.com/v1/organization/costs?start_time=$START&group_by=project_id&limit=30" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" | jq '.data[] | {start: .start_time, results: [.results[] | {project: .project_id, usd: .amount.value}]}'
curl -s "https://api.openai.com/v1/organization/usage/completions?start_time=$START&group_by=project_id,model&bucket_width=1h" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" | jq '.data[].results[] | {project_id, model, input_tokens, output_tokens, num_model_requests}'
Field names in the response can change between API versions; check the current Usage API reference if jq returns nulls.
| Pattern | Likely cause | Action |
|---|---|---|
| One project spikes overnight, steady request count per hour | Batch or backfill job | Pause the job, move it to the Batch API or a separate project with its own budget |
| One key, traffic from unknown sources | Leaked key | Revoke the key now, follow the leaked-key runbook |
| Output tokens jumped, request count flat | Prompt or max_tokens change, agent loop | Roll back the release, cap output tokens |
| Gradual growth, nothing unusual | Normal growth hit a fixed budget | Raise the budget and add forecasting |
Step 5: confirm
- The Step 1 request returns 200 with the production key.
- Gateway error rate back to baseline; no
insufficient_quotain the last 15 minutes of logs. - If you failed over, switch back deliberately and watch error rate for 30 minutes.
- Record the credit balance and the daily burn rate in the incident notes.
Prevent it next time
- Enable auto-recharge for prepaid credit, with a threshold that covers at least several days of peak spend.
- Alert on the error code, not just on 429s. A log query or metric filter on
insufficient_quotashould page someone with billing access, because the on-call engineer usually can't fix it alone. - Separate projects for production, batch and experiments, each with its own key and budget, so a backfill can't starve production chat.
- Watch spend daily with the Costs API and alert when the daily figure exceeds a set multiple of the 7-day average.
- Keep a tested fallback route to a second provider or organization in the gateway.
- Document who holds billing rights in the runbook, with a backup person outside business hours.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get