Relay
Python API reference for RelayClient, Call, Message, and real-time events
The Relay namespace provides imperative, event-driven control over voice calls and SMS/MMS messages through a persistent WebSocket connection to SignalWire. While the Agents namespace handles AI-driven conversations declaratively via SWML, Relay gives you fine-grained, async control over every step of a call — answering, playing prompts, collecting digits, recording, bridging, conferencing, and more.
Relay uses the JSON-RPC 2.0 protocol over WebSocket (wss://). The client
authenticates once, subscribes to contexts for inbound events, and processes
call and message events in an async event loop. Automatic reconnection with
exponential backoff ensures resilience against transient network failures.
Context Routing
Contexts are routing labels that control which inbound calls and messages are delivered to your application. When you assign a phone number to a context in the SignalWire dashboard, all calls to that number are routed to Relay clients subscribed to that context.
A client only receives events for its subscribed contexts. This enables multiple applications or workers to handle different call flows on the same project by subscribing to different contexts.
Example
An IVR that answers calls, plays a menu, collects a digit, and routes accordingly: