YouTube Data API
Search videos, channels and playlists and read YouTube metadata.
What it does
The YouTube Data API (v3) reads and manages YouTube resources: search for videos, channels and playlists; fetch video metadata, statistics and captions; read comment threads; and (with OAuth) upload videos, manage playlists and moderate comments.
Base URL
Authentication
Enable the API in Google Cloud and use an API key (?key=YOUR_KEY) for public read-only calls. Anything user-specific or write requires OAuth 2.0 with the relevant youtube scope.
Code examples
curl -s "https://www.googleapis.com/youtube/v3/videos?part=snippet,statistics"\ "&id=dQw4w9WgXcQ&key=$YT_API_KEY"
import requests
r = requests.get("https://www.googleapis.com/youtube/v3/search", params={
"part": "snippet", "q": "lo-fi beats", "type": "video",
"maxResults": 5, "key": KEY}, timeout=10)
for item in r.json()["items"]:
print(item["id"]["videoId"], item["snippet"]["title"])Rate limits & quotas
Every project gets 10,000 quota units/day by default (request more via a form). Costs are per operation, not per request: a read is typically 1 unit, search.list is 100 units, and writes are ~50. That is only ~100 searches/day on the default quota — cache and avoid search.list where a cheaper endpoint works.
Key response fields
| items[].id.videoId | Video ID (from search results) |
| items[].snippet.title / channelTitle / publishedAt | Basic metadata |
| items[].statistics.viewCount / likeCount | Counters (request part=statistics) |
| nextPageToken | Pass as pageToken for the next page |
| pageInfo.totalResults | Approximate total matches |
Common errors
| 403 quotaExceeded | Daily 10,000-unit quota used up — resets at midnight Pacific. |
| 403 keyInvalid / ipRefererBlocked | Bad key or key restrictions block your origin. |
| 400 missingRequiredParameter | You forgot part= — it is mandatory. |
| 404 | Video/channel ID does not exist or is private. |
When to use it (and alternatives)
Necessary for anything reading real YouTube data. Budget the quota carefully — search.list is expensive. For simple ‘embed this video’ use cases the oEmbed endpoint (https://www.youtube.com/oembed?url=) is free and quota-less.
FAQ
Why do I run out of quota so fast?
search.list costs 100 units, so the default 10,000/day is only 100 searches. Use videos.list/channels.list/playlistItems.list (1 unit each) whenever you already know the IDs, and cache results.
Can I get a video's full view count history?
No — the API only returns current totals. Historical analytics require the separate YouTube Analytics API and ownership of the channel.
Do I need OAuth to read public videos?
No, an API key is enough for public reads. OAuth is only for uploads, playlist edits, and reading a signed-in user’s private data.
New to APIs?
Short guides for working with this API — and any other.