InnerTube client and response mapping
The InnerTube client is the boundary between Metrolist and YouTube Music. It sends catalog, playback, account, and library requests, then turns YouTube's renderer-shaped responses into stable music items and page results for the rest of the app. This page is a child of Music discovery; see Catalog search and browse flows for user-facing catalog paths and External content and AI services for other remote services.
System boundary
The innertube module separates request transport from music data use. InnerTube exposes a focused request surface, while YouTube combines those responses into results that discovery and playback features can consume.
flowchart LR
A[Discovery or playback request] --> B[YouTube facade]
B --> C[InnerTube client]
C --> D[YouTube Music InnerTube]
D --> E[Response models]
E --> F[Music page converters]
F --> G[Search results, pages, and playback data]
Request client
Request transport
The request transport provides one shared path for YouTube Music InnerTube calls. It applies the selected client profile and session context to requests, while the compatibility facade keeps parsed Metrolist models separate from the lower-level request library. The client also exposes selected calls to playback, suggestions, queues, transcripts, account state, and library changes through the same boundary. innertube/…/InnerTube.kt• L41-51 innertube/…/InnerTube.kt• L196-286
References: innertube/…/InnerTube.kt• L41-51 innertube/…/InnerTube.kt• L196-286
Endpoint configuration
The client targets the YouTube Music InnerTube API through one base endpoint. Each operation adds its own request path and chooses a YouTube client profile such as WEB or WEB_REMIX; that profile controls the service context used by YouTube. The same HTTP transport also supports the separate dislike-count service used for media details. innertube/…/InnerTube.kt• L141-194 innertube/…/InnerTube.kt• L399-403
References: innertube/…/InnerTube.kt• L141-194 innertube/…/InnerTube.kt• L399-403 innertube/…/YouTubeClient.kt• L1-3
Session and endpoint context
Each request uses a YouTube client profile, such as the web or web-remix profile, to select the service context that can answer it. The shared session carries locale, visitor data, account identity, cookies, and the browse-login choice. Proxy changes rebuild the transport but preserve this session, so network routing does not silently discard account context. innertube/…/InnerTube.kt• L58-128 innertube/…/YouTube.kt• L90-133
References: innertube/…/InnerTube.kt• L58-128 innertube/…/YouTube.kt• L90-133 innertube/…/YouTubeClient.kt• L1-3
Request outcomes
Read operations return response bodies for the mapping layer to decode. Mutating operations require a successful HTTP status and turn a failed status into an InnerTube error. This keeps a failed like, subscription, playlist edit, or upload from looking like a completed action. innertube/…/InnerTube.kt• L235-369
References: innertube/…/InnerTube.kt• L235-369
Playback registration
Playback registration records a listen only when an authenticated session and the history setting allow it. The client obtains a fresh account-bound tracking URL for each listen, checks that the URL is the trusted playback path, then sends the registration with the same session snapshot. A transport or account change during that exchange cancels the registration instead of sending it with stale identity. innertube/…/InnerTube.kt• L212-243 innertube/…/PlaybackRegistrationTest.kt• L19-97
References: innertube/…/InnerTube.kt• L212-243 innertube/…/PlaybackRegistrationTest.kt• L19-97
Response mapping
Response models
The response model layer mirrors only the parts of an InnerTube response that the product needs. Search responses provide tabs, shelves, item renderers, and continuation data. Browse responses provide page columns, headers, shelves, grids, actions, and continuation variants. Unknown fields can remain outside the model so changes in YouTube's wider response do not block useful data. innertube/…/SearchResponse.kt• L8-33 innertube/…/BrowseResponse.kt• L18-79
References: innertube/…/SearchResponse.kt• L8-33 innertube/…/BrowseResponse.kt• L18-79 innertube/…/InnerTube.kt• L139-152
Navigation endpoints
Navigation endpoints preserve the actions embedded in YouTube Music data. A single endpoint model can describe playback, playlist playback, browse navigation, search, queue insertion, feedback, sharing, and account or library commands. Its derived view selects the available action so page converters can pass user intent onward without rebuilding the original response shape. innertube/…/NavigationEndpoint.kt• L5-70 innertube/…/Endpoint.kt• L10-123
References: innertube/…/NavigationEndpoint.kt• L5-70 innertube/…/Endpoint.kt• L10-123
Music item models
The mapping layer presents a small set of product-level item types instead of exposing renderer names to callers. YTItem covers songs, episodes, albums, playlists, podcasts, and artists, with shared identity, title, image, explicit flag, and share-link concepts. Item-specific fields retain play endpoints, artist or album links, duration, library tokens, and podcast state when those values affect later actions. innertube/…/YTItem.kt• L5-160
References: innertube/…/YTItem.kt• L5-160
Pagination
Continuation tokens
A continuation is an opaque token that asks InnerTube for the next slice of a shelf, grid, search result, or page. The shared helper reads the supported continuation fields, including radio continuation data, so callers do not need to know which response branch supplied the token. innertube/…/Continuation.kt• L7-20
References: innertube/…/Continuation.kt• L7-20 innertube/…/SearchResponse.kt• L18-31 innertube/…/BrowseResponse.kt• L45-79
Page assembly
Page methods turn the first response and its continuation responses into one application result. Search keeps distinct items and returns the next token. Album, artist, library, and playlist flows select the continuation branch that matches the page shape, append new items, and stop when no usable token remains. Playlist continuation handling can combine section, shelf, and appended-item branches, while long-running album pagination guards against repeated tokens and excessive requests. innertube/…/YouTube.kt• L316-383 innertube/…/YouTube.kt• L559-619 innertube/…/YouTube.kt• L818-968 innertube/…/YouTube.kt• L1174-1232
References: innertube/…/YouTube.kt• L316-383 innertube/…/YouTube.kt• L559-619 innertube/…/YouTube.kt• L818-968 innertube/…/YouTube.kt• L1174-1232
URL parsing
Supported link types
The URL parser converts common YouTube and YouTube Music links into typed identifiers before the discovery layer chooses a page. It recognizes videos from watch, short-link, and Shorts forms; regular YouTube playlists; YouTube Music album playlists; and Music artist channel or browse links. Unsupported or malformed links return no parsed value. innertube/…/YouTubeUrlParser.kt• L7-29 innertube/…/YouTubeUrlParser.kt• L31-128
References: innertube/…/YouTubeUrlParser.kt• L7-29 innertube/…/YouTubeUrlParser.kt• L31-128
Link identity
The parser keeps the link type separate from the identifier because the same YouTube identifier space can represent different product pages. In particular, a Music playlist link is treated as an album candidate, while the browse response remains the source of truth for the final page type. innertube/…/YouTubeUrlParser.kt• L99-124 innertube/…/Endpoint.kt• L40-77
References: innertube/…/YouTubeUrlParser.kt• L99-124 innertube/…/Endpoint.kt• L40-77
Music-data conversion
Search conversion
Search conversion reads renderer rows and classifies them as songs, episodes, artists, albums, playlists, podcasts, or profiles. It extracts text runs, linked artists, album or podcast identity, duration, images, explicit state, play endpoints, and library action tokens. The result is a de-duplicated SearchResult or a grouped search summary that callers can present without knowing the response renderer layout. innertube/…/SearchPage.kt• L17-35 innertube/…/YouTube.kt• L165-314
References: innertube/…/SearchPage.kt• L17-35 innertube/…/SearchPage.kt• L117-364 innertube/…/YouTube.kt• L165-314
Browse conversion
Browse conversion maps page headers, shelves, grids, and page-specific sections into albums, artists, playlists, podcasts, songs, and episodes. Each page converter owns the meaning of its response shape, while shared helpers handle artist links, durations, thumbnails, library tokens, and endpoint state. Podcast and artist pages can use alternate header layouts without changing the product items returned to callers. This lets home, explore, charts, history, library, and detail pages share the same product item types without sharing their full response layouts. innertube/…/YouTube.kt• L385-557 innertube/…/YouTube.kt• L622-816 innertube/…/YouTube.kt• L1234-1531 innertube/…/HomePage.kt• L23-100
References: innertube/…/YouTube.kt• L385-557 innertube/…/YouTube.kt• L622-816 innertube/…/YouTube.kt• L970-1121 innertube/…/YouTube.kt• L1234-1531 innertube/…/HomePage.kt• L23-100
Shared metadata rules
Shared conversion rules protect product meaning when YouTube changes presentation details. Artist extraction accepts known Music page types and channel IDs. Library token extraction distinguishes add and remove actions while ignoring unrelated pin actions. Item filters then apply product choices for explicit content, video songs, and Shorts at the page-result level. innertube/…/PageHelper.kt• L12-19 innertube/…/PageHelper.kt• L82-149 innertube/…/BrowseResult.kt• L8-67
References: innertube/…/PageHelper.kt• L12-19 innertube/…/PageHelper.kt• L82-149 innertube/…/BrowseResult.kt• L8-67
Change checklist
When these files or sections are changed, remember to consider these:
- When client profiles or session fields change, check both the request facade and every flow that depends on anonymous or logged-in browse behavior.
- When a response model changes, check its first-page and continuation branches. InnerTube can return different shapes for the same product page.
- When renderer classification changes, check the shared
YTItemcontract and every page converter that creates the affected item type. - When endpoint or page-type values change, check URL routing, artist extraction, and the action endpoints kept on converted items.
- When library menu icons or tokens change, check both add and remove actions. Do not treat unrelated pin actions as library state.
- When playback tracking changes, check fresh URL retrieval, trusted-path validation, history privacy checks, and session consistency between the player and registration requests.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A response shape moves from a first-page renderer to a continuation renderer | The first page may work while later pages return no items or stop early | Keep page and continuation mappings together and return a continuation only when the mapped item list is usable |
| A renderer matches more than one item kind | An episode can be mapped as a song or lose its podcast data | Classify episode rows before the broader song check |
| A library icon or token is read as a pin action | Library add or remove controls can send the wrong feedback token | Use the shared library-token rules and ignore KEEP and KEEP_OFF actions |
| A proxy or transport is replaced without copying session state | Account, locale, or visitor context disappears from later requests | Recreate the transport from the saved session snapshot |
| A playback tracking URL is accepted without validating its path or session | Playback history can receive an unintended request or stale account context | Validate the playback path and compare the transport, session, and history setting before registration |
| A mutation returns a non-success response | The caller may show a completed action that YouTube rejected | Require success before returning from mutating client operations |
Key files
| File | Why to read it |
|---|---|
| innertube/…/InnerTube.kt | Defines the request boundary, endpoint setup, session context, transport lifecycle, playback registration, and operation outcomes. |
| innertube/…/YouTube.kt | Shows how request responses become discovery, playback, account, and library results. |
| innertube/…/PlaybackRegistrationTest.kt | Shows the privacy, session, URL validation, and fresh-request guarantees for playback history. |
| innertube/…/SearchResponse.kt | Shows the search response and continuation shape. |
| innertube/…/BrowseResponse.kt | Shows the page, shelf, grid, header, and continuation variants. |
| innertube/…/YTItem.kt | Defines the stable music item contract used after mapping. |
| innertube/…/SearchPage.kt | Illustrates renderer classification and search item conversion. |
| innertube/…/PageHelper.kt | Defines shared artist, duration, and library-token extraction rules. |
| innertube/…/YouTubeUrlParser.kt | Defines supported external link forms and typed URL results. |