Skip to main content
Build a Grok voice-agent in xAI Voice Agents and have it answer calls to your Plivo phone number. Plivo sends each call over an inbound SIP trunk to xAI, where the agent is hosted, so you don’t run any server.

How the integration works

Call flowPlivo SIP Trunking · xAI
  1. CallerDials your Plivo phone number
  2. Plivo inbound SIP trunkPrimary URI: sip.voice.x.ai
  3. xAIChecks Plivo’s IP address or SIP digest credentials, then matches the dialed number
  4. 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 by plivo login, not the environment variables below.
Export your credentials as environment variables to use with the cURL, Python, and Node samples:

Inbound calls

Set up the agent in xAI, route your Plivo number to xAI, and then connect the number to the agent.
1

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.
  1. Sign in to the xAI Console and select Voice Agents in the left navigation.
  2. Select Create agent. A builder chat asks about your use case. Describe it, or select Skip to configure the agent yourself.
  3. 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.
  4. To rename the agent, select the pencil icon next to its name, enter a Name, and select Save.
Copy the agent ID from the page URL, for example agent_a1B2c3D4e5F6g7H8.
2

Configure and publish the agent

  1. On the Configuration tab, enter the agent’s Instructions.
  2. 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.
  3. Optional: review the settings that matter on a phone call:
  1. Select Publish.
Publish after every change: Edits are saved as a draft, and the agent’s status changes from Live to Draft. Calls use the published version until you select Publish again.
3

Create an inbound trunk in Plivo

Create an inbound trunk that sends calls to xAI’s SIP endpoint, sip.voice.x.ai, over TLS.
  1. Sign in to the Plivo Console.
  2. Navigate to SIP Trunking → Inbound Trunks and select Create Trunk.
  3. Enter a Trunk Name, for example xAI-Inbound.
  4. For SIP Platform, select xAI (SpaceXAI). The Primary URI is filled in with the xAI SIP URI, sip:sip.voice.x.ai;transport=tls.
  5. Select Create Trunk.
4

Connect your phone number

Route calls to your Plivo phone number through the inbound trunk.
  1. Navigate to Phone Numbers and select your phone number.
  2. For Application Type, select SIP Trunk.
  3. For SIP Inbound Trunk, select the trunk you created in the previous step.
  4. Select Save changes.
5

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.
  1. In the xAI Console, open your agent and select the Deployment tab.
  2. Under Phone numbers, select Add number.
  3. 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.
  4. Enter a Name and your Phone number in E.164 format, for example +15105550100.
  5. Under Allowed addresses, enter each IP address range from the list above, and select Add after each one.
  6. Select Add number.
Add the ranges faster: The field accepts one range at a time. Press Enter after each range instead of selecting Add. To add all 14 ranges in a single request, use the API tab instead.
The number appears under Phone numbers with Provisioned by set to Direct SIP.
6

Test the integration

  1. Call your Plivo phone number. The agent answers with its welcome message.
  2. In the xAI Console, open your agent and select the Conversations tab. Select a call to see its transcript, per-turn audio, and raw events. xAI keeps conversations for 30 days.

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.
In Plivo, turn on authentication for the trunk’s primary URI:
  1. Navigate to SIP Trunking → Inbound Trunks and open your xAI trunk.
  2. Open the Primary URI list and select the pencil icon next to the xAI URI.
  3. Turn on Authentication needed, then enter the Username and Password.
  4. Select Update URI.
In xAI, add the same credentials to your phone number:
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.
  1. Open the agent’s Deployment tab and select ⋯ → Edit on the number.
  2. Change the Name and select Save.
  3. 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.
For error codes, see Plivo hangup codes.

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.