Timeouts bound how long one call can block. A circuit breaker opens after repeated failures, so you stop sending doomed requests and give the provider and your own queue room to recover.
Time-to-first-token timeouts for LLM latency
LLM latency is unpredictable and long-tailed: a single generation can take tens of seconds. A tight whole-call timeout fails healthy requests, and a 2-second limit, the kind that suits a typical microservice, would fail most healthy calls.
Stream the response and put a timeout on the time to the first token. You see initial output quickly, the user stays informed, and a model that stalls is handled without tying up resources. Also cap the total token budget per request, which limits both cost and time for one call.
Breaker states: closed, open and half-open
Libraries such as resilience4j (Java) or Polly (.NET) implement the breaker. Netflix Hystrix is an older equivalent that is no longer in active development.
- The breaker counts failures over a time window.
- When failures pass the threshold, it opens: requests stop going to the failing service and go to a fallback.
- During the cooldown, the upstream service has time to recover.
- The breaker goes half-open and lets a limited number of requests through to probe.
- If the probes succeed, it closes. If not, it opens again.
The fallback is whatever alternative path you define for requests while the breaker is open.
Retry storms during a provider brownout
Without a breaker, your application keeps sending requests to a degraded provider. In-flight requests pile up, the worker pool is exhausted, and the failure spreads through your own service until it cannot handle legitimate traffic.
Failing fast with a cooldown stops that. You refuse the doomed requests yourself and keep serving what you can.
Tuning timeouts for interactive and batch work
- Put a breaker on every external model dependency.
- For interactive use, tighten the time-to-first-token timeout so users get quick feedback.
- For batch or offline jobs, relax the total time limit, since responsiveness matters less.
The result is bounded latency and no thread-pool exhaustion, and the system can recover from provider failures without a person stepping in.
Timeout errors that the breaker did not stop
Example scenario: timeout errors rise 50% in an hour, hitting 200 requests per minute (illustrative). The provider is slow or down, and the breaker is not tripping because its thresholds are misconfigured.
- Check API response times and error rates for the last hour.
- Review the breaker's timeout and failure thresholds.
- Look in the logs for patterns in failures or latency spikes.
Make the breaker trip sooner on repeated failures. The tradeoff is that it may reject valid requests during a brief outage. Watch response times and error rates to confirm the change.