I'm trying out the Python Multimodal Voice Agent, ...
# ask-ai
f
I'm trying out the Python Multimodal Voice Agent, but I'm stuck due to a 401 error. Could you help me resolve this? What I did:
Copy code
git clone <https://github.com/livekit-examples/multimodal-agent-python.git>
cd multimodal-agent-python
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env.local
I filled in the
.env.local
file with the URL, API_KEY, and API_SECRET obtained from the LiveKit Web Console. I also ensured that the OPENAI_API_KEY is correctly set. When I run
python3 agent.py dev
, I get the following error:
Copy code
python agent.py dev
2025-02-13 16:12:08,612 - DEBUG asyncio - Using selector: EpollSelector
2025-02-13 16:12:08,613 - DEV  livekit.agents - Watching /home/noah/ghq/github.com/livekit-examples/multimodal-agent-python
2025-02-13 16:12:09,115 - DEBUG asyncio - Using selector: EpollSelector
2025-02-13 16:12:09,118 - INFO livekit.agents - starting worker {"version": "0.12.12", "rtc-version": "0.20.0"}
2025-02-13 16:12:09,433 - WARNING livekit.agents - failed to connect to livekit, retrying in 0s: 401, message='Invalid response status', url='<wss://my-first-ai-voice-agent-f84md5vr.livekit.cloud/agent>'
2025-02-13 16:12:09,476 - WARNING livekit.agents - failed to connect to livekit, retrying in 2s: 401, message='Invalid response status', 
...
I've double-checked the URL, API_KEY, and API_SECRET multiple times, and they are correct. Is there anything I might be missing? Could you provide any insights into possible causes of this issue? Any help would be greatly appreciated!
g
A 401 error typically indicates an authentication issue. Ensure that your API key and secret are correctly set in the
.env.local
file. According to LiveKit Docs, the access token must be JWT-based and signed with your API secret. Double-check that the token is generated correctly and not expired. Also, verify that the
LIVEKIT_URL
is correct and does not include any trailing paths like
/agent
. If the issue persists, try generating a new API key and secret from the LiveKit console, as sometimes keys may need refreshing. Additionally, ensure that your system clock is synchronized, as time discrepancies can affect token validation. Would you like more detailed troubleshooting steps? Sources: - LiveKit Authentication - LiveKit Slack Discussion šŸ‘ 1 button šŸ‘Ž 0 button šŸ’” Hint: Mention @millions-hair-24956 in the thread for followups.
f
@millions-hair-24956 I have checked the following: • I created a new API key and secret from the LiveKit console and updated the
.env.local
file, but the same error persists. • I have verified that the API_KEY/API_SECRET were copied correctly and that there are no expiration issues. • The LIVEKIT_URL was copied directly from the LiveKit Web Console and does not include any extra paths like
/agent
. • The system clock is accurate, with no discrepancies beyond a few seconds. Is it possible to receive a 401 error even when the authentication credentials are correct?
g
Yes, a 401 error can still occur even if the authentication credentials appear correct. According to LiveKit Slack Discussions, this can happen due to several reasons: 1. Environment Variables: Ensure that the
.env.local
file is correctly loaded. You can print the environment variables in your script to confirm they are being read correctly. 2. Token Generation: Verify that the token is generated with the correct permissions. The token should include the necessary grants for the actions you intend to perform, such as joining a room or publishing tracks. 3. Network Issues: Check for any network-related issues that might be affecting the connection to the LiveKit server. Sometimes, proxies or firewalls can interfere with the connection. 4. Server Configuration: Ensure that the LiveKit server is correctly configured to accept connections from your client. This includes checking any IP whitelisting or security settings. Would you like more detailed troubleshooting steps or a code snippet to verify the environment variables? Sources: - LiveKit Slack Discussion šŸ‘ 0 button šŸ‘Ž 0 button šŸ’” Hint: Mention @runllm in the thread for followups.
f
The issue was caused by my PC's clock being 5 minutes ahead of the actual time. After adjusting it to the correct time, the warning no longer appears.