Module 5: OpenRouter - Introduction

Module 5: OpenRouter - Introduction

What will you learn in this module?

So far you've used:

  • Module 2: OpenAI (1 provider)
  • Modules 3-4: Local (Mistral/Llama)

OpenRouter is an aggregator that gives you access to 100+ models from multiple providers with a single API:

  • OpenAI (GPT-3.5, GPT-4)
  • Anthropic (Claude 3)
  • Google (Gemini)
  • Meta (Llama)
  • Mistral AI
  • And 90+ more

Advantages:

  • ✅ One API key → 100+ models
  • ✅ Cost optimization (pick the cheapest model)
  • ✅ Automatic fallback (if one fails, try another)
  • ✅ No vendor lock-in
  • ✅ OpenAI SDK compatible

🎯 Module objective

Master OpenRouter: Multi-provider access

Deliverables:

  1. OpenRouter account + API key
  2. Access to multiple models (GPT, Claude, Gemini)
  3. Cost optimization strategy
  4. Automatic fallback
  5. Reusable unified client

Final project: A chatbot that auto-selects the optimal model


📋 Module structure

Phase 1: Setup (capsules 1-3)

  • 01: Introduction
  • 02: Account setup and API key
  • 03: First multi-provider requests

Phase 2: Optimization (capsules 4-5)

  • 04: Cost optimization
  • 05: Fallback strategies

Phase 3: Advanced (capsules 6-7)

  • 06: Automatic model selection
  • 07: Provider comparison

Phase 4: Project (capsule 8)

  • 08: Mini-project - Smart chatbot

🔗 Connections with other modules

Reuses code from:

  • Module 2 (OpenAI SDK) - 100% compatible

Comparison:

FeatureOpenAIOpenRouter
ModelsGPT-3.5/4100+
Providers1 (OpenAI)10+
Fallback
CostFixedVariable

⏱️ Estimated time

Total: 2-3 hours

Breakdown:

  • Setup: 30 min
  • Multi-provider: 45 min
  • Optimization: 45 min
  • Project: 60 min

🛠️ Skills you'll develop

Technical:

  1. OpenRouter API:

    • Multi-provider access
    • Model switching
    • Cost comparison
  2. Optimization:

    • Auto-select the cheap model
    • Fallback chains
    • Cost tracking
  3. Production:

    • Vendor diversification
    • High availability
    • Cost efficiency

💰 Cost

OpenRouter:

  • Signup: Free
  • Initial credits: $1 (some users)
  • Pay-as-you-go afterward

Pricing: Variable by model

  • GPT-3.5: $0.50/1M tokens (same as OpenAI)
  • Claude 3 Haiku: $0.25/1M (50% cheaper)
  • Mixtral: $0.24/1M (95% cheaper vs GPT-4)

🎯 Why OpenRouter

Problem: Vendor lock-in

If you only use OpenAI:

  • You depend on one provider
  • If OpenAI raises prices: No alternative
  • If the API is down: Your app is down

Solution: OpenRouter

  • Switch model in 1 line of code
  • Automatic fallback
  • Cost optimization

📊 What you'll build

Final project:

An intelligent chatbot that:

  • Simple queries → cheap model (Mixtral)
  • Complex queries → powerful model (GPT-4)
  • If it fails → automatic fallback
  • Cost dashboard

✅ Success criteria

  • OpenRouter account created
  • You tried 3+ different models
  • You implemented fallback
  • You compared costs
  • Chatbot with auto-selection works

🔗 Resources

  1. OpenRouter.ai - Official site
  2. Docs - API reference
  3. Models - Full list
  4. Pricing - Comparison

🚀 Get started

Next: 02-account-setup.md

You'll create an OpenRouter account and get your API key.

Time: 15 min
Difficulty: Low


Total time: 2-3 hours
Next: 02-account-setup.md