white-fireman-9846
09/08/2025, 9:13 PMtall-airline-16756
09/08/2025, 9:14 PMtall-airline-16756
09/08/2025, 9:14 PMaiohttp.client_exceptions.WSServerHandshakeError: 401 usually means the WebSocket handshake didn’t go through because the authentication credentials weren’t quite right. Most often, this happens when the JSON Web Token (JWT) you’re using is either not generated correctly or doesn’t have the permissions it needs.
Here’s how you can fix it:
1. Make sure you’re creating a valid JWT with the right grants. For agent connections, your token needs to include the api.VideoGrants(agent=True) grant.
2. Try using this example to generate the token with the `livekit-server-sdk`:
from livekit import api
# Initialize AccessToken with your API key and secret
at = api.AccessToken(api_key="your-api-key", api_secret="your-api-secret")
# Add video grants for agent access
at.add_grant(api.VideoGrants(agent=True))
# Generate the JWT token
token = at.to_jwt()
1. Double-check that the API key and secret you’re using to create the token are correct and still active. You can always verify or regenerate them in your LiveKit project settings.
2. If your agent relies on environment variables, just confirm that LIVEKIT_API_KEY and LIVEKIT_API_SECRET are set up properly:
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
Once your JWT is generated properly and in use, connecting to wss://keestudio-2jxcbw0l.livekit.cloud/agent should work smoothly. If you hit any bumps along the way, feel free to reach out!
Sources: livekit-plugins/livekit-plugins-anam/livekit/plugins/anam/api.py | LiveKit CLI project management | LiveKit Docs | Protocol & WebRTC | livekit/livekit_composite | DeepWikiwhite-fireman-9846
09/08/2025, 9:17 PMtall-airline-16756
09/08/2025, 9:17 PMagent.py dev). Just make sure the JWT you generated is being used properly for authentication.
If your agent is set up to get the JWT from environment variables, don't forget to set it like this before running the agent:
export LIVEKIT_JWT=your_generated_jwt
Feel free to reach out if you want me to walk you through any part of this!white-fireman-9846
09/08/2025, 9:21 PMtall-airline-16756
09/08/2025, 9:22 PMAttributeError: partially initialized module 'livekit.api' has no attribute 'AccessToken', usually happens because your script file has the same name as a library it’s trying to use. For example, if your script is named jwt.py, it can clash with the jwt library that the livekit package relies on.
Here’s a simple way to fix it:
1. Rename your script from jwt.py to something like `generate_jwt.py`—anything that’s not just jwt.py.
2. Delete any jwt.pyc or similar compiled files in the same folder to keep things clean.
3. Try running your renamed script again to generate the JWT.
If you hit any more bumps or have questions, just let me know—I’m here to help!white-fireman-9846
09/08/2025, 9:24 PMtall-airline-16756
09/08/2025, 9:24 PMwhite-fireman-9846
09/08/2025, 9:26 PM