InnerTube can operate in two distinct modes depending on whether you supply a session cookie. Unauthenticated mode works for most read-only operations, while authenticated mode unlocks library management, social features, and upload capabilities.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/faraasaaay/innertube-v1/llms.txt
Use this file to discover all available pages before exploring further.
Unauthenticated vs. Authenticated
- Unauthenticated
- Authenticated
No cookie is required. The library sends requests without an
Authorization header. This covers the vast majority of read-only operations:search(),searchSuggestions(),searchSummary()album(),artist(),playlist(),podcast()player()— stream URL resolution for public contenthome(),explore(),newReleaseAlbums(),moodAndGenres()next(),queue()
How Cookie Authentication Works
TheInnerTube HTTP layer implements YouTube’s cookie-based authentication protocol automatically. When YouTube.cookie is set and a request method opts into login, two things happen:
- The raw cookie string is attached as the
Cookierequest header. - A
SAPISIDHASHAuthorizationheader is computed and appended:
ORIGIN is https://music.youtube.com. This SHA-1 hash ties the credential to the current timestamp and origin, preventing replay attacks from other origins.
The library handles all of this internally. You only need to supply the cookie string.
Setting Up Authentication
Obtaining the Cookie String
YouTube does not provide an OAuth flow for InnerTube. The typical approach is to extract cookies from a logged-in YouTube session in a WebView:At minimum the cookie string must contain the
SAPISID cookie. Without it, the SAPISIDHASH header cannot be computed and authentication will silently fall back to unauthenticated mode.dataSyncId and onBehalfOfUser
WhenYouTube.dataSyncId is set, the library includes it as onBehalfOfUser in the request context body for all methods that support login. This signals to the InnerTube server which account’s data to return for library browse requests, liked songs, subscriptions, and personalised recommendations.
Fetching and Persisting visitorData
visitorData is an opaque token that YouTube uses to track session state. Keeping it consistent across requests improves the quality of personalised results (radio, recommendations). Fetch it once and persist it:
useLoginForBrowse
By default, browse methods only attach login headers when they explicitly opt in (e.g.playlist(), library(), history()). Setting YouTube.useLoginForBrowse = true causes every InnerTube.browse() call to include the cookie and SAPISIDHASH header. This is useful when you want fully personalised responses from the home page or genre/mood pages.