Scority

YouTube API Python Guide

Use Python to fetch YouTube transcripts with the Scority API. See requests examples, API key auth, language options and error handling.

Direct answer

Fetch transcripts from Python with a server-side API call

For transcript extraction, Python code can call the Scority HTTP API directly. Send a video_id or video_url, include x-api-key from a server-side environment variable and parse the JSON response.

  • Use https://api.scority.ai as the API base URL.
  • Call GET /v1/youtube/transcript with exactly one video identifier.
  • Use language when your workflow needs a specific caption language.
  • Handle normalized error codes such as unauthorized, rate_limited and upstream_transcript_failed.
Fit

When Python developers need transcript access

Python transcript workflows often sit behind agents, RAG indexing jobs, summarizers, research tools and internal automation. Those jobs need text plus segment timing, not a browser-only scraping script.

  • Use Python for batch processing, enrichment and downstream NLP workflows.
  • Keep API keys on the server, in workers or in private notebook environments.
  • Avoid putting transcript API calls with real keys into public frontend code.
API choice

Official YouTube API vs transcript API

The official YouTube Data API is useful for metadata and platform workflows. A transcript-specific API focuses on caption text, timestamps and transcript-specific errors.

  • Use the official API when you need official metadata, channels, playlists or platform operations.
  • Use Scority when your Python app needs transcript text for a public video with accessible captions.
  • Do not treat Scority as a replacement for every YouTube API use case.

Python request by video_id

import os
import requests

response = requests.get(
    "https://api.scority.ai/v1/youtube/transcript",
    params={"video_id": "dQw4w9WgXcQ"},
    headers={"x-api-key": os.environ["SCORITY_API_KEY"]},
    timeout=30,
)
response.raise_for_status()

transcript = response.json()
print(transcript["text"])

Python request by video_url and language

import os
import requests

response = requests.get(
    "https://api.scority.ai/v1/youtube/transcript",
    params={
        "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
        "language": "en",
    },
    headers={"x-api-key": os.environ["SCORITY_API_KEY"]},
    timeout=30,
)

result = response.json()
Response

Read text, segments, source and language

A successful response returns the selected language, transcript source, full text and ordered transcript segments. The segment list is useful when you need timestamps for citations, clipping, search snippets or chunking.

  • text is the full transcript text.
  • segments contains text, start and duration fields.
  • language tells you the caption language selected by the API.
  • source identifies the transcript source path without exposing internal diagnostics.

Handle 429 errors explicitly

if response.status_code == 429:
    error = response.json()["error"]
    if error["code"] == "rate_limited":
        retry_after = response.headers.get("Retry-After")
        print(f"Retry after {retry_after} seconds")
    elif error["code"] == "quota_exceeded":
        print("Monthly quota reached")
SDK status

Use HTTP for production Python integrations

The repository contains a Python client preview for future package work. For production integrations today, use the HTTP API and OpenAPI reference.

  • Do not add public package-install commands for a Scority Python package until distribution is finalized.
  • Use YOUR_API_KEY or a server-side environment variable in examples.
  • Follow /docs/authentication for API key handling.
Reference

API reference

See query parameters, response fields and rate-limit headers.

Open →
Auth

Authentication

Keep x-api-key in server-side configuration.

Open →
Errors

Error codes

Map normalized API errors to retry and validation behavior.

Open →
Guide

YouTube API transcript guide

Understand video IDs, video URLs and transcript-specific API behavior.

Open →