Getting this error while running the deepgram-flux...
# ask-ai
m
Getting this error while running the deepgram-flux model :
Copy code
aiohttp.client_exceptions.WSServerHandshakeError: 400, message='Invalid response status', 
url='<wss://api.deepgram.com/v2/listen?model=flux-general-en&sample_rate=16000&encoding=linear16&mip_opt_out=false&eot_timeout_ms=1000>'
here is the agentsession code:
Copy code
session = AgentSession(
        userdata=userdata,
        turn_detection="stt",
        vad=ctx.proc.userdata["vad"],
        min_interruption_duration=0.15,
        min_interruption_words=1,
        preemptive_generation=False,
        user_away_timeout=20.0,
        stt=deepgram.STTv2(
            model="flux-general",
            eot_timeout_ms=1000,
        ),
        llm=openai.LLM(
            model="gpt-4.1-mini",
            temperature=0.55,
            max_completion_tokens=150,
            parallel_tool_calls=True,
        ),
        tts=inworld.TTS(
            api_key=os.getenv("INWORLD_API_KEY"),
            model="inworld-tts-1.5-max",
            voice="Brian",
            speaking_rate=1.2,
            temperature=0.8,
        ),
    )
why is this happening? i have just created a new key and still the same error
t
Thanks for reaching out, Milind. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I see you're hitting a
WSServerHandshakeError: 400 Invalid response status
when connecting to Deepgram's Flux model using your AgentSession code, and that you already tried a new API key. Let's walk through the most likely causes and quick checks you can run to get this resolved. Summary of the most likely causes • Authentication failure (most common): the Deepgram key is missing, not loaded, or not sent correctly. • Wrong model name: the Flux model requires the specific name
flux-general-en
. • Network/proxy blocking WebSocket handshakes (corporate proxies, ZScaler, VPNs). • Extra/unsupported query parameters in the WebSocket URL. What to check and try (in order) 1. Confirm the API key is loaded and being sent ◦ Add a quick check to confirm your env var is present:
Copy code
from dotenv import load_dotenv
     import os

     load_dotenv()
     print("DEEPGRAM_API_KEY loaded:", "yes" if os.getenv("DEEPGRAM_API_KEY") else "no")
• If it prints "no", ensure
.env
is loaded before you read the key and that the key name matches. 1. Use the exact model name required ◦ Update your STT config to use:
Copy code
stt=deepgram.STTv2(model="flux-general-en", eot_timeout_ms=1000)
•
flux-general
is rejected;
flux-general-en
is the correct model name. 1. Test the WebSocket handshake manually ◦ A successful handshake returns HTTP 101. You can try a curl-style test to confirm:
Copy code
curl -i -N -H "Upgrade: websocket" \
       -H "Connection: Upgrade" \
       -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
       -H "Sec-WebSocket-Version: 13" \
       -H "Authorization: Token YOUR_DEEPGRAM_API_KEY" \
       "<wss://api.deepgram.com/v2/listen?model=flux-general-en&sample_rate=16000&encoding=linear16&eot_timeout_ms=1000>"
• Replace
YOUR_DEEPGRAM_API_KEY
. If you still get a 400 here, the issue is at the Deepgram handshake step (auth or params). 1. Reduce parameters to a minimal test ◦ Temporarily remove extra params and test:
Copy code
stt=deepgram.STTv2(model="flux-general-en")
• If that works, add one parameter at a time to find which param triggers rejection. 1. Check network/proxy interference ◦ Corporate proxies or deep packet inspection (ZScaler, other appliances) often break WebSocket handshakes. ◦ Try running the same script from a different network (home/mobile hotspot) to rule out proxy/firewall issues. 1. Ensure the plugin and env loading are correct ◦ Confirm Deepgram plugin is installed:
Copy code
pip install "livekit-agents[deepgram]"
• Confirm
load_dotenv()
runs before
os.getenv("DEEPGRAM_API_KEY")
. Debugging helpers to add • Print the full WebSocket URL the client is using (to confirm model/query string). • Print whether the DEEPGRAM key is present (see step 1). • Capture and share the exact server response headers if you can (curl -i helps). What to do if this persists • If the key is present, the model name is
flux-general-en
, you've tried minimal params, and you still get a 400 from the manual curl test — this is a rejection at the Deepgram server during the handshake (typically auth or parameter-related). • Since you've already tried a new key, re-check that the key has streaming/API permissions and that there's no accidental whitespace/newline when loading it from env. If you'd like, share: • The output of the DEEPGRAM_API_KEY loaded check, • The exact WebSocket URL your client prints, • Whether the manual curl attempt returned 101 or 400 and any response headers you see. I can then suggest the next targeted steps based on those results. Sources: Deepgram STT | LiveKit Documentation | Configure ZScaler proxy for LiveKit connections | LiveKit