It was connecting fine in console mode, but when I...
# ask-ai
b
It was connecting fine in console mode, but when I ran it in dev mode, the LiveKit connection didn’t work. 2025-11-06 142822,988 - WARNING livekit.agents - failed to connect to livekit, retrying in 0s Traceback (most recent call last): File "/Users/choiyunji/Developer/agent-starter-python/.venv/lib/python3.10/site-packages/livekit/agents/worker.py", line 695, in _connection_task ws = await self._http_session.ws_connect( File "/Users/choiyunji/Developer/agent-starter-python/.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://vmonster-voice-test-qmo3rxem.livekit.cloud/agent' 2025-11-06 142823,033 - WARNING livekit.agents - failed to connect to livekit, retrying in 2s
t
Thanks for reaching out, 최윤지. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! The error
WSServerHandshakeError 401
usually happens when the access token isn’t quite right. When you’re working in dev mode, LiveKit uses the default API key
devkey
and secret
secret
. To get things going smoothly, make sure you generate a valid token with these credentials. Here’s an example to guide you:
Copy code
lk token create \
  --api-key devkey --api-secret secret \
  --join --room my-room --identity user1 \
  --valid-for 24h
Once you have your token, include it in the WebSocket connection request under the
Authorization: Bearer JWT
header. Also, double-check that your LiveKit server is running with
livekit-server --dev
. Some common reasons this error pops up are: • Using the wrong API key or secret • Token has expired • The JWT token is malformed • Missing or incorrect
Authorization
header If you’d like, I’m here to help you troubleshoot further—just let me know! Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | README.md | Running LiveKit locally | LiveKit Docs