Skip to content

fix(llm): raise streaming timeout default#1464

Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
series-foresail-dyes
Open

fix(llm): raise streaming timeout default#1464
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
series-foresail-dyes

Conversation

@rosetta-livekit-bot
Copy link
Copy Markdown
Contributor

@rosetta-livekit-bot rosetta-livekit-bot Bot commented May 12, 2026

Summary

Fixes #5508.

The Anthropic LLM plugin used httpx.AsyncClient(timeout=5.0), which sets all httpx sub-timeouts — including the per-chunk SSE read timeout — to 5 seconds. Claude's adaptive-thinking phases routinely pause for 10–30 s before emitting the first content chunk, so the 5 s read timeout fires during normal usage and raises APIConnectionError, killing voice sessions mid-turn.

Changes

  • Default split timeout: httpx.Timeout(5.0, read=30.0) — connect stays at 5 s (genuine TCP failures surface fast) while the per-chunk read window is 30 s (covers standard thinking budgets with headroom).
  • New timeout constructor parameter: timeout: httpx.Timeout | None = None lets callers supply a custom timeout without constructing a whole anthropic.AsyncClient — e.g. httpx.Timeout(5.0, read=60.0) for extended thinking or very large contexts. Aligns with the pattern already used by the OpenAI plugin.
  • Six unit tests in tests/test_plugin_anthropic.py cover the default split, tight connect value, custom timeout pass-through, and client= precedence over timeout=.

Before / after

# Before — all sub-timeouts at 5 s, kills thinking phases
httpx.AsyncClient(timeout=5.0, ...)

# After — tight connect, generous read
httpx.AsyncClient(timeout=timeout or httpx.Timeout(5.0, read=30.0), ...)

Usage (new parameter)

# Default (30 s read) — sufficient for most models
llm = anthropic.LLM(model="claude-sonnet-4-6")

# Extended thinking or very large contexts
llm = anthropic.LLM(
    model="claude-opus-4-6",
    timeout=httpx.Timeout(5.0, read=60.0),
)

Test plan

  • uv run pytest tests/test_plugin_anthropic.py -v — 6/6 pass
  • uv run ruff check — no errors
  • uv run ruff format --check — no changes needed

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

🦋 Changeset detected

Latest commit: d09fdd5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread agents/src/types.ts
export const DEFAULT_SESSION_CONNECT_OPTIONS: ResolvedSessionConnectOptions = {
sttConnOptions: DEFAULT_API_CONNECT_OPTIONS,
llmConnOptions: DEFAULT_API_CONNECT_OPTIONS,
llmConnOptions: DEFAULT_LLM_API_CONNECT_OPTIONS,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 AgentSession still uses 10s LLM timeout base, defeating the PR's 30s default

The PR's stated intent is to raise the default LLM streaming request timeout to 30s. While DEFAULT_SESSION_CONNECT_OPTIONS.llmConnOptions at agents/src/types.ts:73 was updated to use DEFAULT_LLM_API_CONNECT_OPTIONS (30s), the actual resolution of session connect options in AgentSession constructor at agents/src/voice/agent_session.ts:324 still uses DEFAULT_API_CONNECT_OPTIONS (10s) as the base:

llmConnOptions: { ...DEFAULT_API_CONNECT_OPTIONS, ...connOptions?.llmConnOptions },

In the voice pipeline, agent.ts:428 passes activity.agentSession.connOptions.llmConnOptions to llm.chat(), which overrides the plugin-level default. So the LLM timeout in the primary voice pipeline path remains 10s, not 30s. The plugin-level defaults (DEFAULT_LLM_API_CONNECT_OPTIONS) only take effect when llm.chat() is called directly without connOptions.

Prompt for agents
In agents/src/voice/agent_session.ts line 324, the llmConnOptions base should use DEFAULT_LLM_API_CONNECT_OPTIONS instead of DEFAULT_API_CONNECT_OPTIONS. Import DEFAULT_LLM_API_CONNECT_OPTIONS from '../types.js' and change line 324 from:

  llmConnOptions: { ...DEFAULT_API_CONNECT_OPTIONS, ...connOptions?.llmConnOptions },

to:

  llmConnOptions: { ...DEFAULT_LLM_API_CONNECT_OPTIONS, ...connOptions?.llmConnOptions },

This ensures the voice pipeline (the primary code path for LLM calls) correctly uses the new 30s default timeout.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant