Skip to main content
The X Calls API is in development. It isn’t generally available yet, and endpoints and payloads may still change.
This walkthrough starts a call hosted by your bot, puts your agent in it and leaves again. You need an X app and the bot account your agent speaks as.
1

Get a user token for your bot

Every endpoint needs a user-context token for the account your agent speaks as; app-only bearer tokens are rejected. With OAuth 2.0 (Authorization Code with PKCE), request tweet.read, users.read, dm.read and dm.write, which cover every Calls endpoint. See Authentication for the per-endpoint scopes and OAuth 1.0a.
2

Create a call

The call starts empty. Share its join_url with the people you want in it.
To ring someone instead, pass the conversation_id of your bot’s conversation with them. See Calling people.
3

Join the call

Choose the sample rate your agent works at. It applies in both directions.
Open the media WebSocket before expires_at. The media_token works once.
4

Connect your agent

Open media_url with the media token. Binary frames carry audio (PCM16 little-endian mono at your sample rate); text frames carry JSON events from X and commands to X.
The session starts with session.created, then session.joined once your agent is in the call. See Media WebSocket for every event and command, and Example agent for a complete program.
5

Leave

Send {"type": "leave"} on the WebSocket, call POST /2/calls/:id/leave, or close the socket. Your WebSocket receives session.ended with the reason.

Next steps

Media WebSocket

Session lifecycle, events, commands and turn-taking.

Scheduled calls

Put calls on the calendar and find the ones to join.