For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • BedrockAgent
      • CLI Tools
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions
      • LiveWire
      • MCP Gateway
      • PomBuilder
      • Prefabs
      • Search
      • SkillBase
      • Skills
      • SWAIGFunction
      • SWMLBuilder
      • SWMLService
      • WebService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
        • connect
        • dial
        • disconnect
        • execute
        • receive
        • run
        • send_message
        • unreceive
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • Chat
      • Compat
      • Datasphere
      • Fabric
      • Imported Numbers
      • Logs
      • Lookup
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSub
      • Queues
      • Recordings
      • Registry
      • RestClient
      • Short Codes
      • SignalWireRestError
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Examples
  • Manual connect/disconnect
  • Async context manager
RELAYRelayClient

connect

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

dial

Next
Built with

Establish a WebSocket connection to SignalWire RELAY and authenticate. This method connects to wss://<host>, sends a signalwire.connect authentication request, subscribes to the configured contexts, and starts the internal receive loop.

For most use cases, prefer run() which calls connect() internally and adds automatic reconnection. Use connect() directly only when you need manual control over the event loop or are using the async context manager.

By default, only one RelayClient connection is allowed per process. Calling connect() on a second instance without disconnecting the first raises RuntimeError. Set the RELAY_MAX_CONNECTIONS environment variable to allow multiple concurrent connections.

Parameters

None.

Returns

None

Examples

Manual connect/disconnect

1import asyncio
2from signalwire.relay import RelayClient
3
4client = RelayClient(
5 project="your-project-id",
6 token="your-api-token",
7 host="your-space.signalwire.com",
8 contexts=["default"],
9)
10
11async def main():
12 await client.connect()
13 # Connected and authenticated -- do work here
14 call = await client.dial(
15 devices=[[{"type": "phone", "params": {"to_number": "+15559876543", "from_number": "+15551234567"}}]]
16 )
17 await call.hangup()
18 await client.disconnect()
19
20asyncio.run(main())

Async context manager

1import asyncio
2from signalwire.relay import RelayClient
3
4client = RelayClient(
5 project="your-project-id",
6 token="your-api-token",
7 host="your-space.signalwire.com",
8 contexts=["default"],
9)
10
11async def main():
12 async with client:
13 call = await client.dial(
14 devices=[[{"type": "phone", "params": {"to_number": "+15559876543", "from_number": "+15551234567"}}]]
15 )
16 await call.hangup()
17
18asyncio.run(main())