Phase 3: Video Generation · 55 min · Python · fal.ai API · Runway SDK
Multi-Provider Routing & Fallback
If Sora fails, try Veo. If Veo fails, try Kling. If all fail, fail gracefully — that's production video generation.
Hiring signal: Multi-provider routing with fallback chains is a core production engineering pattern — it's tested in system design interviews for video generation services.
What you will learn
- Build multi-provider routing: switch between Sora, Veo, Kling based on use case, cost, availability
- Implement fallback chains: if Sora fails → try Veo → try Kling → fail gracefully
- Implement cost-aware routing: cheap models for previews, expensive models for final output
- Handle content policy routing: if one provider rejects prompt, try alternative provider
The Problem
A production video generation service uses only Sora 2. During a product launch, Sora's API experiences downtime — all video generation requests fail. The team has no fallback. Customers see error messages. The launch is delayed. If they had multi-provider routing with fallback chains, the service would automatically switch to Veo or Kling when Sora fails, maintaining uptime.
Multi-provider routing with fallback chains is a core production engineering pattern. It's tested in system design interviews for video generation services.
What you'll build
A multi-provider router that switches between Sora, Veo, Kling, and Runway based on use case, cost, and availability. Implement fallback chains with automatic retry on failure. Handle content policy routing — if one provider rejects a prompt, try another.
Provider Routing Strategy
Use Case-Based Routing
class VideoRouter:
"""Routes video generation to the best provider based on use case."""
ROUTING = {
"social": {"primary": "pika", "fallback": ["kling", "runway"]},
"cinematic": {"primary": "veo", "fallback": ["sora", "kling"]},
"storytelling": {"primary": "sora", "fallback": ["veo", "kling"]},
"filmmaker": {"primary": "runway", "fallback": ["kling", "pika"]},
"fast": {"primary": "kling", "fallback": ["pika", "runway"]},
"preview": {"primary": "pika", "fallback": ["kling"]}, # Cheap for previews
"final": {"primary": "veo", "fallback": ["sora", "kling"]}, # Best quality for final
}
Cost-Aware Routing
# Use cheap models for previews, expensive models for final output
def route_by_stage(stage: str) -> str:
if stage == "preview":
return "pika" # $0.08 — cheap for iteration
elif stage == "review":
return "kling" # $0.25 — good quality for review
elif stage == "final":
return "veo" # $0.50 — best quality for delivery
A client needs 50 preview videos for A/B testing and 1 final hero video. How should you route these?
Use Pika ($0.08) for the 50 preview videos = $4.00, and Veo ($0.50) for the 1 final hero video = $0.50. Total: $4.50 vs $25.50 if using Sora/Veo for everything — a 5.7x cost savings. Previews don't need cinematic quality; the final does. This is cost-aware routing.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Fallback Chains, Content Policy Routing, Production Router Implementation, Circuit Breaker Pattern, Key Takeaways, What's Next — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy