YouTube Data API keys are Google Cloud API keys created under APIs & Services → Credentials in the Google Cloud console, after enabling "YouTube Data API v3" for the project. An API key only reads public data such as video metadata and search results; uploading, editing, deleting or reading a user's private data needs an OAuth 2.0 client ID and user consent. Google says to restrict every key before production use.
YouTube Data API key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| Google Cloud API key Google does not state a prefix rule; its example key string begins with AIza. Every call counts against the Cloud project's YouTube quota, so a leaked key spends your quota. | — | Yes | Public YouTube data, for whichever APIs and applications the key is restricted to | Does not expire unless rotated or deleted |
| OAuth 2.0 client ID and secret Created under Create credentials → OAuth client ID, choosing web, desktop, mobile or TV application type. | — | Yes | Identifies the app when a user authorizes it; needed for insert, update and delete calls and private data such as `channels.list` with `mine=true` | — |
| OAuth access and refresh tokens Google limits refresh tokens per client and user, so older ones can stop working. | — | Yes | The YouTube scopes the user granted to the app | Access tokens expire after the `expires_in` seconds returned with them; refresh tokens last until revoked or until a time-based grant ends |
How to create a YouTube Data API key
- Create or select a project in the Google Cloud console.
- Open the API Library and enable YouTube Data API v3 for the project.
- Go to APIs & Services → Credentials and choose Create credentials → API key.
- Select Restrict key, add an application restriction (websites, IP addresses or apps) and limit the API restriction to YouTube Data API v3.
- For uploads or private data, also create an OAuth client ID for your application type.
Open YouTube Data API's key settings
Limiting what the key can do
An API key has no YouTube permissions beyond public reads, so the risk is quota theft and abuse charged to your project. Google recommends setting both an API restriction, so the key works only with YouTube Data API v3, and an application restriction, so it works only from your websites, server IP addresses or apps. For OAuth, request only the YouTube scopes the app needs; Google returns insufficientPermissions when a token's scopes do not cover the request. Projects get 10,000 quota units per day for most endpoints, plus a separate allowance of 100 search.list and 100 videos.insert calls, and more can be requested with the YouTube API Services quota extension form.
How to rotate a YouTube Data API key
- Open the key on the Credentials page and choose Rotate key; the new key gets the same restrictions.
- Copy the new key string and update every application that uses the YouTube key.
- Check that traffic has moved, then click Delete the previous key in the Previous key section.
Both the old and new key work until the previous key is deleted. A key deleted too early can be undeleted within 30 days; after 30 days it cannot be restored.
How to revoke a YouTube Data API key
- Delete the API key on the Google Cloud console Credentials page.
- To revoke a user's OAuth grant, send the access or refresh token to
https://oauth2.googleapis.com/revoke; revoking an access token also revokes its refresh token.
If your YouTube Data API key leaked
- Add an API restriction and an application restriction to the exposed key at once if it has none.
- Rotate the key, deploy the new string, then delete the previous key.
- Check the project's quota usage in the Cloud console for calls you did not make.
- If OAuth tokens were exposed, revoke them at
https://oauth2.googleapis.com/revoke.
Things that catch people out
- An API key can never upload, edit or delete YouTube content; those calls always need OAuth user authorization.
- Quota belongs to the Cloud project, so every unrestricted key in the project can exhaust the same 10,000 daily units.
uploadLimitExceededis a YouTube platform limit on the channel and is separate from the project's API quota.- Revoking one OAuth token removes all scopes the user granted to the project, for every client in that project.
Common YouTube Data API authentication errors
quotaExceeded
HTTP 403. The Cloud project that owns the key has used its daily YouTube Data API quota.
authorizationRequired
HTTP 401. The request uses the mine parameter, or home on activities.list, without an OAuth token; an API key alone cannot read a user's own data.
insufficientPermissions
HTTP 403. The OAuth 2.0 token's scopes do not cover the data or action requested.
Using your YouTube Data API key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a YouTube Data API key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
How do I get a YouTube Data API key?
Enable YouTube Data API v3 in a Google Cloud project, then go to APIs & Services → Credentials → Create credentials → API key. Restrict the key before using it in production.
Do I need OAuth or an API key for the YouTube API?
An API key is enough for public data such as video details and search. Uploading videos, changing playlists or reading a user's own channel needs an OAuth 2.0 client ID and the user's consent.
What is the YouTube Data API daily quota?
Google gives each project 10,000 units per day for most endpoints, plus 100 search.list and 100 videos.insert calls. Request more with the quota extension form for YouTube API Services.
How do I restrict a YouTube API key?
Open the key, choose Restrict key, limit the API restriction to YouTube Data API v3 and add an application restriction for your websites, server IPs or apps.
Can an AI agent use a YouTube API key for research?
Yes, for public reads such as search and video statistics. Give the agent a separate key restricted to YouTube Data API v3 in its own Cloud project, so its calls cannot use up the quota your production app depends on.
Can an AI agent use my YouTube Data API key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, so the agent gets the result and never the value.