Engineering

429 Retry-After: Check Quota Before Retrying

Do not treat every HTTP 429 as a short-lived request rate limit. First identify whether the rejection concerns request pacing, an exhausted allowance, or a billing restriction. For LLMAPI, check the billing mode and key actually used by the client before deciding whether to wait or change billing configuration.

The distinction matters: LLMAPI subscription allowance and pay-as-you-go balance are separate, with separate keys. Topping up API credit does not increase subscription quota. For a confirmed request rate limit, follow Retry-After when present; do not assume that every LLMAPI 429 includes that header.

Start with the error reason, not just the status

Read the response body alongside the status and headers. Use the error details for the service you are calling, rather than assigning a single meaning to all 429 responses.

OpenAI's official error guide illustrates why this distinction is necessary. It lists both request-rate errors and billing-related errors under HTTP 429:

OpenAI error example Documented meaning Next step
credit_balance_exhausted The organization has no prepaid credits remaining Address the credit balance before another request
Rate limit reached for requests Requests are being sent too quickly Pace requests and follow Retry-After when present
slow_down The request rate increased too quickly Follow Retry-After when present, reduce the rate, and increase it gradually

These are OpenAI-specific examples, not an LLMAPI error-code contract. Do not require an LLMAPI response to contain those names or interpret a different service's error solely through this table.

For OpenAI billing errors, the guide specifically recommends inspecting error.code: the broader error.type can still be insufficient_quota. It also states that retrying billing, spend, or quota errors does not restore access. Treat those as account checks, not instructions to send the same request repeatedly.

Check which LLMAPI allowance the request uses

The LLMAPI model-selection documentation separates the two billing paths:

  • Monthly subscription: use a subscription key; supported models share the plan allowance.
  • Pay-as-you-go API: use an API billing key and a separate balance; charges depend on the selected channel.

Before retrying, check which key type is configured in the failing client. Do not use the presence of money in one billing mode as proof that the other mode has remaining capacity.

For example, consider this illustrative troubleshooting scenario, not an observed incident: a client uses a subscription key, its subscription allowance is exhausted, and the user adds pay-as-you-go credit. The relevant check is still the subscription allowance. The Claude Code setup guide explicitly says that topping up API credit does not increase subscription quota.

If you intend to use pay-as-you-go billing instead, verify the matching API billing key, model billing mode, and supported client protocol. Do not assume that protocol compatibility makes a model part of your subscription. LLMAPI's live catalog and your key permissions govern the available model IDs, protocols, and features; this catalog is not an official model vendor specification.

For subscription exhaustion, check the allowance reset

LLMAPI subscription allowances are measured in model-weighted units and restore on two windows: five hours and one week. Usage varies with model, context length, and task complexity. Check usage and allowance reset times in the console rather than estimating remaining allowance from a raw count of requests.

Use the current plans page to compare plan allowances and current pricing. For an exhausted subscription allowance, use the account's displayed usage and reset information to decide when to try again; do not substitute an arbitrary short retry delay for that check.

A practical account checklist is:

  1. Confirm that the client is using the intended subscription or API billing key.
  2. Inspect usage for that billing mode, not just the other mode's balance.
  3. For a subscription, inspect allowance and reset times.
  4. Confirm the requested model's billing mode and your key permissions.
  5. Only then decide whether the next step is waiting, correcting configuration, or addressing billing.

Use Retry-After for pacing, not as a billing fix

For request-rate errors, OpenAI's documented guidance is to pace requests and follow Retry-After when it is present. For slow_down, it additionally recommends reducing the request rate and increasing it gradually.

Use that distinction as a troubleshooting rule: first establish that the problem is request pacing, then apply the service's retry guidance. A header should not replace checking an explicit billing or quota reason.

For LLMAPI, inspect the actual response for Retry-After; do not build your diagnosis around a presumed guarantee that the header will be returned. If it is absent, do not invent a reset time from the 429 status alone. Check the error reason and the relevant account usage before choosing a retry schedule.

As a conservative client policy, avoid an immediate, unbounded retry loop while the reason remains unclear. For a confirmed request-rate restriction, pace subsequent work rather than simply repeating the rejected request at the same rate. For an exhausted subscription allowance, consult the displayed reset information. For a credit issue, inspect the balance associated with the key in use.

The essential order is classify the rejection, check the matching account state, then decide whether and when to retry. Retry-After belongs in that decision—not in a blanket rule that treats every 429 as temporary throttling.

分享这篇文章

开始使用 LLM API

免费套餐可用。Claude Code 一行配置。

免费开始