Agent Wranglers

API-35Required

Set timeouts on every call

Give every outgoing and incoming request a time limit. Never wait forever on another service.

How to do it

Set a connect timeout and a total timeout on each HTTP client, database and queue call. Set each limit to about twice that call's 99th percentile time. Without measurements yet, start at 1 second to connect and 3 seconds in total. Make each inner limit shorter than the outer one, so the caller gets a clear 503 or 504 problem. The database query is shortest, then the server's request, then the screen's, as in query time limits and screen request time limits. Model calls follow model timeouts.

Examples

JavaScript example

const response = await fetch('https://stock.example.com/items/TEA-01', { signal: AbortSignal.timeout(3000) })

Python example

import httpx

response = httpx.get("https://stock.example.com/items/TEA-01", timeout=httpx.Timeout(3.0, connect=1.0))

How to check

Point a staging dependency at a server that accepts connections and never answers. The request fails within the set limit with a 504 or 503 problem.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/reliability/timeouts">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.