Twitch API
api.twitch.tv · Media
Live streaming data from Twitch — streams, games, clips, channels, and user data. Build Twitch integrations and bots. Free, OAuth2 required.
Authentication
OAuth2
OAuth2 client credentials flow. Register app at dev.twitch.tv/console. Exchange client_id + client_secret for access token. Pass as Authorization: Bearer TOKEN and Client-Id: CLIENT_ID headers.
Sample Requests
GET
Get top games
Get the top 5 games currently being streamed.
https://api.twitch.tv/helix/games/top?first=5
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Client-Id | YOUR_CLIENT_ID |
| Authorization | Bearer YOUR_TOKEN |
curl -X GET "https://api.twitch.tv/helix/games/top?first=5" \ -H "Client-Id: YOUR_CLIENT_ID" \ -H "Authorization: Bearer YOUR_TOKEN"
import requests
params = {
"first": "5"
}
headers = {
"Client-Id": "YOUR_CLIENT_ID",
"Authorization": "Bearer YOUR_TOKEN"
}
response = requests.get(
"https://api.twitch.tv/helix/games/top",
params=params,
headers=headers,
)
print(response.json())const url = new URL('https://api.twitch.tv/helix/games/top');
url.searchParams.set('first', '5');
const response = await fetch(url, {
headers: {
'Client-Id': 'YOUR_CLIENT_ID',
'Authorization': 'Bearer YOUR_TOKEN'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.twitch.tv/helix/games/top")
q := baseURL.Query()
q.Set("first", "5")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("Client-Id", "YOUR_CLIENT_ID")
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.twitch.tv/helix/games/top")
uri.query = URI.encode_www_form({
"first" => "5"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["Client-Id"] = "YOUR_CLIENT_ID"
req["Authorization"] = "Bearer YOUR_TOKEN"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.twitch.tv/helix/games/top?" . http_build_query([
"first" => "5"
]);
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"Client-Id: YOUR_CLIENT_ID",
"Authorization: Bearer YOUR_TOKEN"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Get streams
Get current Just Chatting streams.
https://api.twitch.tv/helix/streams?first=5&game_id=509658
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Client-Id | YOUR_CLIENT_ID |
| Authorization | Bearer YOUR_TOKEN |
curl -X GET "https://api.twitch.tv/helix/streams?first=5&game_id=509658" \ -H "Client-Id: YOUR_CLIENT_ID" \ -H "Authorization: Bearer YOUR_TOKEN"
import requests
params = {
"first": "5",
"game_id": "509658"
}
headers = {
"Client-Id": "YOUR_CLIENT_ID",
"Authorization": "Bearer YOUR_TOKEN"
}
response = requests.get(
"https://api.twitch.tv/helix/streams",
params=params,
headers=headers,
)
print(response.json())const url = new URL('https://api.twitch.tv/helix/streams');
url.searchParams.set('first', '5');
url.searchParams.set('game_id', '509658');
const response = await fetch(url, {
headers: {
'Client-Id': 'YOUR_CLIENT_ID',
'Authorization': 'Bearer YOUR_TOKEN'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.twitch.tv/helix/streams")
q := baseURL.Query()
q.Set("first", "5")
q.Set("game_id", "509658")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("Client-Id", "YOUR_CLIENT_ID")
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.twitch.tv/helix/streams")
uri.query = URI.encode_www_form({
"first" => "5",
"game_id" => "509658"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["Client-Id"] = "YOUR_CLIENT_ID"
req["Authorization"] = "Bearer YOUR_TOKEN"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.twitch.tv/helix/streams?" . http_build_query([
"first" => "5",
"game_id" => "509658"
]);
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"Client-Id: YOUR_CLIENT_ID",
"Authorization: Bearer YOUR_TOKEN"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Register at dev.twitch.tv/console → new application
- Get client_id and client_secret
- POST to https://id.twitch.tv/oauth2/token with grant_type=client_credentials to get access_token
- Set Authorization: Bearer ACCESS_TOKEN and Client-Id: CLIENT_ID headers
- GET /helix/games/top to test