Skip to main content
The complete flow from nothing to a live broadcast on X:
1

Get the recommended region

GET /2/region → obtain the recommended region. See Get Recommended Region.
2

Create (or reuse) a stream source

POST /2/sources → create a source for that region. Record its id (the source id) and rtmps_url, and store its stream_key securely. To reuse a source, find its id with GET /2/sources and read its key with GET /2/sources/:id/stream_key. See Create a Source and Get Source Stream Key.
3

Start your encoder

Configure and start your encoder with the source’s rtmps_url and stream key. is_stream_active becomes true within a few seconds (poll Get Source by ID if desired). You can also start it right after going live, but video must arrive within 5 minutes of going live. Some sources can’t go live until video is flowing (Go Live returns a 409 conflict until it is); starting the encoder first avoids this.
4

(Optional) Prepare chat access

Subscribe to the user’s broadcast.chat events in the X Activity API. If you have already done this previously, you don’t need to resubscribe — the subscription covers all broadcasts for the user. See Accessing Live Chat.
5

Go live

POST /2/broadcasts with the source id as source_id (+ title, chat_option, etc.). The broadcast is created already RUNNING and publicly visible. Note the id and share_url. If the source already has a live broadcast, that broadcast is returned instead (200). See Go Live.
6

While live

Poll GET /2/broadcasts/:id for viewer counts, thumbnails, state, and the announcement post’s tweet_id; read chat via the X Activity API; optionally post messages with POST /2/broadcasts/:id/chat.
7

End the broadcast

When done: stop your encoder, then PUT /2/broadcasts/:id/state with { "state": "END" }. The broadcast transitions to ENDED. See End Broadcast.
8

(Optional) Pull chat history

GET /2/broadcasts/:id/chat returns the broadcast’s chat history. This endpoint is only valid after the broadcast has ended. See Get Chat History.
9

(Optional) Clean up

Delete the broadcast with DELETE /2/broadcasts/:id, or the source with DELETE /2/sources/:id, if no longer needed.
Sources are reusable. Create a new source only when you need a different region or want to isolate encoder configs.
This workflow uses the /2/sources and /2/broadcasts routes. The original /2/users/:user_id/sources and /2/users/:user_id/broadcasts routes are deprecated and will be removed on January 1, 2027; see the migration guide.