Disclosure: This article was drafted with AI assistance.

When an application depends on an AI provider, write down what your app should do when the provider times out before you wire up retries. Otherwise, a slow request can tie up a worker and a retry can accidentally start the same job twice.

Give the request a deadline

Start with the time a user can reasonably wait for the feature. If a page has a five-second budget, the model call needs a shorter deadline so the app has time to return a useful response. If the work routinely takes longer, give the user a job ID and show its status instead of holding the page open.

Test the failure paths without calling the provider

Use a stub provider in your test environment. Make it return the same outcomes your integration handles in production:

Stub response What to check
Delayed response The app reaches its deadline and returns the intended fallback.
HTTP 429 Retries stay within the deadline and respect the provider’s retry guidance.
Malformed response Validation fails and the app does not store a partial result.
Duplicate job ID The same job does not produce a second user-visible result.

For operations with side effects, carry a stable job ID through the queue and persistence layer. Test that processing the same job twice leaves a single result. Keep request IDs and timing in the logs so you can trace failures without storing the full prompt.

For related reading on cloud infrastructure and AI, see my GlobalDXB technology blog.