Skip to content

Stream timeouts

Last updated: 2026-11-27T12:02:53-03:00 (UTC-3)

Bound a streaming operation without cutting a healthy answer at the ordinary request timeout. The stream_timeouts flag is disabled by default. Enable it explicitly; otherwise streaming keeps the existing request_timeout deadline and these four clocks are inactive.

Clock Default Allowed
First byte 60s 100ms–30m
Idle 120s 0s–30m
Maximum 30m 1s–24h
Client write 60s 100ms–30m
  • First byte (network.stream_first_byte_timeout): each attempt’s response headers to its first body byte. The response-header timeout remains separate.
  • Idle (network.stream_idle_timeout): a blocked read waiting for the provider’s next byte. 0s disables this clock. Keepalive comments count as traffic; time blocked writing to the client does not.
  • Maximum (network.stream_max_duration): the whole streaming operation, including queues, permitted attempts and response consumption. Retries do not receive a fresh duration budget.
  • Client write (network.client_write_stall_timeout): a downstream write and flush. A client that stops reading must release the operation’s resources. With stream_settle_on_disconnect the gateway stops writing and reads the provider’s answer to its end, still bounded by the idle and maximum clocks.

The maximum starts at the provider-operation boundary, after bounded input parsing and preflight; it is not an upload or whole-listener deadline. The caller’s earlier deadline or cancellation still wins. HTTP headers, upload/admission, async jobs and Realtime/WebSocket sessions retain their separate controls. Buffered answers and internal calls that return JSON still use the ordinary request deadline; being called by a stream does not turn them into streams.

Cached SSE replay has no provider first-byte or read-idle clock. With stream clocks enabled, its replay uses the applicable maximum and downstream write bound. Cache lookup and embedding preparation retain their existing deadline policy; cache attribution stays separate from newly billed provider usage. A semantic lookup may call its configured embedding model: a hit avoids a new generation, not necessarily every provider operation. The enabled request-timeout header is validated on a cache hit too.

A timeout before any downstream bytes follows the route’s existing fallback policy. It does not enable retries for routes that prohibit them. After streaming starts, the gateway never replays the request or fabricates a successful terminal event. An incomplete usage proof remains unknown under the quota and receipt contracts.

A load balancer or proxy between the client and the gateway usually closes a connection that carries no bytes for some time (60 seconds is a common default). A reasoning model can think longer than that before its first token, or between two parts of an answer, and the client then loses a stream that was still working. The gateway can send an SSE comment to the client while the provider is silent:

network:
client_keepalive_interval: 15s # off when empty or 0s (the default)
Parameter Default Accepted values When it applies
network.client_keepalive_interval empty: off empty or 0s (off), 1s to 5m At startup; restart each replica

After the interval passes with nothing written to the client, the gateway writes this comment and flushes it:

: keepalive

