Create Clips
Learn to create clips using the Twitch API.
We'll cover the following
We retrieve information regarding clips, but we can also use the Twitch API to create a clip from a currently ongoing live stream programmatically. To do so, we can send a simple POST request to the clips endpoint and pass the ID of a currently streaming channel.
All POST requests to create a clip must be authenticated with a user access token that has the clips:edit
scope.
Input parameters
It requires a single query parameter, and another optional query parameter. The table below gives an overview of both parameters:
Parameter | Type | Category | Description |
| String | Required | This is the ID of the live channel whose ongoing live stream we want to clip. |
| Boolean | Optional | This indicates whether to wait for a short period before capturing the clip. If it is |
The ID that we pass in the broadcaster_id
parameter must be a valid ID, and the corresponding user must be live when we make the request. If the broadcaster is not live, clip creation will fail.
Example call
Let's make a sample call to this endpoint. First, let's query the streams endpoint to retrieve a list of ongoing streams. Next, we’ll call the clips endpoint with the ID of a user that is currently live.
Note: The code below extracts a clip ID to be used later, so don't forget to save it. If your access token has expired, return to this lesson and follow the steps to generate a new one.
headers = {'Authorization' : 'Bearer {{USER_ACCESS_TOKEN}}','Client-Id' : '{{CLIENT_ID}}'}# Making a call to the streams endpoint to get ongoing live streamsresponse = requests.get('https://api.twitch.tv/helix/streams', headers=headers).json()# Extracting the ID of a user who is currently live from the previous responsebroadcaster = response['data'][0]['user_id']parameters = {'broadcaster_id' : broadcaster}# Making a POST request to the clips endpointresponse = requests.post('https://api.twitch.tv/helix/clips',headers=headers, params=parameters).json()print(json.dumps(response, indent=4))
Let's make a GET request to the clips endpoint to retrieve the details of the clip we just created:
Note: Clip creation may take some time, so if you don't get the expected response from the following request, try running the code again after a few minutes. If your access token has expired, return to this lesson and follow the steps to generate a new one.
headers = {'Authorization' : 'Bearer {{APP_ACCESS_TOKEN}}','Client-Id' : '{{CLIENT_ID}}'}parameters = {'id' : '{{CLIP_ID}}'}response = requests.get('https://api.twitch.tv/helix/clips',headers=headers, params=parameters).json()print(json.dumps(response, indent=4))
Response structure
The JSON response from a POST request to the clips endpoint when creating a clip has a single top-level property—data
. This property contains an array of objects, with each object representing a clip that was just created. The table below discusses the properties of these objects:
Property | Type | Description |
| String | This is the ID of the clip. |
| String | This is the URL where the created clip can be edited. |