Skip to content

AI API rate limits: queue work before adding retries

7 min read
AI Strategy
AI API rate limits: queue work before adding retries

Key Takeaways

  • 1Admit work against the capacity shared by interactive features and background jobs
  • 2Give queued requests a priority, expiry and owner before increasing worker counts
  • 3Classify error details before retrying; spend and quota failures need intervention
  • 4Use one retry policy with an attempt limit and a deadline for the whole operation

Your AI feature can leave an employee waiting while a background import competes for the same API capacity. Adding workers then gives you more callers without settling whose request should run next. AI API rate limits make that scheduling decision part of the product.

Before expanding retries, decide which work to admit, defer or stop. The policy below is our engineering recommendation for an application that shares capacity between interactive requests and background jobs. Its priorities and deadlines are choices for your team, separate from the provider rules cited here. For the underlying integration, start with our practical guide to using AI through an API.

Map the AI API rate limits your callers share

Ask the platform owner to inventory callers by provider, organization, project or workspace, model, and endpoint. Include scheduled imports, internal tools and retries. A queue cannot protect capacity it does not know other services are consuming.

According to OpenAI's rate-limit documentation, limits apply at organization and project level, vary by model, and can constrain requests or tokens. Some models share a limit. OpenAI also documents throttling caused by a rapid traffic increase, even below the ordinary request and token limits. Check the limits for the credentials and model you actually deploy.

Anthropic's rate-limit documentation describes organization limits and configurable workspace limits. For the Messages API, it measures requests, input tokens and output tokens separately. It also warns that short bursts can hit limits. A daily average therefore tells you little about whether a scheduled job can start alongside live traffic.

Use that map to define a shared dispatch budget for each applicable capacity pool. Coordinate it across application instances; a separate local counter in each worker cannot enforce an aggregate ceiling. Reconcile token estimates with observed usage, and leave headroom while those estimates are uncertain.

Give queued work a priority and an expiry

Consider an illustrative application with an employee drafting a customer reply while a document import runs in the background. The product owner should decide how long the employee can wait and whether the import may pause. Neither choice comes from the provider's quota table.

Use this decision table as a starting policy, then tune it against your service expectations:

Work arriving at the dispatcher Admit when Otherwise Decision owner
Interactive draft Capacity and remaining deadline allow a useful response Offer a bounded wait or a manual path Product owner
Background import Its allocation is available without consuming reserved interactive capacity Keep it queued until its expiry Workflow owner
Expired request A newly authorized request replaces it Stop and record expiry Workflow owner
Work blocked by spend or quota The responsible owner has restored access Suspend dispatch for the affected scope Account owner

Priority alone is insufficient: an uninterrupted stream of interactive work could starve the import. Give background work an explicit share or a scheduled window, then review its oldest waiting job. Conversely, do not admit unlimited work just because it can wait. Bound queue size and queued token demand, and reject or defer new submissions when that bound is reached.

Store a job identifier, enqueue time, expiry, priority and status. Tell the caller whether work is queued, running, completed or stopped. After the employee leaves the workflow, producing a late draft may have no value; the product owner should choose cancellation rather than let the queue make that decision accidentally.

Classify the failure before scheduling another attempt

An HTTP status alone is too coarse for the dispatcher's recovery decision. OpenAI's error guide lists temporary rate-limit responses alongside credit, spend and usage-limit failures under HTTP 429. OpenAI says those billing and quota failures need action before retrying. Record the structured error code and the affected scope.

For Claude, Anthropic documents a monthly tier spend-cap response that also uses 429 and rate_limit_error, but has no retry-after header. On the Messages API, error.details.error_code identifies it as enforced_spend_limit_reached. A missing header is therefore not permission to assume a temporary throttle.

Route a recognized temporary throttle back through the dispatcher. Reduce dispatch pressure for the affected pool and schedule eligible work later. Route a spend-cap failure to the account owner, suspending that scope until access resumes or an authorized change restores it. An unknown response should enter a diagnosable failure state with an alert; do not turn uncertainty into an unlimited retry loop.

Keep the distinction between admission and spending visible. Increasing an approved capacity allowance does not establish whether a workflow is worth running. Maintain its separate cost and loop boundaries using the approach in our AI agent cost-controls guide.

Put retries under a single policy owner

The integration owner should choose where retries happen. OpenAI documents automatic SDK retries for eligible responses, with behavior dependent on settings and version. Anthropic also documents automatic SDK retries and configurable retry settings. Inspect the installed client before adding a worker-level loop.

Count every attempt, including SDK attempts, against the same policy. Set an attempt ceiling and an overall deadline that includes queueing, execution and retry delays. A timeout on each attempt does not by itself enforce that overall deadline, as OpenAI's retry guidance explains.

For a classified temporary failure, follow a valid Retry-After when supplied; OpenAI describes it as a minimum delay. If it is absent or invalid, use exponential backoff with jitter within the operation's remaining budget. If the server's required delay exceeds that budget, stop or defer the operation; do not shorten the delay to fit the interface.

Preserve the job identifier across attempts and protect downstream writes against duplicates. A timeout does not prove that nothing happened. For the interface, use preview and acceptance states for streamed AI output to distinguish an arriving answer from a completed draft ready for review. Partial streaming output also needs explicit handling: Anthropic notes that an error can arrive after the initial successful HTTP response. Decide whether to discard, resume or present partial work before allowing another attempt.

Test the queue before increasing capacity

Ask the integration owner to exercise these scenarios in staging with simulated provider responses:

  • Start an import alongside interactive traffic; check both user waiting time and background progress.
  • Return a temporary throttle with a delay hint, then without one; verify pacing and eventual termination.
  • Return a spend-cap failure; verify suspension and notification of the account owner.
  • Cancel a waiting request; check that it is removed before dispatch.
  • Interrupt a response and repeat delivery of a result; check that downstream writes remain unique.

Measure queue age, end-to-end latency, attempts per job, expiry and rejection rates, and failures by structured category. Capture provider request identifiers for investigation without logging credentials or unnecessary prompt content.

This design fits deferrable work. A workflow with a strict response deadline may need immediate rejection or an approved manual alternative. A queue cannot guarantee provider availability, and adding another provider requires its own evaluation and data-handling approval. Account settings and endpoint behavior remain deployment-specific.

The useful capacity decision is whether admitted work can finish while it still matters. Have the product owner set the waiting policy and the integration owner run the staging checklist before increasing concurrency. If imports move to a batch service, carry that discipline into result handling with our guide to reconciling AI batch results before retrying failed requests.

Sources

  • OpenAI, 2026, Rate limits. Live documentation reviewed 19 November 2026.
  • OpenAI, 2026, Error codes. Live documentation reviewed 19 November 2026.
  • Anthropic, 2026, Rate limits. Live documentation reviewed 19 November 2026.
  • Anthropic, 2026, Claude API errors. Live documentation reviewed 19 November 2026.

Share this article

Need expert guidance?

Let's discuss how our experience can help solve your biggest challenges.