import{c as t,Q as a,j as i,m as e}from"./chunks/framework.BPKcPtvA.js";const c=JSON.parse('{"title":"Cascade Routing: Cut Your API Costs by 66%","description":"","frontmatter":{},"headers":[],"relativePath":"blog/posts/cascade-routing.md","filePath":"blog/posts/cascade-routing.md","lastUpdated":1780488472000}'),n={name:"blog/posts/cascade-routing.md"};function l(h,s,p,d,o,r){return a(),i("div",null,[...s[0]||(s[0]=[e(`<h1 id="cascade-routing-cut-your-api-costs-by-66" tabindex="-1">Cascade Routing: Cut Your API Costs by 66% <a class="header-anchor" href="#cascade-routing-cut-your-api-costs-by-66" aria-label="Permalink to &quot;Cascade Routing: Cut Your API Costs by 66%&quot;">​</a></h1><p><strong>June 11, 2026</strong></p><p>Most teams use one model for everything. They default to Claude Opus or GPT-5 for every task, which means they are paying premium prices for simple work.</p><h2 id="the-price-range" tabindex="-1">The Price Range <a class="header-anchor" href="#the-price-range" aria-label="Permalink to &quot;The Price Range&quot;">​</a></h2><table tabindex="0"><thead><tr><th>Model</th><th>Input ($/M)</th><th>Output ($/M)</th></tr></thead><tbody><tr><td>Gemini 2.5 Flash</td><td>$0.15</td><td>$0.60</td></tr><tr><td>DeepSeek V3</td><td>$0.27</td><td>$1.10</td></tr><tr><td>Claude Sonnet 4</td><td>$3.00</td><td>$15.00</td></tr><tr><td>Claude Opus 4</td><td>$15.00</td><td>$75.00</td></tr></tbody></table><p>That is a 100x range between the cheapest and most expensive.</p><h2 id="the-cascade-pattern" tabindex="-1">The Cascade Pattern <a class="header-anchor" href="#the-cascade-pattern" aria-label="Permalink to &quot;The Cascade Pattern&quot;">​</a></h2><p>Route different steps to different models. Use cheap models for simple retrieval and formatting. Use expensive models only for complex reasoning.</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>Retrieve context -&gt; Gemini Flash ($0.15/$0.60)</span></span>
<span class="line"><span>Analyze data     -&gt; Claude Sonnet ($3/$15)</span></span>
<span class="line"><span>Make decision    -&gt; Claude Opus ($15/$75)</span></span>
<span class="line"><span>Format output    -&gt; Gemini Flash ($0.15/$0.60)</span></span></code></pre></div><h2 id="the-savings" tabindex="-1">The Savings <a class="header-anchor" href="#the-savings" aria-label="Permalink to &quot;The Savings&quot;">​</a></h2><table tabindex="0"><thead><tr><th>Pattern</th><th>Cost/Task</th><th>Savings</th></tr></thead><tbody><tr><td>All Opus</td><td>$2.50</td><td>Baseline</td></tr><tr><td>Cascade</td><td>$0.85</td><td>66%</td></tr><tr><td>All Sonnet</td><td>$0.50</td><td>80% (but quality loss on complex steps)</td></tr></tbody></table><h2 id="implementation" tabindex="-1">Implementation <a class="header-anchor" href="#implementation" aria-label="Permalink to &quot;Implementation&quot;">​</a></h2><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> route_task</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(task_complexity: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">str</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> task_complexity </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;retrieval&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;gemini-2.5-flash&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> task_complexity </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;analysis&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;claude-sonnet-4&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> task_complexity </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;decision&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;claude-opus-4&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    elif</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> task_complexity </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">==</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;formatting&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;gemini-2.5-flash&quot;</span></span></code></pre></div><h2 id="when-not-to-cascade" tabindex="-1">When Not to Cascade <a class="header-anchor" href="#when-not-to-cascade" aria-label="Permalink to &quot;When Not to Cascade&quot;">​</a></h2><p>If your task is a single critical decision, use the best model. Cascade routing shines when you have a pipeline of steps with varying complexity, which is most real-world agent systems.</p><hr><p><em>From Module 6 of the <a href="/">Agentic Engineering Course</a>. The full module includes a cost optimization lab with working code.</em></p>`,17)])])}const u=t(n,[["render",l]]);export{c as __pageData,u as default};
