Vibe Coder · Unit 10: APIs · Lesson 13 of 13

Errors and retries

Engineers: API calls fail. Handle rate limits, timeouts and overloads so your users see a working product.

Read the short notes and pictures.Do everything inside a blue frame.

Designing for failure

Model APIs are busy services. Requests are sometimes rejected or slow. Whether the user notices depends on how you handle it: retry what is temporary, report what is permanent, and keep their input safe.

A 3D scene of coloured blocks and cards. Kinds of failure: rate limit, timeout, overload, bad request.
Rate limits, timeouts, overloads and bad requests.

Which errors to retry

Retry

Rate limited, overloaded, timed out. Use exponential backoff with jitter.

Do not retry

Invalid request, authentication failure. These need a code or config fix.

Cap it

A maximum number of attempts and a total time limit.

A 3D scene of coloured blocks and cards. Retry with backoff: 1 second, 2 seconds, 4 seconds, give up.
Wait longer between each retry.

What the user sees

  1. Keep their input

    Never clear the form on failure.

  2. Say what happened

    In plain words, with a retry button.

  3. Degrade gracefully

    The rest of the app keeps working.

  4. Alert yourself

    Log and monitor error rates.

ActivityBuild stepOne AI feature

Harden your AI feature

Add timeouts, backoff retries for temporary errors, a clear error state that keeps the user’s input, and logging. Test by simulating a rate limit and a timeout.

Done when

Your AI feature is implemented, structured, tooled, cached and resilient.

Keep these

  • Expect API failures.
  • Retry temporary errors with backoff.
  • Keep user input and fail clearly.