Authentication
Learn how to authenticate your API requests using Bearer tokens.
Overview
The YouTube Transcript API uses Bearer token authentication. Every request to the API must include an header with your API key. Authorization
Keep your API key secret
Never expose your API key in client-side code, public repositories, or share it with others. If compromised, revoke it immediately from your dashboard.
Getting Your API Key
Follow these steps to obtain your API key:
Navigate to API Keys
Generate a new API key
Click "Create New Key", give it a name, and copy the generated key. Make sure to save it - you won't be able to see it again!
API Key Format
API keys are prefixed with yt_ followed by a unique identifier:
yt_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6Making Authenticated Requests
Include your API key in the Authorization header using the Bearer scheme:
Two authentication methods are supported:
Authorization: Bearer yt_your_api_key- Bearer token in Authorization headerX-API-Key: yt_your_api_key- Direct API key header
cURL (Bearer Token)
curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ" \
-H "Authorization: Bearer yt_your_api_key"cURL (X-API-Key Header)
curl -X GET "https://api.fetchtranscript.com/v1/transcripts/dQw4w9WgXcQ" \
-H "X-API-Key: yt_your_api_key"Python
import requests
API_KEY = "yt_your_api_key"
BASE_URL = "https://api.fetchtranscript.com/v1"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
response = requests.get(
f"{BASE_URL}/transcripts/dQw4w9WgXcQ",
headers=headers
)
print(response.json())JavaScript
const API_KEY = "yt_your_api_key";
const BASE_URL = "https://api.fetchtranscript.com/v1";
const response = await fetch(
`${BASE_URL}/transcripts/dQw4w9WgXcQ`,
{
headers: {
"Authorization": `Bearer ${API_KEY}`
}
}
);
const data = await response.json();
console.log(data);Authentication Errors
If authentication fails, you will receive one of the following error responses:
| Status Code | Error | Description |
|---|---|---|
| 401 | missing_api_key | No API key provided in request |
| 401 | invalid_api_key | API key has been revoked |
| 402 | insufficient_credits | Insufficient credits |
Best Practices
Use environment variables
Store your API key in environment variables, not in your code.
Use different keys for different environments
Create separate API keys for development, staging, and production.
Rotate keys periodically
Regularly rotate your API keys to minimize security risks.
Never expose keys client-side
Make API calls from your server, not from browser JavaScript.