The Model Switchboard

Difficulty: HARDID: finops-model-router

The Scenario

You have access to two models:

  1. "Haiku-Flash" (Cheap): $0.10 / M tokens. Fast, good for simple tasks.
  2. "Opus" (Expensive): $15.00 / M tokens. Slow, needed for complex reasoning.

The Problem: Your team routes everything to Opus-Ultra. Your bill is $50,000/month. 90% of your queries are "Summarize this email" or "Extract the date"—tasks Haiku could do for $300.

The Goal

Implement a Cost Router (The Switchboard):

  1. Analyze Complexity: Check query length or keywords.
    • If length < 100 chars -> Use Cheap Model.
    • If length >= 100 chars -> Use Expensive Model.
  2. Fallback is Mandatory: If Cheap Model fails, fallback to Expensive. If Expensive fails, raise error.
  3. Savings: The test will spam short queries and verify your bill stays low.

Requirements:

  • Implement route_and_generate(prompt, client).
  • Short queries (< 100 chars) MUST attempt haiku-flash first.
  • Long queries (>= 100 chars) MUST use opus.
  • All failures must attempt fallback to the other model (if sensible) or just the robust one.
solution.py
Loading...
⚠️ Do not include PII or secrets in your code.
SYSTEM_LOGS
5/5
// Waiting for execution trigger...
PREVIEW MODE — SOLVE PREVIOUS MISSIONS TO UNLOCK