agents icon indicating copy to clipboard operation
agents copied to clipboard

in _ws_connect raise WSServerHandshakeError( aiohttp.client_exceptions.WSServerHandshakeError: 401

Open sarangmohod opened this issue 4 weeks ago • 8 comments

Bug Description

when i try to run agent.py file in dev it shows this kind of error

2025-11-07 13:50:16,282 - WARNING livekit.agents - failed to connect to livekit, retrying in 0s Traceback (most recent call last): File "/home/livekit/new_backend/livekit-voice-agent/.venv/lib/python3.10/site-packages/livekit/agents/worker.py", line 695, in _connection_task ws = await self._http_session.ws_connect( File "/home/livekit/new_backend/livekit-voice-agent/.venv/lib/python3.10/site-packages/aiohttp/client.py", line 1093, in _ws_connect raise WSServerHandshakeError( aiohttp.client_exceptions.WSServerHandshakeError: 401, message='Invalid response status', url='wss://demoproject-tdoekpst.livekit.cloud/agent'

Expected Behavior

when we run "uv run agent.py dev" it should connect to livekit cloud server

Reproduction Steps

1.follow steps to create agent using python quickstart 
2.created agent
3.then run using uv run agent.py dev
...
- Sample code snippet -
from dotenv import load_dotenv

from livekit import agents
from livekit.agents import AgentSession, Agent, RoomInputOptions
from livekit.plugins import noise_cancellation, silero
from livekit.plugins.turn_detector.multilingual import MultilingualModel

load_dotenv(".env.local")


class Assistant(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="""You are a helpful voice AI assistant.
            You eagerly assist users with their questions by providing information from your extensive knowledge.
            Your responses are concise, to the point, and without any complex formatting or punctuation including emojis, asterisks, or other symbols.
            You are curious, friendly, and have a sense of humor.""",
        )


async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        stt="assemblyai/universal-streaming:en",
        llm="openai/gpt-4.1-mini",
        tts="cartesia/sonic-3:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc",
        vad=silero.VAD.load(),
        turn_detection=MultilingualModel(),
    )

    await session.start(
        room=ctx.room,
        agent=Assistant(),
        room_input_options=RoomInputOptions(
            # For telephony applications, use `BVCTelephony` instead for best results
            noise_cancellation=noise_cancellation.BVC(), 
        ),
    )

    await session.generate_reply(
        instructions="Greet the user and offer your assistance."
    )


if __name__ == "__main__":
    agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))

Operating System

linux

Models Used

No response

Package Versions

livekit                                  1.0.18
livekit-agents                           1.2.18
livekit-api                              1.0.7
livekit-blingfire                        1.0.0
livekit-plugins-assemblyai               1.2.18
livekit-plugins-noise-cancellation       0.2.5
livekit-plugins-silero                   1.2.18
livekit-plugins-turn-detector            1.2.18
livekit-protocol                         1.0.8

Session/Room/Call IDs

No response

Proposed Solution


Additional Context

No response

Screenshots and Recordings

No response

sarangmohod avatar Nov 07 '25 09:11 sarangmohod