Log the status, error.type and error.code from the failing response
The docs say to inspect error.code for billing-related errors, because error.type can still be insufficient_quota. Log all three fields where you handle the 429 so production logs show the cause.
const body = await res.json();
console.log(res.status, body.error?.type, body.error?.code);
Docs: developers.openai.com →
Check the prepaid credit balance of the organization that owns the production key
If error.code is credit_balance_exhausted, the organization has no prepaid credits remaining. The error-codes page lists one fix: add credits to continue using the API.
Docs: developers.openai.com →
Check spend and usage limits at organization and project level
If the code names a spend or usage limit, check that limit for the organization or project it names. The documented fixes are to increase or remove the organization or project spend limit, or to request a higher approved usage limit or contact support.
Docs: developers.openai.com →
Confirm which key, organization and project production is using
Read the environment variables of the deployed service, not your local .env, and find which organization and project that key was created in. The docs list a key from a different organization or project as a cause of authentication errors. The same mismatch can send you to the wrong credits and limits here, so rule it out.
Docs: developers.openai.com →
Fix the credit or limit, then send one test request before restoring traffic
The docs say to update the relevant credits or limits before sending another request. Send a single request with the production key and check that error.code is gone before you re-enable queued jobs or retries.
Docs: developers.openai.com →
Treat billing and quota codes as non-retryable in your client
Retrying a billing stop adds load and delay, and access stays blocked. Fail fast on these codes and surface them to whoever owns the account. Keep backoff with Retry-After for genuine rate limits.
const STOP = new Set([
"credit_balance_exhausted",
"organization_spend_limit_exceeded",
"project_spend_limit_exceeded",
"organization_usage_limit_exceeded",
]);
if (res.status === 429 && STOP.has(body.error?.code)) {
throw new Error(`billing stop: ${body.error.code}`); // no retry
}
Docs: developers.openai.com →