Back to Automation

How Do You Handle Errors and Rate Limits?

How Do You Handle Errors and Rate Limits?
AI Tutorials Team 29 April 2026

API calls fail: rate limits, timeouts, overload, transient network problems. Anything running unattended needs to expect that rather than treating it as exceptional.

What are the common failures?

  • Rate limits. Too many requests too quickly.
  • Overload. The provider is busy.
  • Timeouts. Particularly on long generations.
  • Invalid requests. Malformed or too large.
  • Authentication. Expired or revoked keys.

Which should you retry?

Transient ones: rate limits, overload and timeouts. A malformed request will fail identically however many times you send it, and retrying it wastes calls and obscures the actual problem.

What is exponential backoff?

Waiting longer between each retry rather than hammering immediately. That gives the limit time to reset and prevents your retries from compounding the congestion you are responding to.

What is jitter and why does it matter?

Adding randomness to the wait, so that many clients retrying do not synchronise. Without it, everything retries at the same moment and the problem repeats.

How are rate limits usually structured?

As requests per minute and tokens per minute, separately. Hitting the token limit while well under the request limit is common and confusing if you only watched one.

What about failures at the provider?

They happen, they are total while they last, and they are outside your control. An application with no fallback simply stops working, which is acceptable for some things and not for others.

Falling back to a second provider is genuine insurance and real work, since prompts and behaviour differ. For most applications, failing clearly and queuing for later is the proportionate response.

How do you raise them?

Usually through usage tiers that increase automatically with spend, or by request. Planning around current limits is more reliable than assuming an increase will arrive when needed.

What about telling the user?

Better than silence. A message saying the service is busy and to try shortly is more useful than a generic failure, and it prevents the user repeating the request and compounding the load.

Where you can queue the work and notify later, that is better still. Failing gracefully is a design decision rather than an afterthought, and it is what distinguishes an application that handles a bad afternoon from one that appears broken.

What should happen when retries are exhausted?

Something graceful. Queuing for later, falling back to a smaller model, or telling the user clearly are all better than an unexplained failure or a silent gap.

What about timeouts?

Set them deliberately, and longer than you think for capable models on hard tasks. A timeout shorter than the generation takes produces failures that look like provider problems.

What should you do about repeated failures?

Stop trying, and say so. An application that keeps retrying indefinitely turns an outage into an expensive one and denies the user any information about what is happening.

A circuit breaker is the standard pattern: after several consecutive failures, stop attempting for a period and fail immediately instead. That protects your budget, reduces load on a struggling provider, and produces a clearer experience than an endless wait.

What about failures you should not retry?

Worth distinguishing carefully, because retrying the wrong thing wastes money and hides the problem. A malformed request, an oversized input or a revoked key will fail identically however many times you send it.

Those need a different response: log clearly, alert somebody, and stop. An application that retries everything three times turns a configuration error into a slow, expensive failure rather than an obvious one.

What should you log?

The error type, the request identifier and what you did about it. Providers include identifiers in responses, and having them is what makes a support conversation productive.

What is the minimum?

Retry transient failures with backoff and jitter, cap the attempts, and fail visibly. That handles the great majority of what goes wrong in practice.