I am running the example `python complex-agents/dr...
# ask-ai
p
I am running the example
python complex-agents/drive-thru/drivethru_agent.py dev
but it is complaining
Copy code
2025-10-17 17:27:01,152 - WARNING livekit.agents - failed to connect to livekit, retrying in 10s
Traceback (most recent call last):
  File "/Users/haoyu/Workspace/livekit-examples/python-agents-examples/venv/lib/python3.13/site-packages/livekit/agents/worker.py", line 656, in _connection_task
    ws = await self._http_session.ws_connect(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "/Users/haoyu/Workspace/livekit-examples/python-agents-examples/venv/lib/python3.13/site-packages/aiohttp/client.py", line 1100, in _ws_connect
    raise WSServerHandshakeError(
    ...<5 lines>...
    )
aiohttp.client_exceptions.WSServerHandshakeError: 401, message='Invalid response status', url='wss://test-n96ch9qz.livekit.cloud/agent'
t
Thanks for reaching out, Haoyu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error is related to an authentication issue when the agent tries to connect to the LiveKit server. Let’s work through this together with a few steps that usually help resolve it: 1. First, please make sure your
.env
file is located in the same directory as
drivethru_agent.py
and includes the following details:
Copy code
LIVEKIT_URL=wss://your-livekit-server.com
LIVEKIT_API_KEY=your-api-key
LIVEKIT_API_SECRET=your-api-secret
1. Double-check that your API key and secret are accurate and match what’s set up on your server. 2. Try generating a test token using the LiveKit CLI to verify your credentials work as expected:
Copy code
lk token create --api-key devkey --api-secret secret --join --room test-room --identity test-user --valid-for 1h
1. If you’re using a development server, please ensure it’s running with
livekit-server --dev
. 2. Also, confirm that your tokens haven’t expired and are properly signed. If you’re still experiencing issues after these steps, could you kindly let me know: • What type of LiveKit server setup you’re using (Cloud, self-hosted, or development mode)? • Whether you’re able to successfully create tokens using the CLI? I’m here to help, so feel free to share any details or questions you have! Sources: livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt_v2.py | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki | Authentication | LiveKit Docs | LiveKit Server Platform | livekit/livekit_composite | DeepWiki | realtime-agents/openai-realtime-drive-thru.py