# YouTube Data API API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/youtube
Last checked: 2026-11-08

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Google Cloud API key | — | 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 | — | 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 | — | 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

1. Create or select a project in the Google Cloud console.
2. Open the API Library and enable **YouTube Data API v3** for the project.
3. Go to **APIs & Services** → **Credentials** and choose **Create credentials** → **API key**.
4. Select **Restrict key**, add an application restriction (websites, IP addresses or apps) and limit the API restriction to YouTube Data API v3.
5. For uploads or private data, also create an **OAuth client ID** for your application type.

## 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

1. Open the key on the Credentials page and choose **Rotate key**; the new key gets the same restrictions.
2. Copy the new key string and update every application that uses the YouTube key.
3. Check that traffic has moved, then click **Delete the previous key** in the Previous key section.

## How to revoke a YouTube Data API key

1. Delete the API key on the Google Cloud console Credentials page.
2. 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 the key leaked

1. Add an API restriction and an application restriction to the exposed key at once if it has none.
2. Rotate the key, deploy the new string, then delete the previous key.
3. Check the project's quota usage in the Cloud console for calls you did not make.
4. If OAuth tokens were exposed, revoke them at `https://oauth2.googleapis.com/revoke`.

## Gotchas

- 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.
- `uploadLimitExceeded` is 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.

## Using this key with AI agents (BotPassword)

- `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.

## FAQ

### 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.

## Sources

- https://developers.google.com/youtube/registering_an_application
- https://developers.google.com/youtube/v3/getting-started
- https://developers.google.com/youtube/v3/docs/errors
- https://developers.google.com/youtube/v3/guides/auth/installed-apps
- https://docs.cloud.google.com/docs/authentication/api-keys
