How can I bump the timeout for this? livekit.agent...
# ask-ai
p
How can I bump the timeout for this? livekit.agents._exceptions.APIConnectionError: failed to generate LLM completion after 4 attempts (body=None, retryable=True)
t
Thanks for reaching out, Mario. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I see you're hitting an
APIConnectionError
after 4 retries when generating an LLM completion and want to bump the timeout. You can lengthen the per-request timeout and/or reduce retries using the
connOptions
passed into
AgentSession
. Below are concise examples and recommendations. Python
Copy code
from livekit.agents import AgentSession

session = AgentSession(
    llm="openai/gpt-4o-mini",
    stt="deepgram/nova-2",
    tts="cartesia/sonic-3",
    connOptions={
        "timeout": 30.0,     # seconds per request (increase from default)
        "max_retries": 2,    # reduce number of retries (optional)
    },
)
Node.js / TypeScript
Copy code
const session = new AgentSession({
    llm: "openai/gpt-4o-mini",
    stt: "deepgram/nova-2",
    tts: "cartesia/sonic-3",
    connOptions: {
        timeout: 30.0,      // seconds per request
        maxRetries: 2,      // number of retry attempts
    },
});
Recommendations • Start with
timeout: 30.0
seconds and
max_retries
(or
maxRetries
) set to 2. Tune up/down based on observed provider latency. • If your LLM provider sometimes has longer tail latencies, increase
timeout
rather than only increasing retries. • Verify your network and the LLM provider’s health if timeouts persist — long timeouts won't help if the endpoint is unreachable or rate-limited. If you’d like, tell me: • which language/runtime you’re using (Python or Node), • the current
timeout
and
max_retries
values if set, and I’ll suggest precise values and an example tailored to your setup. Sources: Agents (Python) | livekit/livekit_composite | DeepWiki
p
there is no connOptions
t
Thanks — I hear you: you tried the
connOptions
suggestion but
connOptions
isn’t present in your environment. I can help get this sorted. To diagnose why it’s missing and give a working alternative, I need a bit more info. Could you share the following? • Which language/runtime are you using (Python or Node)? • The exact
livekit-agents
package version (for Python run
pip show livekit-agents
, for Node run
npm ls livekit-agents
or check package.json). • The snippet where you create the AgentSession (or equivalent) and the full traceback/error you see when you try to pass
connOptions
. What I’ll look for after you send that: • If your SDK version is older,
connOptions
may not exist — I’ll give upgrade steps and a compatible example. • If you’re on a supported version but using a different constructor shape (e.g., passing model objects instead of plain strings), I’ll show the correct placement for connection settings. • If
connOptions
truly isn’t supported in your build, I’ll suggest alternative places to increase timeouts (for example, provider-specific client options or environment-level HTTP timeout settings) and give concrete code examples. Send the version and snippet and I’ll provide the exact fix or next steps. Sources: Agents (Python) | livekit/livekit_composite | DeepWiki