WebSocket Endpoint
Endpoint:ws://your-domain.com/live-transcript/{call_sid}?token={api_key}
This WebSocket endpoint provides real-time streaming of call transcripts as they are generated. It’s designed for building live monitoring dashboards, call supervision tools, and accessibility features.
Path Parameters
call_sid
(string, required): The Twilio Call SID of the call you want to monitor
Authentication
Required: All connections must be authenticated using a valid API key. Methods Supported:-
Query Parameter (Recommended):
-
Authorization Header:
-
WebSocket Subprotocol:
Access Control
- Only users from the same organization as the call’s assistant can access the transcript stream
- API keys must have valid permissions and belong to an active user
- Invalid authentication results in immediate connection termination with code 1008
Connection Process
- Establish Connection: Connect to the WebSocket endpoint with a valid Call SID
- Receive Confirmation: Server sends a connection established message
- Get Historical Data: Receive any existing transcripts for the call
- Stream Live Data: Receive real-time transcripts as they’re generated
- Handle Status Updates: Receive call status changes (start, end, etc.)
Server-to-Client Messages
Connection Established
Transcript Data
content
: The transcribed textspeaker
:"user"
or"assistant"
is_final
: Whether this is a final transcriptconfidence
: Speech recognition confidence (0.0 - 1.0)segment_start
: Start time in seconds from call startsegment_end
: End time in seconds from call startcreated_at
: ISO timestamp of transcript creation
Call Status Updates
in-progress
: Call is activecompleted
: Call ended successfullyfailed
: Call failed or was terminated
Error Messages
Pong Response
Client-to-Server Messages
Ping (Health Check)
Send a ping to test connection health:pong
message
Request Status
Request the current call status:call_status
message
Features
Historical Transcripts
When connecting to an ongoing call, you’ll immediately receive all existing transcripts before new live data starts streaming.Multiple Connections
Multiple clients can connect to the same call simultaneously without performance impact.Automatic Cleanup
Connections are automatically cleaned up when:- Clients disconnect
- Calls end
- Connection errors occur
Error Handling
The server gracefully handles:- Invalid Call SIDs
- Connection timeouts
- Malformed messages
- Concurrent connection limits
Example Usage
JavaScript
Python
Error Codes
Code | Description |
---|---|
1000 | Normal closure |
1001 | Going away |
1002 | Protocol error |
1003 | Unsupported data |
1006 | Abnormal closure |
1008 | Authentication failed or access denied |
1011 | Server error |
Rate Limits
- Connections per Call: 10 concurrent connections maximum
- Messages per Second: 100 messages per connection
- Connection Duration: No limit (connections persist until call ends)
Best Practices
- Secure API Keys: Store API keys securely and never expose them in client-side code
- Implement Reconnection: Use exponential backoff for reconnection attempts
- Handle All Message Types: Process all message types to avoid missing important updates
- Validate Call SID: Ensure Call SID format is valid before connecting
- Use Ping/Pong: Regularly send pings to maintain connection health
- Error Handling: Always handle connection errors and authentication failures gracefully
- Use Query Parameters: Prefer query parameter authentication for simplicity
Security Considerations
- Validate Call SID ownership before connecting
- Implement rate limiting in production
- Use secure WebSocket connections (WSS) over HTTPS
- Consider implementing authentication tokens for sensitive deployments