Get Source Stream Key - X
Documentation Index Fetch the complete documentation index at: /llms.txt Use this file to discover all available pages before exploring further. Skip to main content GET / 2 / sources / {id} / stream_key Get a Stream Source's Stream Key curl --request GET \ --url https://api.x.com/2/sources/{id}/stream_key \ --header 'Authorization: Bearer <token>' import requests url = "https://api.x.com/2/sources/{id}/stream_key" headers = {"Authorization": "Bearer <token>"} response = requests.get(url, headers=headers) print(response.text) const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}}; fetch('https://api.x.com/2/sources/{id}/stream_key', options) .then(res => res.json()) .then(res => console.log(res)) .catch(err => console.error(err)); <?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api.x.com/2/sources/{id}/stream_key", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "Authorization: Bearer <token>" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.x.com/2/sources/{id}/stream_key" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer <token>") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } HttpResponse<String> response = Unirest.get("https://api.x.com/2/sources/{id}/stream_key") .header("Authorization", "Bearer <token>") .asString(); require 'uri' require 'net/http' url = URI("https://api.x.com/2/sources/{id}/stream_key") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer <token>' response = http.request(request) puts response.read_body { "data": { "id": "<string>", "stream_key": "<string>" }, "errors": [ { "detail": "<string>", "resource_type": "<string>", "title": "<string>", "type": "https://api.x.com/2/problems/resource-not-found", "parameter": "<string>", "resource_id": "<string>", "status": 123, "value": "<string>" } ] } { "code": 123, "message": "<string>" } Returns the stream key of one of the authenticated user’s stream sources. :id is the source id (19 digits) from Get Sources .
Configure your encoder with the source’s rtmps_url and this stream key. With OAuth 2.0, this read requires both the broadcast.read and broadcast.write scopes. { "data" : { "id" : "9123456789012345678" , "stream_key" : "YOUR_STREAM_KEY" } } The stream key is a credential: anyone with it can stream to the source. Fetch it only when you need to configure an encoder, and keep it out of logs, URLs, analytics and client-side code.
Errors Status Problem type When 400 https://api.x.com/2/problems/invalid-request :id isn’t a source id, for example a stream key: The `id` value is not a source id. The value isn’t echoed back. 404 https://api.x.com/2/problems/resource-not-found The source doesn’t exist or belongs to another user. Authorizations OAuth2UserToken UserToken Authorization string header required The access token received from the authorization server in the OAuth 2.0 flow.
Scopes broadcast.write Manage your live broadcasts and send chat messages on your behalf. broadcast.read View your live broadcasts and their chat. Path Parameters id string required Source id (19 digits), from GET /2/sources. Response The request has succeeded. data object Show child attributes errors object[] Option 1 Option 2 Option 3 Option 4 Option 5 Option 6 Option 7 Option 8 Option 9 Option 10 Option 11 Option 12 Option 13 Option 14 Option 15 Option 16 Option 17 Option 18 Option 19 Option 20 Option 21 Option 22 Option 23 Option 24 Option 25 Option 26 Option 27 Option 28 Option 29 Option 30 Option 31 Option 32 Option 33 Option 34 Option 35 Option 36 Option 37 Option 38 Option 39 Option 40 Option 41 Option 42 Option 43 Option 44 Option 45 Option 46 Option 47 Option 48 Option 49 Option 50 Option 51 Option 52 Option 53 Option 54 Option 55 Option 56 Option 57 Option 58 Option 59 Option 60 Option 61 Show child attributes ⌘ I Get a Stream Source's Stream Key curl --request GET \ --url https://api.x.com/2/sources/{id}/stream_key \ --header 'Authorization: Bearer <token>' import requests url = "https://api.x.com/2/sources/{id}/stream_key" headers = {"Authorization": "Bearer <token>"} response = requests.get(url, headers=headers) print(response.text) const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}}; fetch('https://api.x.com/2/sources/{id}/stream_key', options) .then(res => res.json()) .then(res => console.log(res)) .catch(err => console.error(err)); <?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api.x.com/2/sources/{id}/stream_key", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "Authorization: Bearer <token>" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.x.com/2/sources/{id}/stream_key" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer <token>") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } HttpResponse<String> response = Unirest.get("https://api.x.com/2/sources/{id}/stream_key") .header("Authorization", "Bearer <token>") .asString(); require 'uri' require 'net/http' url = URI("https://api.x.com/2/sources/{id}/stream_key") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer <token>' response = http.request(request) puts response.read_body { "data": { "id": "<string>", "stream_key": "<string>" }, "errors": [ { "detail": "<string>", "resource_type": "<string>", "title": "<string>", "type": "https://api.x.com/2/problems/resource-not-found", "parameter": "<string>", "resource_id": "<string>", "status": 123, "value": "<string>" } ] } { "code": 123, "message": "<string>" }