Docs
One script, no dependencies beyond requests, and no YouTube API key.
Create a token on your account page and put it in an environment variable. The script below queues a video, waits for it, and prints the text.
import time
import requests
BASE = "https://api.youtubetotext.ai"
HEADERS = {"Authorization": "Bearer ytt_<your-token>"}
# Queue the video. This answers straight away with an id; the work runs after.
job = requests.post(
f"{BASE}/v1/api/transcribe",
headers=HEADERS,
json={"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"},
).json()
# Poll until the job stops. Every 3 seconds is plenty.
while True:
result = requests.get(
f"{BASE}/v1/api/transcription/{job['id']}", headers=HEADERS
).json()
if result["state"] in ("done", "failed"):
break
time.sleep(3)
if result["state"] == "failed":
raise SystemExit(result["error"])
print(result["txt"])The popular Python packages fetch the caption track YouTube already holds. That is fast and free, and it stops at the same place every time: a video with captions turned off has nothing to read, and an auto-caption track is what the uploader was given, not what you would get from a fresh transcription.
This API transcribes the audio instead. It works on a video with no captions at all, it puts in punctuation and paragraphs, it labels the speakers, and it costs minutes, which a caption fetch does not. If the video you want already has a good caption track and you only need the words, a caption library is the cheaper tool and we would rather say so. Our own measured accuracy is on the accuracy page.