Discussions
WebSocket Connection Failures on Railway.app Deployment (Pipecat Integration)
Title:
WebSocket Connection Failures on Railway.app Deployment (Pipecat Integration)
Category:
Streaming API / Troubleshooting
Body:
Issue Summary
I'm experiencing persistent WebSocket disconnections (websocket is not connected anymore) when using HeyGen's Streaming API from a Railway.app deployment. The exact same code works perfectly on my local machine.
Environment Details
- Deployment Platform: Railway.app (cloud hosting)
- Framework: Pipecat (Python) with HeyGen integration
- Programming Language: Python 3.11
- Avatar: Using a custom avatar (tested with multiple different avatars - same issue)
- Quality Setting: Medium (also tested with Low - same issue)
Configuration
session_request = NewSessionRequest(
avatar_id="[CUSTOM_AVATAR_ID]",
quality="medium",
disable_idle_timeout=True, # As recommended by support
)
heygen = HeyGenVideoService(
api_key=os.getenv("HEYGEN_API_KEY"),
session=session,
session_request=session_request,
)
Symptoms
Local Development (macOS):
- ✅ HeyGen initializes successfully
- ✅ WebSocket connection stable
- ✅ Video streaming works perfectly
- ✅ Avatar responds to audio input
- ✅ No disconnections
Railway.app Production:
- ✅ HeyGen initializes (session created)
- ✅ Bot connects to Daily.co room
- ✅ OpenAI Realtime API works
- ❌ WebSocket immediately disconnects
- ❌ Constant
websocket is not connected anymoreerrors - ❌ No video output
Error Logs from Production
The bot subprocess shows hundreds of these errors:
2025-11-18 10:01:09.030 | DEBUG | pipecat.services.heygen.client:_ws_send:263 - <pipecat.services.heygen.client.HeyGenClient object at 0x7fbd6f3eaba0> websocket is not connected anymore.
2025-11-18 10:01:09.030 | DEBUG | pipecat.services.heygen.client:_ws_send:263 - <pipecat.services.heygen.client.HeyGenClient object at 0x7fbd6f3eaba0> websocket is not connected anymore.
[... repeated hundreds of times ...]
The WebSocket disconnects immediately after initialization and never recovers.
What I've Already Tried
- ✅ Verified all environment variables - API keys are correctly set on Railway
- ✅ Added
disable_idle_timeout=True- As recommended by support - ✅ Implemented retry logic - 3 attempts with exponential backoff
- ✅ Tested multiple avatars - Same issue with different avatar IDs
- ✅ Lowered quality setting - Tried
lowquality, same issue - ✅ Checked other services - OpenAI Realtime API and Daily.co work fine on Railway
- ✅ Confirmed HeyGen API accessible - Can successfully call list sessions endpoint from Railway
Network Details
What works on Railway:
- OpenAI WebSocket connections (Realtime API)
- Daily.co WebRTC connections
- Standard HTTPS API calls to HeyGen (e.g.,
v1/streaming.list)
What doesn't work:
- HeyGen WebSocket streaming connection
This suggests Railway's network can handle WebSockets in general, but something specific about HeyGen's WebSocket implementation or servers is incompatible.
Questions
-
Are Railway.app IP addresses being throttled or blocked by HeyGen's WebSocket servers?
-
Are there specific WebSocket connection parameters or headers required for cloud deployments?
-
Does HeyGen's streaming API have known compatibility issues with certain cloud providers?
-
Are there regional differences in HeyGen's WebSocket server stability? (Railway may use different data centers than my local ISP)
-
Should I implement a WebSocket proxy or use a different connection strategy for production deployments?
-
Are there any session states I should check for? (You mentioned checking for sessions stuck in "connecting," "connected," or "closing" states - how do I query this?)
Additional Context
- Repository: GitHub (private repository - can share code snippets if needed)
- Similar reports: Found general HeyGen instability issues on GitHub but no Railway-specific solutions
- Support recommendation: Post to developer forum for engineering team assistance
- Note: Happy to provide API key privately to HeyGen engineers for debugging if needed
What Would Help
- Guidance on Railway.app compatibility
- WebSocket debugging steps specific to cloud deployments
- Alternative configuration options for production environments
- Information about HeyGen's WebSocket infrastructure and requirements
Thank you for your help! This is blocking our production deployment. Happy to provide additional logs, network traces, or test configurations as needed.