Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

YouTube API Features

Alex edited this page Feb 11, 2023 · 7 revisions

The YouTube API

Created in 2015, InnerTube is a cross-platform API created to simplify the deployment of updates and experiments across the platform. This is not confused with the YouTube Data API, which is the publicly available, officially supported API for programmatic use

This page documents Innertube to help contributors get up to speed with API and its known features. This page will be updated periodically as the reverse engineering process continues.

Initialisation

Obtaining an API Key

To obtain an API key, send a get request to https://youtube.com/sw.js_data. The API key will be a 39-character string often beginning with the string AIza

Context

This is a standard context object. The context object will be needed for most API calls to Innertube, this will only need to be created once per session as the context object doesn't change. Note: All the examples in this page will use an abbreviated version of the context object.

{
  "client": {
    "gl": "US",
    "hl": "en-US",
    "deviceMake": "Generic",
    "userAgent": "Dalvik/2.1.0 (Linux; U; Android 12; sdk_gphone64_x86_64 Build/SE1A.220203.002.A1),gzip(gfe)",
    "clientVersion": "18.06.35",
    "clientName": "ANDROID",
    "osName": "ANDROID",
    "osVersion": "12",
    "platform": "MOBILE",
    "visitorData": "CgtZZFRBc1VkVmthayiow_uUBg%3D%3D",
    "clientFormFactor": "SMALL_FORM_FACTOR"
  }
}

Let's take a look at what all these values mean

  • gl: the ISO-3166-1 Alpha 2 code for the location of the user. The default value can be obtained in the sw.js_data endpoint.
  • hl: the ISO 639-1 code for the language. May also be trailed by an all caps ISO-3166-1 Alpha 2 country code for languages with regional differences (i.e en-US). The default value can be obtained in the sw.js_data endpoint.
  • userAgent: a random user agent
  • clientName & clientVersion: the API types & version
  • visitorData: a protobuf encoded 11-character random string and the current UNIX timestamp in seconds, replacing the + and / with the - and _ characters respectively. This can also be obtained in the sw.js_data endpoint.
  • devicemake, osName, osVersion, platform & clientFormFactor: data about the device. Can be hard coded.

API types & version

Client Name Version
ANDROID 18.06.35
WEB 2.20230206.06.00
MWEB 2.20230206.06.00

The Home Page

to retrieve the home page, simply send a post request to the https://www.youtube.com/youtubei/v1/browse endpoint.

this request supports pagination. See Continuations.

curl --request POST \
  --url 'https://www.youtube.com/youtubei/v1/browse?key=AIzaSyDCU8hByM-4DrUqRUYnGn-3llEO78bcxq8' \
  --header 'Content-Type: application/json' \
  --data '{
    "context": {
        "client": {
            "clientName": "ANDROID",
            "clientVersion": "18.06.35",
            "hl": "en-US"
        }
    },
    "browse_id": "FEwhat_to_watch"
}'

Search

To search for a given query, use the https://www.youtube.com/youtubei/v1/search endpoint

this request supports pagination. See Continuations.

curl --request POST \
  --url 'https://www.youtube.com/youtubei/v1/search?key=AIzaSyDCU8hByM-4DrUqRUYnGn-3llEO78bcxq8' \
  --header 'Content-Type: application/json' \
  --data '{
    "context": {
        "client": {
            "clientName": "ANDROID",
            "clientVersion": "18.06.35",
            "hl": "en-US"
        }
    },
    "query": "Linus Tech Tips"
}'

Continuations

For any features or segments that support infinite pagination, there will be a continuations array which contains a nextContinuationData object that contains a long string with the key continuation.

Simply call the https://youtube.com/youtubei/v1/next endpoint with the continuation string to paginate

curl --request POST \
  --url 'https://www.youtube.com/youtubei/v1/next?key=AIzaSyDCU8hByM-4DrUqRUYnGn-3llEO78bcxq8' \
  --header 'Content-Type: application/json' \
  --data '{
    "context": {
        "client": {
            "clientName": "ANDROID",
            "clientVersion": "18.06.35",
            "hl": "en-US"
        }
    },
    "continuation": "4qmFsgL6AhIPRkV3aGF0X3RvX3dhdGNoGuYCQ0FWNi13RkhUVkJHYm5aWFpXMTJaME5OWjNOSmFuSlhZWEU0WmpKd05IVmZRVlp3ZFVOdGQwdEhXR3d3V0ROQ2FGb3lWbVpqTWpWb1kwaE9iMkl6VW1aamJWWnVZVmM1ZFZsWGQxTklNRlV3VG0xc01HUldaSEZUVmtWM1ZWVkdSVkV5TVRKaldFWlpXVEpLZUUxdVduQk1VekZHWlVkallVeG5RVUZhVnpSQlFWWldWRUZCUms5WFowRkNRVVZhUm1ReWFHaGtSamt3WWpFNU0xbFlVbXBoUVVGQ1FVRkZSRUZSUlVGQlVVRkNRVUZCUWtGUlFtbE1RV2RCUldoT2QxbFhaR3hZTTA1MVdWaENlbUZIT1RCWU0xSjJZVEpXZFVkb1RVbHlZMjFCT1ZvMllTMUJTVlpvYjBwcVFtZ3pjblozZWxNdGNIcElkbEZyUTBOQlk4Z0dBZm9HQkFvQ0NBVSUzRA%3D%3D"
}'
Clone this wiki locally