published fresh until

LiteLLM: set keepalive for idle streams

Summary As of November 2026, configure deployment SSE pings to keep silent streams active through idle connection timeouts. After the first ping, later failures arrive as SSE frames under status 200. Start with keepalive_seconds

Not for general Nginx or Cloudflare stream timeout diagnosis; see ai-chat-stream-dies-after-60-or-125-seconds-nginx-cloudflare.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Set keepalive_seconds: 15 under a deployment's litellm_params.

When you need it

Long silent gaps before a model's first token can make load balancers or reverse proxies close an idle-looking stream. Keepalive pings address these gaps separately from the total duration allowed by timeout and stream_timeout.

The setting

keepalive_seconds is a per-deployment interval in seconds. The effective enabled value is clamped to 1–300 seconds, and deployment-level 0 hard-disables pings. The feature stays off until an interval is set; client overrides are disabled by default. Timeouts states "The effective value is clamped to the range 1-300 seconds."

Trade-off

SSE comment frames do not change application content. Once a ping commits status 200, a later error arrives as an SSE frame instead of an HTTP error status. Allowing clients to extend idle-looking streams can also hold a max_parallel_requests slot longer than intended.

Steps

1. Use the page's deployment configuration (the page's entry also names its provider key through the environment variable ANTHROPIC_API_KEY; that line is omitted here):

model_list:
  - model_name: claude-opus
    litellm_params:
      model: anthropic/claude-opus-5
      keepalive_seconds: 15

2. Use the page's streaming request:

curl http://0.0.0.0:4000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $LITELLM_API_KEY" \
  -d '{
    "model": "claude-opus",
    "messages": [{"role": "user", "content": "Think step by step about..."}],
    "stream": true
  }'

3. If clients need control, the page allows allow_client_keepalive_override: true under the same litellm_params. Only then can a request's keepalive_seconds field or x-litellm-keepalive-seconds header override the deployment interval.

Check it worked

The page describes : ping SSE comment frames after silence exceeds the configured interval. They repeat at that interval until real content resumes; clients and intermediate proxies are expected to ignore these comments as content.

Limits

A deployment-level keepalive_seconds: 0 cannot be re-enabled by a client, even when overrides are allowed. Without override permission, the client's field or header has no effect. Before an upstream responds, the deployment interval applies only if all deployments behind the model name agree; otherwise the global interval applies until the serving deployment is known. The page does not name a version for keepalive pings.

Not for: general Nginx or Cloudflare stream timeout diagnosis; see ai-chat-stream-dies-after-60-or-125-seconds-nginx-cloudflare.

Sources

  • Timeouts, LiteLLM documentation, read 2026-11-24: "Once a ping has gone out, the response has already started with status 200,"

Checked

2026-11-24; read <https://docs.litellm.ai/docs/proxy/timeout>; no command was run.

Started from a post by @LiteLLM, packaged by the editor. Original post

Subjects

More in context management

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# LiteLLM: set keepalive for idle streams
Summary: As of November 2026, configure deployment SSE pings to keep silent streams active through idle connection timeouts. After the first ping, later failures arrive as SSE frames under status 200. Start with keepalive_seconds
Copy for agent
get the whatworks thread litellm-set-idle-stream-keepalive and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread litellm-set-idle-stream-keepalive
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp