5-08-22 11:13:23,973 - DEBUG - Using proactor: Ioc...
# ask-ai
e
025-08-22 111323,973 - DEBUG - Using proactor: IocpProactor 2025-08-22 111323,973 - DEBUG asyncio - Using proactor: IocpProactor 2025-08-22 111323,973 - INFO - starting worker 2025-08-22 111323,973 - INFO livekit.agents - starting worker {"version": "1.2.6", "rtc-version": "1.0.12"} 2025-08-22 111324,259 - WARNING - failed to connect to livekit, retrying in 0s Traceback (most recent call last): File "D:\Bigagent\venv\Lib\site-packages\livekit\agents\worker.py", line 649, in _connection_task ws = await self._http_session.ws_connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\aiohttp\client.py", line 1084, in _ws_connect raise WSServerHandshakeError( aiohttp.client_exceptions.WSServerHandshakeError: 401, message='Invalid response status', url='wss://utkarshpc-9jcqjqam.livekit.cloud/agent' 2025-08-22 111324,259 - WARNING livekit.agents - failed to connect to livekit, retrying in 0s Traceback (most recent call last): File "D:\Bigagent\venv\Lib\site-packages\livekit\agents\worker.py", line 649, in _connection_task ws = await self._http_session.ws_connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\aiohttp\client.py", line 1084, in _ws_connect raise WSServerHandshakeError( aiohttp.client_exceptions.WSServerHandshakeError: 401, message='Invalid response status', url='wss://utkarshpc-9jcqjqam.livekit.cloud/agent' 2025-08-22 111324,318 - WARNING - failed to connect to livekit, retrying in 2s Traceback (most recent call last): File "D:\Bigagent\venv\Lib\site-packages\livekit\agents\worker.py", line 649, in _connection_task ws = await self._http_session.ws_connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --------------------------- this just popup in the console out of blue. same code, same version is running in my another device without any error. i haven't change any env, anything in the code.
t
Thanks for reaching out, Utkarsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the WebSocket server handshake didn’t go through because the request wasn’t authorized (HTTP status code 401). This usually means the connection is missing a valid access token, or the token you’re using might be invalid, expired, or not quite right. Here are a few things you can try to fix this: • Make sure you’re sending a valid access token when you try to connect. • Check that the token hasn’t expired and has the right permissions for what you’re trying to access. • Double-check that the token is formatted correctly and included properly in your connection request. If you’re still running into trouble, take another look at the connection URL to be sure it matches what your LiveKit setup expects. Sources: livekit-api/src/signal_client/mod.rs | protobufs/livekit_sip.proto | livekit-api/livekit/api/twirp_client.py
e
ebug this, everthing is fine env is correct, the same code is running fine in another device. so what could be the potenstial issue025-08-22 144530,926 - INFO livekit.agents - registered worker {"id": "AW_nX8eoKZzjwXv", "url": "wss://utkarshpc-9jcqjqam.livekit.cloud", "region": "India", "protocol": 16} 2025-08-22 144602,979 - INFO - received job request 2025-08-22 144602,979 - INFO livekit.agents - received job request {"job_id": "AJ_Hc6awiCTE37H", "dispatch_id": "", "room_name": "*", "agent_name": "bigship-outbound-caller", "resuming": false} 2025-08-22 144603,061 - INFO - initializing job runner 2025-08-22 144603,061 - INFO livekit.agents - initializing job runner {"tid": 20468} 2025-08-22 144603,062 - INFO - Prewarming models... 2025-08-22 144603,062 - INFO __mp_main__ - Prewarming models... 2025-08-22 144603,161 - INFO - Silero VAD model prewarmed successfully. 2025-08-22 144603,161 - INFO __mp_main__ - Silero VAD model prewarmed successfully. 2025-08-22 144603,162 - INFO - job runner initialized 2025-08-22 144603,162 - INFO livekit.agents - job runner initialized {"tid": 20468, "elapsed_time": 0.1} 2025-08-22 144603,162 - DEBUG - Using proactor: IocpProactor 2025-08-22 144603,162 - DEBUG asyncio - Using proactor: IocpProactor 2025-08-22 144604,801 - INFO - Agent connected to room: *, job_id: AJ_Hc6awiCTE37H, call_id: 4ad4aed8-3363-4e00-b874-9252ff0baf7b 2025-08-22 144604,801 - INFO __mp_main__ - Agent connected to room: *, job_id: AJ_Hc6awiCTE37H, call_id: 4ad4aed8-3363-4e00-b874-9252ff0baf7b 2025-08-22 144604,962 - INFO - Placing outbound call to: +918439592468 2025-08-22 144604,962 - INFO __mp_main__ - Placing outbound call to: +918439592468 2025-08-22 144604,963 - DEBUG - http_session(): creating a new httpclient ctx 2025-08-22 144604,963 - DEBUG livekit.agents - http_session(): creating a new httpclient ctx 2025-08-22 144605,174 - ERROR - unhandled exception while running the job task Traceback (most recent call last): File "D:\Bigagent\venv\Lib\site-packages\opentelemetry\util\_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\livekit\agents\ipc\job_proc_lazy_main.py", line 240, in _traceable_entrypoint await self._job_entrypoint_fnc(job_ctx) File "D:\Bigagent\uniid.py", line 258, in entrypoint await ctx.api.sip.create_sip_participant(api.CreateSIPParticipantRequest( File "D:\Bigagent\venv\Lib\site-packages\livekit\api\sip_service.py", line 416, in create_sip_participant return await self._client.request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\livekit\api\twirp_client.py", line 128, in request error_data = await resp.json() ^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\aiohttp\client_reqrep.py", line 749, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 401, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url='https://utkarshpc-9jcqjqam.livekit.cloud/twirp/livekit.SIP/CreateSIPParticipant' 2025-08-22 144605,174 - ERROR livekit.agents - unhandled exception while running the job task Traceback (most recent call last): File "D:\Bigagent\venv\Lib\site-packages\opentelemetry\util\_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\livekit\agents\ipc\job_proc_lazy_main.py", line 240, in _traceable_entrypoint await self._job_entrypoint_fnc(job_ctx) File "D:\Bigagent\uniid.py", line 258, in entrypoint await ctx.api.sip.create_sip_participant(api.CreateSIPParticipantRequest( File "D:\Bigagent\venv\Lib\site-packages\livekit\api\sip_service.py", line 416, in create_sip_participant return await self._client.request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\livekit\api\twirp_client.py", line 128, in request error_data = await resp.json() ^^^^^^^^^^^^^^^^^ File "D:\Bigagent\venv\Lib\site-packages\aiohttp\client_reqrep.py", line 749, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 401, message='Attempt to decode JSON with unexpected mimetype: text/plain; charset=utf-8', url='https://utkarshpc-9jcqjqam.livekit.cloud/twirp/livekit.SIP/CreateSIPParticipant'
t
Hey there! It looks like the error is happening because the API call wasn’t authorized (HTTP 401), and the response came back in a format we didn’t expect (text/plain instead of JSON). This usually means: • Your authentication credentials (like API keys or tokens) might be missing, invalid, or expired. • There might be a mix-up with the API endpoint or headers. Here’s what you can try to fix it: 1. Double-check that your API keys or tokens are correctly set up and still valid. 2. Make sure the API endpoint and headers, especially the authorization header, are configured just right. 3. Verify that all the necessary environment variables (like
LIVEKIT_API_KEY
and
LIVEKIT_API_SECRET
) are properly set. 4. In your code, try handling different response types by checking the content type before you decode JSON. If you’re still running into trouble, just let me know which LiveKit component or plugin is causing this error, and I’ll be happy to help you troubleshoot further! Sources: protocol/unity_proto/UnityAPI.twirp.go | livekit-plugins/livekit-plugins-assemblyai/livekit/plugins/assemblyai/stt.p...