Anonymous Connection for AI Agents
Overview
TheanonymousLogin method allows you to connect to AI assistants without traditional authentication credentials. This is the first step in establishing communication with a Telnyx AI Agent.
Method Signature
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
targetId | String | Yes | - | The ID of your AI assistant |
targetType | String | No | ”ai_assistant” | The type of target |
targetVersionId | String? | No | nil | Optional version ID of the target. If not provided, uses latest version |
userVariables | [String: Any] | No | [:] | Optional user variables to include |
reconnection | Bool | No | false | Whether this is a reconnection attempt |
serverConfiguration | TxServerConfiguration | No | TxServerConfiguration() | Server configuration (signaling server URL and STUN/TURN servers) |
TxServerConfiguration Properties
| Property | Type | Description |
|---|---|---|
signalingServer | URL? | Custom signaling server URL (e.g., wss://your-server.com) |
webRTCIceServers | [RTCIceServer]? | Custom STUN/TURN servers for WebRTC connections |
Usage Example
Advanced Usage
With User Variables
With Version Control
With Custom Server Configuration
Important Notes
- Call Routing: After a successful anonymous connection, any subsequent call, regardless of the destination, will be directed to the specified AI Assistant
- Session Lock: The session becomes locked to the AI assistant until disconnection
- Version Control: If
targetVersionIdis not provided, the SDK will use the latest available version - Error Handling: Monitor delegate callbacks for authentication errors
- Server Configuration: You can customize:
- Signaling Server: Custom WebSocket server URL for SIP signaling (e.g.,
wss://your-server.com) - ICE Servers: Custom STUN/TURN servers for NAT traversal and media relay
- Signaling Server: Custom WebSocket server URL for SIP signaling (e.g.,
- Default Configuration: If no custom configuration is provided, the SDK uses Telnyx’s default servers
Delegate Response Handling
Listen for connection responses using the delegate methods:Error Handling
Common errors you might encounter:Next Steps
After successful anonymous connection:- Start a conversation using
newCall() - Set up transcript updates to receive real-time conversation data
- Send text messages during active calls