Get the FREE Ultimate OpenClaw Setup Guide →
n

YouTube API CLI

Verified

@nerveband

npx machina-cli add skill @nerveband/yt-api-cli --openclaw
Files (1)
SKILL.md
4.5 KB

yt-api-cli

Manage your YouTube account from the terminal. A complete CLI for the YouTube Data API v3.

Installation

# Using go install
go install github.com/nerveband/youtube-api-cli/cmd/yt-api@latest

# Or download from releases
curl -L -o yt-api https://github.com/nerveband/youtube-api-cli/releases/latest/download/yt-api-darwin-arm64
chmod +x yt-api
sudo mv yt-api /usr/local/bin/

Setup

1. Google Cloud Console Setup

  1. Go to Google Cloud Console
  2. Create/enable YouTube Data API v3
  3. Create OAuth 2.0 credentials (Desktop app)
  4. Download client configuration

2. Configure yt-api

mkdir -p ~/.yt-api
cat > ~/.yt-api/config.yaml << EOF
default_auth: oauth
default_output: json
oauth:
  client_id: "YOUR_CLIENT_ID"
  client_secret: "YOUR_CLIENT_SECRET"
EOF

3. Authenticate

yt-api auth login  # Opens browser for Google login
yt-api auth status # Check auth state

Commands

List Operations

# List your videos
yt-api list videos --mine

# List channel videos
yt-api list videos --channel-id UC_x5XG1OV2P6uZZ5FSM9Ttw

# List playlists
yt-api list playlists --mine

# List subscriptions
yt-api list subscriptions --mine

Search

# Basic search
yt-api search --query "golang tutorial"

# With filters
yt-api search --query "music" --type video --duration medium --order viewCount

Upload Operations

# Upload video
yt-api upload video ./video.mp4 \
  --title "My Video" \
  --description "Description here" \
  --tags "tag1,tag2" \
  --privacy public

# Upload thumbnail
yt-api upload thumbnail ./thumb.jpg --video-id VIDEO_ID

Playlist Management

# Create playlist
yt-api insert playlist --title "My Playlist" --privacy private

# Add video to playlist
yt-api insert playlist-item --playlist-id PLxxx --video-id VIDxxx

Channel Operations

# Get channel info
yt-api list channels --id UCxxx --part snippet,statistics

# Update channel description
yt-api update channel --id UCxxx --description "New description"

Output Formats

# JSON (default - LLM-friendly)
yt-api list videos --mine

# Table (human-readable)
yt-api list videos --mine -o table

# YAML
yt-api list videos --mine -o yaml

# CSV
yt-api list videos --mine -o csv > videos.csv

Global Flags

FlagShortDescription
--output-oOutput format: json (default), yaml, csv, table
--quiet-qSuppress stderr messages
--configPath to config file
--auth-typeAuth method: oauth (default), service-account

Environment Variables

VariableDescription
YT_API_AUTH_TYPEAuth method: oauth or service-account
YT_API_OUTPUTDefault output format
YT_API_CLIENT_IDOAuth client ID
YT_API_CLIENT_SECRETOAuth client secret
YT_API_CREDENTIALSPath to service account JSON

Authentication Methods

OAuth 2.0 (Default)

Best for interactive use and accessing your own YouTube account.

yt-api auth login  # Opens browser

Service Account

Best for server-side automation.

yt-api --auth-type service-account --credentials ./key.json list videos

Quick Diagnostic Commands

yt-api info                      # Full system state
yt-api info --test-connectivity  # Verify API access
yt-api info --test-permissions   # Check credential capabilities
yt-api auth status               # Authentication details
yt-api version                   # Version info

Error Handling

Exit codes:

  • 0 - Success
  • 1 - General error
  • 2 - Authentication error
  • 3 - API error (quota, permissions)
  • 4 - Input error

For LLMs and Automation

  • JSON output by default
  • Structured errors as JSON objects
  • --quiet mode for parsing
  • --dry-run validates without executing
  • Stdin support for piping data

Notes

  • Requires valid Google Cloud credentials with YouTube Data API v3 enabled
  • OAuth tokens stored in ~/.yt-api/tokens.json (0600 permissions)
  • Default output is JSON (LLM-optimized)
  • Supports all YouTube Data API v3 resources

Source

GitHub: https://github.com/nerveband/youtube-api-cli

Source

git clone https://clawhub.ai/nerveband/yt-api-cliView on GitHub

Overview

Manage your YouTube account from the terminal with a complete CLI for the YouTube Data API v3. It supports listing and searching videos, uploading content, managing playlists, and more, via commands that map to API endpoints. It also handles authentication (OAuth or service accounts), a config file, and flexible output formats for automation.

How This Skill Works

The tool is a Go-based CLI that reads ~/.yt-api/config.yaml to set default auth and output, and uses YT_API_* environment variables for credentials. Commands like list, search, upload, insert, and update call the YouTube Data API v3 and print results in JSON by default, with options for table, yaml, or csv output.

When to Use It

  • Managing your YouTube channel from the terminal
  • Automating uploads, thumbnails, and playlist management
  • Scripting searches and data extraction for analytics
  • CI/CD pipelines or batch workflows that publish videos
  • Working with a service account for server-side automation

Quick Start

  1. Step 1: Install the CLI with go install github.com/nerveband/youtube-api-cli/cmd/yt-api@latest or download a release
  2. Step 2: Create ~/.yt-api/config.yaml with default_auth and your OAuth client_id/client_secret
  3. Step 3: Run yt-api auth login to authenticate and start using the CLI

Best Practices

  • Securely store credentials in ~/.yt-api/config.yaml and use environment variables for secrets
  • Run yt-api auth login to complete OAuth flow before making API calls
  • Scope requests using --mine or specific IDs to minimize data and quota usage
  • Validate video metadata (title, description, tags) prior to upload to avoid policy issues
  • Use --output formats (json/yaml/table/csv) for automation and logging; monitor quotas

Example Use Cases

  • List your videos: yt-api list videos --mine
  • List channel videos: yt-api list videos --channel-id UC_x5XG1OV2P6uZZ5FSM9Ttw
  • Search: yt-api search --query golang tutorial --type video --order viewCount
  • Upload video: yt-api upload video ./video.mp4 --title My Video --description Description --tags tag1,tag2 --privacy public
  • Create playlist and add video: yt-api insert playlist --title My Playlist --privacy private; yt-api insert playlist-item --playlist-id PLxxx --video-id VIDxxx

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers