DEV Community

Support ExpatHub
Support ExpatHub

Posted on

How I Built an AI YouTube Analytics SaaS with Next.js and Claude API (and kept costs under $2/user/month)

I recently launched CreatorPilot, an AI-powered YouTube analytics platform. Here's how I built it and the technical decisions I made.

The Problem

Most YouTube creators manually copy their analytics into ChatGPT to figure out why their videos perform the way they do. It's tedious and the advice is generic because ChatGPT doesn't actually know your channel data.

The Solution

Connect directly to YouTube Analytics API and feed real channel data into Claude AI to generate specific, actionable insights.

Tech Stack

  • Frontend/Backend: Next.js 14 (App Router)
  • Database: PostgreSQL + Prisma ORM (Neon)
  • AI: Anthropic Claude API
  • Auth: NextAuth.js with Google OAuth
  • Payments: Stripe
  • Deployment: Vercel

The Cost Optimization Challenge

Claude Sonnet costs $3/1M input tokens. With 5 AI features per user, naive implementation would cost $5-7/user/month — killing margins.

Solution: Aggressive DB caching

Feature Cache Duration Model
Video Analysis 24 hours Haiku
Daily Trend 24 hours Haiku
Action Plan 24 hours Haiku
20 Video Recs 170 hours Haiku
Channel Pattern 170 hours Sonnet

Result: ~$1.35/user/month worst case, ~$0.41 average. Gross margin ~90%.

Key Technical Challenges

1. YouTube API Quota Management
YouTube Data API has a 10,000 quota/day limit. Solved by caching video data in PostgreSQL and only calling the API when cache expires.

2. Multilingual AI Responses
Supporting 5 languages (EN, KO, JA, DE, ZH) with consistent quality required careful prompt engineering — especially for Korean historical content analysis.

3. Rate Limiting Without Redis
Built a PostgreSQL-based rate limiting fallback when Redis is unavailable.

Results

Launched today. Would love feedback from fellow developers.

https://creatorpilothq.com

Top comments (1)

Collapse
 
mamoor_ahmad profile image
Mamoor Ahmad

Good work... 👍👍