How to Get a Free YouTube Data API Key in About 3 Minutes

If you’re building a tool that needs to fetch public YouTube data—such as channel information, videos, titles, descriptions, or statistics—you’ll need a YouTube Data API v3 key.

The good news is that getting a YouTube Data API key is free, doesn’t require billing details for the standard quota, and usually takes only a few minutes.

In this guide, we’ll create the key, restrict it for security, add it to a .env file, and verify that it works.

Important: Never publish your API key in your source code, GitHub repository, screenshots, or public documentation.

What You’ll Need

Before starting, you’ll need:

  • A Google account
  • Access to Google Cloud Console
  • A project for your application
  • A terminal if you’re testing the key locally

The default YouTube Data API quota is 10,000 units per day, which is more than enough for many local development and small-scale applications.


Step 1: Create a Google Cloud Project

First, open the Google Cloud Console:

Google Cloud Console

Sign in with your Google account.

Once you’re in:

  1. Click the project selector in the top navigation bar.
  2. Select New Project.
  3. Give your project a name, such as ChannelMind.
  4. Click Create.
  5. Make sure the new project is selected before continuing.

Your API credentials will belong to this project, so selecting the correct project is important.


Step 2: Enable YouTube Data API v3

Next, you need to enable the YouTube API for your project.

Open the YouTube Data API v3 page:

YouTube Data API v3 — Google Cloud Console

Make sure your newly created project is selected.

Then click Enable.

Why is this step important?

Creating an API key isn’t enough by itself. The YouTube Data API must also be enabled for the Google Cloud project.

If you skip this step, your API requests can fail with an error such as:

403 accessNotConfigured

So make sure the API shows as enabled before creating your key.


Step 3: Create the API Key

Now open the Credentials page:

Google Cloud Credentials

Then:

  1. Click + Create Credentials.
  2. Select API key.
  3. Google Cloud will generate your API key.
  4. Copy the key and store it somewhere secure.

The key normally starts with:

AIza...

Don’t share this key publicly.


Step 4: Restrict Your API Key

For security, it’s a good idea to restrict the key so it can’t be freely used with other Google APIs if it gets exposed.

From the Credentials page, click your newly created API key to edit it.

Restrict the API

Under API restrictions:

  1. Select Restrict key.
  2. Select YouTube Data API v3.
  3. Save the changes.

This limits the key to the API your application actually needs.

What about Application restrictions?

For a local application running from your Mac, you can leave Application restrictions set to None.

An IP-address restriction is another option for server-side applications, but it can become inconvenient for local development because your public IP address may change.

For a local development setup, API-level restriction is a practical starting point.


Step 5: Add the Key to Your .env File

If you’re working on a local project such as ChannelMind, don’t hard-code the API key into your Python source code.

Instead, store it in your .env file.

For example:

YOUTUBE_API_KEY=AIza...

If you’re using the project path:

/Users/dev-mode/Desktop/pythonProjects/ChannelMind

you can update the existing value from the terminal with:

cd /Users/dev-mode/Desktop/pythonProjects/ChannelMind

sed -i '' 's|^YOUTUBE_API_KEY=.*|YOUTUBE_API_KEY=AIza...|' .env

Replace AIza... with your actual API key.

Don’t commit .env to Git

Make sure .env is included in your .gitignore:

.env

This prevents your API key from accidentally being pushed to GitHub or another public repository.


Step 6: Verify That the API Key Works

Now let’s make a simple API request.

The following command reads the API key directly from .env, rather than passing it as a command-line argument:

KEY=$(awk -F= '/^YOUTUBE_API_KEY=/{print $2}' .env) && \
curl -s "https://www.googleapis.com/youtube/v3/channels?part=snippet&forHandle=@veritasium&key=$KEY" \
  | python3 -m json.tool | head -20

The request looks up the YouTube channel associated with the @veritasium handle.

If the response contains the channel information and title, your API key is working.

This request uses only 1 quota unit.


Troubleshooting Common Errors

If the request doesn’t work, check the error message.

accessNotConfigured

This usually means the YouTube Data API v3 hasn’t been enabled for your Google Cloud project.

Go back to Step 2 and make sure the API is enabled.

API key not valid

Check that:

  • The key was copied completely.
  • There are no extra spaces.
  • You didn’t accidentally truncate the key.
  • The API key belongs to the currently selected Google Cloud project.

quotaExceeded

The project has reached its available daily YouTube Data API quota.

The standard allocation is 10,000 units per day.


Understanding YouTube API Quotas

One important thing to understand about the YouTube Data API is that requests don’t all cost the same amount of quota.

For example, a simple channel request can cost very little, while more complex operations can consume significantly more.

For the application described here, a full pull of around 2,000 videos can cost approximately 81 quota units, depending on the exact API operations involved.

With a default allocation of 10,000 units per day, that’s a substantial amount of room for a local development workflow.

Increasing the quota is possible, but higher quota requests can involve Google’s additional compliance and review requirements. For a typical local application, the default quota should generally be sufficient.


API Key vs. OAuth: What’s the Difference?

There’s another important distinction if you’re building a more advanced YouTube analytics application.

API Key

An API key is suitable for accessing public YouTube data.

That includes the public data your application needs through the earlier phases of development, such as:

  • Public channel information
  • Public videos
  • Titles and descriptions
  • Public statistics
  • Other publicly available YouTube Data API information

You don’t need the channel owner’s permission simply to retrieve publicly available data.

OAuth

OAuth is different.

If your application needs access to private or owner-only YouTube Analytics information—such as:

  • Impressions
  • Click-through rate (CTR)
  • Audience retention
  • Other channel-owner analytics

—you’ll need an OAuth 2.0 flow and the appropriate Google credentials.

OAuth also means the user must authorize your application.

So, for example:

Public YouTube data → API key

Private/owner analytics → OAuth

These are separate authentication flows and use different credentials.


Security Tips

Treat your YouTube API key like a credential.

Don’t do this

YOUTUBE_API_KEY = "AIzaSy..."

And don’t commit the key to GitHub.

Do this instead

YOUTUBE_API_KEY=AIzaSy...

Then load it through your application’s environment configuration.

Also:

  • Add .env to .gitignore.
  • Restrict the API key to YouTube Data API v3.
  • Don’t post the key in screenshots or support requests.
  • Regenerate the key if you accidentally expose it.
  • Use separate credentials for different environments when appropriate.

That’s It!

You now have a YouTube Data API v3 key that can be used to access public YouTube data.

The complete process is:

Google Cloud Project → Enable YouTube Data API v3 → Create API Key → Restrict Key → Store in .env → Test the API

For a local application, this setup is usually enough to get started without configuring billing or OAuth.

And when your application eventually needs private YouTube Analytics data, you can add OAuth separately rather than replacing the API-key setup.