YouTube Transcript API
Extract closed captions from YouTube videos as structured JSON. Token estimation, smart truncation, and keyword search with timestamps.
GET
/api/youtube/transcript
5 sats
Get the full transcript of a YouTube video. Supports full text or timestamped segments with optional token-based truncation.
| Parameter | Type | Description |
|---|---|---|
videoId | string | YouTube video ID or full URL |
format | string | "full" (default) or "segments" for timestamped chunks |
maxTokens | int | Optional. Truncate transcript to fit within this token budget |
curl "https://agent-commerce.store/api/youtube/transcript?videoId=dQw4w9WgXcQ&format=segments&maxTokens=1000"
GET
/api/youtube/metadata
2 sats
Get video metadata without the transcript. Use as a cheap pre-check to see if a transcript exists and estimate its token count.
| Parameter | Type | Description |
|---|---|---|
videoId | string | YouTube video ID or full URL |
curl "https://agent-commerce.store/api/youtube/metadata?videoId=dQw4w9WgXcQ"
GET
/api/youtube/search
3 sats
Search within a video's transcript for keywords. Returns matching segments with timestamps and surrounding context.
| Parameter | Type | Description |
|---|---|---|
videoId | string | YouTube video ID or full URL |
query | string | Keyword or phrase to search for |
limit | int | Max results (1-50, default 10) |
curl "https://agent-commerce.store/api/youtube/search?videoId=dQw4w9WgXcQ&query=never+gonna&limit=5"
Usage tips: Accepts full YouTube URLs (youtube.com/watch?v=..., youtu.be/...) or bare 11-character video IDs. Not all videos have captions — use the metadata endpoint to check first. Auto-generated captions may contain transcription errors. Use maxTokens to fit transcripts into your LLM context window.
Value-Add
- Extracts and structures closed captions that are otherwise hard to access programmatically
- Token estimation helps agents plan LLM context window usage
- Smart truncation at segment boundaries (not mid-sentence)
- Keyword search with timestamps avoids ingesting full transcripts
- Prefers manual captions over auto-generated for better accuracy
- Accepts multiple URL formats — no need to parse video IDs yourself
Upstream Source
YouTube closed captions via YoutubeExplode.