A powerful API to fetch YouTube video transcripts, built with Hono and youtubei.js.
Deployment Options:
- π³ Docker/Coolify (Self-hosted, recommended for most users)
- βοΈ Cloudflare Workers (Serverless edge deployment)
Perfect for self-hosting on your own infrastructure.
# Clone and install
git clone <your-repo-url>
cd youtube-transcript-api
npm install
# Development mode with hot reload
npm run dev
# Or run with Docker Compose
npm run docker:upDeploy to Coolify: See COOLIFY_SETUP.md for step-by-step guide.
Deploy to Cloudflare's edge network for global performance.
# Development
npm run cf:dev
# Deploy to Cloudflare
npm run cf:deployFor Docker/Coolify:
- Node.js v18 or later
- Docker (optional for local testing)
- Coolify instance or any Docker-compatible hosting
For Cloudflare Workers:
# Clone repository
git clone <your-repo-url>
cd youtube-transcript-api
# Install dependencies
npm install# Hot reload development server (port 3000)
npm run dev
# Build for production
npm run build
# Run production build
npm start
# Docker development
npm run docker:up # Start with Docker Compose
npm run docker:logs # View logs
npm run docker:down # Stop containers# Local development (port 8787)
npm run cf:dev
# Generate TypeScript types for bindings
npm run cf:typegenFetches the transcript for a given YouTube video.
Query Parameters:
id(required): YouTube video ID or URL
Example Requests:
# Using video ID
curl "http://localhost:3000/?id=dQw4w9WgXcQ"
# Using full URL
curl "http://localhost:3000/?id=https://www.youtube.com/watch?v=dQw4w9WgXcQ"
# YouTube Shorts
curl "http://localhost:3000/?id=https://youtube.com/shorts/abc123"Success Response (200 OK):
{
"videoTitle": "Video Title Here",
"transcript": [
{
"text": "Hello and welcome...",
"offset": 0.5,
"duration": 3.2
},
{
"text": "In today's video...",
"offset": 3.7,
"duration": 2.8
}
]
}Error Responses:
| Status | Description |
|---|---|
400 |
Missing or invalid video ID/URL |
403 |
Video is private or unavailable |
404 |
No transcript available |
429 |
Rate limit exceeded (5 req/min) |
451 |
Region-locked video |
500 |
Server error |
Health check endpoint for monitoring.
Response:
{
"status": "ok",
"timestamp": "2024-11-12T10:30:00.000Z"
}Quick Deploy:
-
Push to Git:
git add . git commit -m "Deploy to Coolify" git push
-
Configure in Coolify:
- Create new Application
- Connect your Git repository
- Build Pack:
Dockerfile - Port:
3000 - Health Check:
/health
-
Deploy - Coolify handles the rest!
Detailed Guide: See COOLIFY_SETUP.md
Manual Docker Build:
# Build image
npm run docker:build
# Run container
npm run docker:run
# Or use Docker Compose
npm run docker:up# Login to Cloudflare
wrangler login
# Deploy
npm run cf:deployAfter deployment, Cloudflare will provide your worker URL.
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port (Docker/Node.js only) |
NODE_ENV |
production |
Environment mode |
Set in Docker Compose:
environment:
- PORT=3000
- NODE_ENV=productionSet in Coolify: Application β Environment Variables
Docker/Coolify:
- 5 requests per 60 seconds per IP
- In-memory store (configure in
server.ts)
Cloudflare Workers:
- 5 requests per 60 seconds per IP
- Cloudflare Rate Limiter binding (configure in
wrangler.toml)
| Feature | Docker/Coolify | Cloudflare Workers |
|---|---|---|
| Infrastructure | Your server | Cloudflare Edge |
| Cold Start | ~100-500ms | ~0ms |
| Cost | Fixed server cost | Pay-as-you-go |
| Scalability | Manual | Auto-scale globally |
| Control | Full control | Cloudflare managed |
| Best For | Self-hosting, privacy | Global performance |
- β Rate limiting per IP address
- β Input validation for video IDs
- β Non-root Docker user
- β Comprehensive error handling
- β Multi-stage Docker builds
- β No sensitive data exposure
- COOLIFY_SETUP.md - Quick Coolify deployment guide
- DEPLOYMENT.md - Comprehensive deployment documentation
- Dockerfile - Docker build configuration
- docker-compose.yml - Docker Compose setup
# Health check
curl http://localhost:3000/health
# Fetch transcript
curl "http://localhost:3000/?id=Ks-_Mh1QhMc" | jq
# Test rate limiting (run 6 times quickly)
for i in {1..6}; do curl "http://localhost:3000/health"; done| Script | Description |
|---|---|
npm run dev |
Development server with hot reload (Node.js) |
npm run build |
Build TypeScript to JavaScript |
npm start |
Start production server (Node.js) |
npm run docker:build |
Build Docker image |
npm run docker:run |
Run Docker container |
npm run docker:up |
Start with Docker Compose |
npm run docker:down |
Stop Docker Compose |
npm run docker:logs |
View Docker logs |
npm run cf:dev |
Cloudflare Workers dev server |
npm run cf:deploy |
Deploy to Cloudflare |
npm run cf:typegen |
Generate Cloudflare types |
# Change port
PORT=3001 npm start# Clear cache and rebuild
docker system prune -a
docker build --no-cache -t youtube-transcript-api .Edit server.ts (Docker) or wrangler.toml (Cloudflare):
// server.ts
const RATE_LIMIT_MAX = 10; // Increase from 5Some videos don't have transcripts. Check:
- Video is public
- Captions/subtitles are enabled
- Not a live stream or premiere
- Not region-locked
From Cloudflare Workers to Docker:
All features are preserved! The Docker version includes:
- β Same API endpoints
- β Equivalent rate limiting
- β Same error handling
- β Additional health check endpoint
From Docker to Cloudflare Workers:
The original Cloudflare Worker is still available:
- Use
index.tsinstead ofserver.ts - Deploy with
npm run cf:deploy - Configure in
wrangler.toml
We build tools to help you get the most out of YouTube videos:
-
YoutubeVideoTranscripts.com: Get transcripts of any YouTube video for free. Watch while reading, search within transcripts, and download for offline use.
-
YouTube Transcript Plus (Chrome Extension): Enhance YouTube with full transcript reading, AI chat with videos, and AI-generated chapter summaries.
This project is open source and available under your chosen license.
- Framework: Hono - Ultrafast web framework
- YouTube API: youtubei.js - YouTube API wrapper
- Runtime: Node.js 20+ / Cloudflare Workers
- Language: TypeScript
- Container: Docker with multi-stage builds
Ready to deploy? Check out COOLIFY_SETUP.md for the quickest path to production!