A line that starts with a colon is a comment in the SSE format: parsers ignore it, and the blank line after it dispatches nothing, so the official OpenAI, Anthropic and Gemini SDKs and browser EventSource see no event. What it does and does not do:

  • It applies to every successful (200) text/event-stream answer on the inference API (/v1/* and /v1beta/*): Chat Completions, Responses, Messages, streamGenerateContent and translated streams alike, never to the console, the admin API, JSON answers or errors.
  • It starts when the gateway sends the client its response headers, which is when the provider’s response starts. With keepalive on, a streamed answer’s headers go out at once instead of with its first event, so the comment also covers the silence before the first token. A consequence for translated streams (Messages, Responses or Gemini clients on another provider): a stream that ends before its first byte now reaches the client as a 200 stream with an SSE error event, instead of a 502 JSON error, because the status is already sent. The wait for the provider’s own response headers (network.response_header_timeout), and the wait for a first byte held for a retry policy, happen before that and are not covered.
  • It is written only between events: before the first byte, or after the blank line that ends an event. If the provider stops in the middle of an event, no comment is written until that event ends, so a line or an event is never split.
  • Each write of the answer restarts the interval, so a busy stream gets no comments.
  • It is written under everything else the gateway does with the stream: usage metering, budgets and TPM, the stream usage filter, the answer cache, translation, content capture, request logs and the time to first byte never see it. It does not reset the provider-side clocks above: a provider silent beyond stream_idle_timeout still ends the stream.
  • It stops when the answer ends, before the request is recorded, and when the client goes away. A comment blocked by a client that stopped reading fails with the stream’s next write deadline (client_write_stall_timeout, with stream clocks on); one still blocked when the request ends is abandoned after one second.

Why it is off by default. The comment is valid SSE, but it changes the bytes the client receives: a hand-written client that treats every block as JSON would fail on it. Turn it on when a load balancer in the path has an idle timeout shorter than your longest silence, and set the interval well below that timeout (for example 15s for a 60-second idle timeout). Raising the load balancer’s idle timeout is the alternative.

Inspect it. Settings & sources → Infrastructure → Inference HTTP and GET /api/v1/admin/config (infrastructure.inference_http.client_keepalive) show the applied interval and its source.

Upgrade. Nothing changes until you set the interval. Before rolling back to an older binary, remove network.client_keepalive_interval, because its strict YAML refuses it.

features:
stream_timeouts: true
request_timeout_header: true
# Requires the console and PostgreSQL, in addition to stream_timeouts:
stream_timeout_management: true
network:
request_timeout: 120s
stream_first_byte_timeout: 60s
stream_idle_timeout: 120s
stream_max_duration: 30m
client_write_stall_timeout: 60s

The four network values use their defaults when omitted. A model can override individual clocks with models[].stream_timeouts, using first_byte, idle, max_duration and write_stall. An empty field inherits the effective network value; explicit idle: "0s" disables idle detection for that model. Clock configuration is retained but inactive when stream_timeouts is off. The existing versioned Model catalog editor/API owns model overrides.

The independent flag request_timeout_header is enabled in the base profile. With it enabled, X-Gateway-Timeout-Ms accepts a whole number from 1 to 86400000. It can only lower the buffered/legacy deadline or the four enabled stream ceilings, never extend them. It also bounds an idle clock otherwise disabled with 0s. Invalid values return 400; when the flag is disabled the header is ignored, valid or invalid. The gateway does not forward this control header to the provider.

Enable stream_timeout_management to edit the network clocks in Providers → Resilience. It defaults off and requires stream_timeouts, the console and PostgreSQL. It does not enable the separate relay-admission feature or resize its boot limits.

  • GET /api/v1/admin/stream-timeouts requires resilience:read: returns the global version, optional override, four effective values and their sources.
  • PUT /api/v1/admin/stream-timeouts requires resilience:manage: send version plus stream_timeouts with at least one clock. Empty fields inherit YAML/default values.
  • DELETE /api/v1/admin/stream-timeouts requires resilience:manage: send version only. It removes the override and restores YAML/default values; no override returns 404.

Mutation JSON uses exact field names: version and stream_timeouts for PUT, and only version for DELETE. Case aliases, duplicate fields, null required values and trailing JSON are rejected before a configuration change; version 0 and explicit idle "0s" remain valid.

Writes require the same-origin signed session and CSRF token, and record actor and request ID in the administrative audit. Team roles cannot read or edit global clocks. API access supplies complete examples with the current configuration version; the OpenAPI is the request/response contract.

The precedence for each network clock is default → YAML → console override; a model override then wins for its stream. API and console report the effective network values and default, yaml or console source. When the parent flag is off, Infrastructure shows Disabled and inactive values are null, with an empty source map. Missing or malformed active data is not shown as a default.

Each operation keeps the snapshot it began with. Edits synchronize across replicas and affect new operations after their configuration refresh; an existing stream keeps its previous clocks. A stale version returns 409 and preserves the draft for review. If a write committed but refresh failed, read the current state before retrying; do not assume 503 means the write was rolled back.

Use request_id and trace_id in Request logs, structured logs and OTLP. timeout_kind identifies the clock that ended the operation: first_byte, idle, max_duration, client_stall, request, or attempt when the last provider attempt exceeded the alias’s attempt timeout and no target was left. Empty means no timeout was established. A failed attempt followed by a successful fallback does not turn the successful operation into a timeout; inspect its child attempt for the earlier failure. Historical timeout values remain readable under the same permissions after a flag is disabled.

Before headers, administrative stop remains 503 gateway_panic and client cancellation remains 499. Neither becomes a provider timeout. After headers, wire and recorded status preserve what was already sent, often 200, including interrupted delivery; inspect termination, timeout kind, usage coverage and receipt state rather than status alone. A timeout label does not prove that a provider charged or authorize releasing an unknown financial reservation.

  1. Choose clocks for the provider/model and the caller’s deadlines; keep load balancer, ingress and orchestrator limits compatible with the expected stream lifetime.
  2. Enable the parent flag, and optionally the runtime editor. Check effective values and sources in Infrastructure; admission sizes still require rollout.
  3. Verify a successful stream, a silent provider, keepalives and a client that stops reading in an isolated environment. Check IDs and resource release after cancellation.
  4. Change one clock and confirm the old stream keeps its snapshot while a new stream sees the new value on each replica. Test viewer denial, stale-version conflict and revert.
  5. On rollback, revert the override/flags and verify new operations. Reverting clocks does not replay requests or change already-running operations.

The parameter registry supplies the existing four network-clock defaults and bounds and the four model-clock inheritance rules to Go validation, default resolution and trusted console constraints. Clock text retains its existing 16-byte UTF-8 limit. Idle zero remains an actual off switch; an empty model clock inherits the effective network clock.

These definitions do not start a clock, change the parent or management flags, or grant editing permission. YAML changes need a rollout. The existing versioned runtime editor affects new operations after refresh, while each admitted operation keeps its snapshot.

m7gtwcontact@m7gtw.com