this is the error ``` raise WSServerHandshakeEr...
# ask-ai
b
this is the error
Copy code
raise WSServerHandshakeError(
aiohttp.client_exceptions.WSServerHandshakeError: 401, message='Invalid response status', url='<wss://voice-bot-914ffmrd.livekit.cloud/agent>'
2025-07-14 13:20:15,155 - livekit.agents - WARNING - failed to connect to livekit, retrying in 10s
t
Thanks for reaching out, Sahab. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
WSServerHandshakeError 401
indicates an authentication failure when connecting to your LiveKit cloud WebSocket endpoint. This is most commonly caused by one of the following: • Missing or incorrect API credentials (API key or secret) • Expired or improperly generated access tokens • Incorrectly formatted authorization headers To resolve this, please verify the following: Sources: Authentication | LiveKit Docs | livekit-agents/livekit/agents/worker.py | Accepting incoming calls | LiveKit Docs | Web and mobile frontends | LiveKit Docs
b
then how it is working on console model
t
Hey there! I totally get why this might be frustrating. The LiveKit Console makes things super smooth by handling all the authentication behind the scenes, which is why it seems to work like magic there. But when you're building your own client, you'll need to do a bit more of the heavy lifting. Think of it like this: the Console is basically doing the token handshake for you automatically, but in your custom setup, you'll need to generate a valid access token yourself. If something's off with the token - maybe it's missing, expired, or just not quite right - you'll see that pesky 401 error pop up. No worries, though! The fix is pretty straightforward. Just make sure you've got a server-side process that creates a proper JWT access token using your API key and secret. Then, when your client connects, just include that token, and you should be good to go. Want me to walk you through the steps? Sources: Authentication Examples | livekit/livekit_composite | DeepWiki | Connecting to LiveKit | LiveKit Docs | src/room/RegionUrlProvider.ts | client/web/.env.example | Next.js quickstart | LiveKit Docs | Web and mobile frontends | LiveKit Docs