25/11/2026

LLM APIs Don't Behave Like Normal REST APIs in Production: Handling Streaming, Timeouts, and Retries

Knowledge_seci_model

LLM APIs look like REST APIs. You send a POST request, you get a response, you parse some JSON. That mental model holds right up until you put an LLM API call into a real production path — behind a reverse proxy, behind an ingress controller, inside a service that other people depend on. Then it breaks in ways a normal CRUD endpoint never would: connections that stay open for a minute, responses that arrive one token at a time, and retries that quietly cost you money or duplicate side effects. This guide covers what's actually different, and what to configure before it bites you.

Why LLM API Calls Don't Fit the Normal REST Mental Model

A typical REST call to a database-backed API resolves in milliseconds to a couple of seconds, and the response arrives as one complete payload. An LLM API call is a different shape of request entirely. Time-to-first-token can be a few hundred milliseconds, but total completion time for a long generation can run to 30–60 seconds or more, and that time is spent streaming tokens back incrementally rather than waiting for one final blob.

That changes two things your infrastructure usually assumes: how long a connection is allowed to stay open, and whether anything in the path is allowed to buffer the response before the client sees it. Most reverse proxies, load balancers, and HTTP clients were tuned for short-lived request/response cycles, and their defaults quietly work against streaming.

Streaming Breaks Default Proxy and Load Balancer Timeouts

If you're proxying an LLM API call — your own backend streaming tokens to a browser, or a backend-to-backend call to a provider — two defaults will hurt you first: read timeouts that are too short for a long generation, and response buffering that defeats the point of streaming in the first place.

nginx buffers upstream responses by default, which means a client can sit waiting with nothing rendered until nginx's buffer fills or the upstream finishes, even though your server already sent the first token. Disabling buffering for the route that handles streaming completions fixes that:

location /api/chat/stream {
    proxy_buffering off;
    proxy_read_timeout 120s;
    proxy_send_timeout 120s;
}

A single response header has the same effect without touching the proxy config, if you control the upstream app instead:

X-Accel-Buffering: no

On Kubernetes, if you're fronting the service with ingress-nginx, the equivalent is a pair of annotations on the Ingress resource rather than a server block you edit directly:

metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "120"
    nginx.ingress.kubernetes.io/proxy-buffering: "off"

If you're on Traefik, the comparable setting lives in the entry point's transport configuration, not on the route itself:

entryPoints:
  websecure:
    transport:
      respondingTimeouts:
        readTimeout: 120s
        idleTimeout: 180s

And if you've moved to Gateway API, HTTPRoute has a dedicated timeouts field instead of overloading a generic annotation — which also makes the budget visible in the route spec itself rather than buried in proxy config:

rules:
  - backendRefs:
      - name: llm-gateway-svc
        port: 8080
    timeouts:
      request: 120s
      backendRequest: 90s

Diagram of a client request flowing through a reverse proxy and ingress controller to an LLM API, with buffering off and a coordinated timeout budget

Timeouts Disagree Across Layers Unless You Coordinate Them

The failure mode that's hardest to debug isn't "timeout too short" in isolation — it's that your HTTP client, your reverse proxy, your ingress controller, and the LLM provider all have independent timeout values, and whichever one is shortest wins silently. A client library with a 30-second default timeout will cut off a generation that the proxy was perfectly happy to keep streaming for another minute, and the error you see has nothing to do with the proxy you spent an hour tuning.

Treat this as one budget, not four separate settings:

  • Set the HTTP client timeout (in your backend code, not just the browser fetch) explicitly, and make it the largest number, since it's closest to the actual LLM call
  • Set proxy/ingress read timeouts a little higher than the client timeout, so the proxy never cuts the stream before your own code gives up
  • Treat the provider's documented maximum generation time (check the specific API's docs — this varies by model and is not safe to assume) as the floor your whole chain has to accommodate

Retries Are Not Safe by Default for LLM Calls

Retrying a failed request is routine for REST APIs: the call is usually idempotent, and a duplicate GET or PUT costs nothing extra. An LLM completion is neither cheap nor obviously idempotent. If a connection drops partway through a stream, you don't know how much of the response the client actually rendered, and a naive retry regenerates the entire response — and bills you for it — rather than resuming where it left off.

A production-safe retry policy for LLM calls is narrower than a typical API client's default:

  • Only retry on responses that indicate the request never reached the model — connection errors and 5xx from the provider, plus 429 after honoring the documented backoff
  • Don't retry after a partial stream failure without an explicit resume strategy; treat it as a failed response to the caller instead of silently re-sending
  • Use exponential backoff with jitter so a provider-side outage doesn't turn your retries into the thing that makes the outage worse
  • If your app has tool calls or function calling in the loop, make sure a retried request can't re-trigger a side effect (sending an email, writing a record) that the first, seemingly-failed attempt already completed

Monitor Latency Percentiles, Not Just Error Rate

A health check that only tracks error rate will look green while your users are sitting through 20-second waits. LLM latency has a long tail that a simple average hides completely, so p50 and p95 need to be tracked separately — and the two numbers you actually care about are different metrics, not one:

  • Time to first token (TTFT) — how long before anything starts rendering
  • Total completion time — how long until the full response is done

A request can have a fast TTFT and still run long if the generation itself is lengthy, and that's a normal, healthy pattern — not an incident. Dashboards that conflate the two end up paging someone for a slow model response that was never actually broken.

This is also where the infrastructure underneath the LLM call starts to matter as much as the call itself. Getting request-level latency into something like Prometheus — with the service actually instrumented to expose first-token and total-completion time as separate histograms — is what turns "the AI feature feels slow sometimes" into a number you can act on. Kubo runs standard Kubernetes underneath these services, which means the same Prometheus-based monitoring setup used for any other workload applies directly to your LLM gateway or proxy layer — no separate observability stack just because the backend happens to call an LLM API instead of a database.

Comparison of time to first token versus total completion time for an LLM API response, at p50 and p95

A Practical Checklist Before You Ship an LLM API Call to Production

  • Disable response buffering on every proxy hop between your backend and the client (proxy_buffering off or the ingress-controller equivalent)
  • Set read/send timeouts as one coordinated budget across client, proxy, and ingress — not four unrelated defaults
  • Restrict retries to connection errors, 5xx, and backed-off 429 — never a blind retry after a partial stream
  • Guard any tool-call or function-calling side effect against duplicate execution from a retry
  • Track time-to-first-token and total completion time as separate metrics, both at p50 and p95

The Plumbing Still Has to Live Somewhere

None of this is specific to one cloud or one LLM provider — it's what any team self-hosting an LLM-backed service in front of real traffic runs into. If you're already evaluating where that service runs, the same questions come up that come up for any self-hosted app: who owns the ingress layer, who sets up the monitoring stack, and whether switching providers later means rewriting your deployment too.

That's the gap Kubo is built to close — standard Kubernetes with the ingress, timeout, and monitoring configuration above already wired in, so you're not assembling it from scratch for one more service. It also means the AI backend isn't locked into one vendor's proxy conventions: the same cluster can run migrated from a classic Ingress to Gateway API if that's the direction your timeout and routing needs take you, on infrastructure you can run in the cloud or on-prem. Plans start at ¥8,800/month for a small service like this; see the full plan comparison if you're weighing what fits your traffic.