How the integration works
Call flowPlivo SIP Trunking · xAI
- CallerDials your Plivo phone number
- Plivo inbound SIP trunkPrimary URI: sip.voice.x.aiSIP over TLS
- xAIChecks Plivo’s IP address or SIP digest credentials, then matches the dialed number
- xAI Voice AgentAnswers with its welcome message
Inbound only: xAI Voice Agents answer incoming calls. They don’t place outbound calls. See Outbound calls.
Prerequisites
For the code samples, you also need:
- Your Plivo Auth ID and Auth Token, available on the Plivo Console home page. The Plivo API uses HTTP Basic authentication.
- An xAI API key, created on the API Keys page of the xAI Console. The xAI API uses Bearer authentication.
- The Plivo CLI, logged in with
plivo login. The CLI uses the profile saved byplivo login, not the environment variables below.
Inbound calls
Set up the agent in xAI, route your Plivo number to xAI, and then connect the number to the agent.Create a voice agent in the xAI Console
Create the agent in the xAI Console. xAI doesn’t provide APIs to create or manage voice agents.
- Sign in to the xAI Console and select Voice Agents in the left navigation.
- Select Create agent. A builder chat asks about your use case. Describe it, or select Skip to configure the agent yourself.
- Alternatively, select a template (such as Customer Support or Appointment Scheduler) or Start from scratch from the agents list. The agent is created as soon as you select one.
- To rename the agent, select the pencil icon next to its name, enter a Name, and select Save.
agent_a1B2c3D4e5F6g7H8.Configure and publish the agent
- On the Configuration tab, enter the agent’s Instructions.
- Turn on Welcome message and enter a greeting to have the agent speak first. When it’s off, the agent waits for the caller to speak.
- Optional: review the settings that matter on a phone call:
- Select Publish.
Create an inbound trunk in Plivo
Create an inbound trunk that sends calls to xAI’s SIP endpoint,
sip.voice.x.ai, over TLS.- Console
- API
- Sign in to the Plivo Console.
- Navigate to SIP Trunking → Inbound Trunks and select Create Trunk.
- Enter a Trunk Name, for example
xAI-Inbound. - For SIP Platform, select xAI (SpaceXAI). The Primary URI is filled in with the xAI SIP URI,
sip:sip.voice.x.ai;transport=tls. - Select Create Trunk.
Connect your phone number
Route calls to your Plivo phone number through the inbound trunk.
- Console
- API
- Navigate to Phone Numbers and select your phone number.
- For Application Type, select SIP Trunk.
- For SIP Inbound Trunk, select the trunk you created in the previous step.
- Select Save changes.
Assign the number to your agent
Add your Plivo phone number to the agent, and allow all of Plivo’s signaling IP addresses. xAI accepts calls for the number only from these ranges, and Plivo can route a call through any region during a service disruption:To authenticate Plivo with a SIP username and password instead, see Use SIP digest authentication.
- Console
- API
- In the xAI Console, open your agent and select the Deployment tab.
- Under Phone numbers, select Add number.
- Select Direct SIP. You’re connecting your own Plivo number, so you don’t need a phone number from xAI. If the dialog says xAI can’t provision numbers in your region, you can continue.
- Enter a Name and your Phone number in E.164 format, for example
+15105550100. - Under Allowed addresses, enter each IP address range from the list above, and select Add after each one.
- Select Add number.
Outbound calls
xAI Voice Agents don’t support outbound calling. You don’t need a Plivo outbound trunk for this integration.Use SIP digest authentication
To authenticate Plivo with a SIP username and password instead of IP address ranges, add the same credentials in Plivo and xAI:- Username: 5 to 20 characters, alphanumeric only.
- Password: 5 to 20 characters, using only alphanumeric characters and the special characters
~!@#$%^&*()_+, with at least one special character.
- Console
- API
- Navigate to SIP Trunking → Inbound Trunks and open your xAI trunk.
- Open the Primary URI list and select the pencil icon next to the xAI URI.
- Turn on Authentication needed, then enter the Username and Password.
- Select Update URI.
- Console
- API
When you add the number in Assign the number to your agent, expand Authentication and enter the Username and Password. You can leave Allowed addresses empty.You can’t change the authentication of a number you already added. To switch an existing number to SIP digest authentication, select ⋯ → Edit → Remove number on the number under Phone numbers, and then add it again.
Make changes after setup
Update the agent
To change the agent’s instructions, voice, or tools, edit the agent in the xAI Console and select Publish. Nothing changes in Plivo.Update a registered number
You can rename a registered number, and with the API, route it to a different agent. Its allowed IP address ranges and SIP credentials can’t be changed in place: remove the number and add it again with the new values.- Console
- API
- Open the agent’s Deployment tab and select ⋯ → Edit on the number.
- Change the Name and select Save.
- To change the allowed IP address ranges or SIP credentials, select Remove number, and then add the number again.
Troubleshooting
SIP configuration errors typically surface only when a call is placed. If a call fails, check the following common issues:
Debug logs:
- Call doesn’t reach the agent: first check the Plivo logs, then the agent’s Conversations tab in the xAI Console.
- Call reaches the agent but behaves unexpectedly: check the call’s transcript and Raw events in the agent’s Conversations tab.
Related
SIP Trunking API overview
Plivo SIP Trunking API reference.
SIP Trunking overview
Plivo SIP trunking documentation.
xAI SIP Phone Calls
xAI’s SIP documentation.
xAI Voice API reference
xAI phone number and realtime API reference.