<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TokenLat</title>
    <description>The latest articles on DEV Community by TokenLat (@tokenlat).</description>
    <link>https://dev.to/tokenlat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4028280%2F94d16010-df94-45df-aee5-7d51647fcb74.png</url>
      <title>DEV Community: TokenLat</title>
      <link>https://dev.to/tokenlat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tokenlat"/>
    <language>en</language>
    <item>
      <title>Cache affinity in practice: 5 patterns that keep your agent's prompt cache warm</title>
      <dc:creator>TokenLat</dc:creator>
      <pubDate>Tue, 11 Aug 2026 07:46:05 +0000</pubDate>
      <link>https://dev.to/tokenlat/cache-affinity-in-practice-5-patterns-that-keep-your-agents-prompt-cache-warm-3a9m</link>
      <guid>https://dev.to/tokenlat/cache-affinity-in-practice-5-patterns-that-keep-your-agents-prompt-cache-warm-3a9m</guid>
      <description>&lt;p&gt;You shipped an agent. Tokens/month exploded. You switched to a "cheaper" model and the bill barely moved.&lt;/p&gt;

&lt;p&gt;Here's the thing nobody prints on the pricing page: in a loop, the model price is often a rounding error next to the &lt;strong&gt;repeat tax&lt;/strong&gt; — and the repeat tax is, at its core, a &lt;em&gt;cache-affinity&lt;/em&gt; problem.&lt;/p&gt;

&lt;p&gt;This is the practical follow-up to &lt;em&gt;why agentic systems should care about cache-hit pricing&lt;/em&gt;. That post argued the cost lives in cache behavior, not in raw model price. This one is about what you can actually do about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What prefix caching actually rewards
&lt;/h2&gt;

&lt;p&gt;Most providers (OpenAI, Gemini, Anthropic, and the OpenAI-compatible gateways on top of them) offer &lt;em&gt;automatic&lt;/em&gt; prefix caching: if the start of your prompt is byte-for-byte identical to a previous request, the cached tokens cost a fraction of a fresh input token.&lt;/p&gt;

&lt;p&gt;The keyword is &lt;strong&gt;byte-for-byte identical&lt;/strong&gt;, and it only helps if the identical part sits at the &lt;em&gt;front&lt;/em&gt; of the prompt. Reorder one line, inject a timestamp above the system prompt, or re-serialize history with a fresh UUID, and you've evicted your own cache. The model never sees the hit — you just pay full input, every step.&lt;/p&gt;

&lt;p&gt;So "cheaper model" optimizes the wrong number. The lever is &lt;strong&gt;cache affinity&lt;/strong&gt;: how stable is your prefix across the loop?&lt;/p&gt;

&lt;h2&gt;
  
  
  5 patterns that keep the cache warm
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stable system prompt + fixed tool schemas at the very top.&lt;/strong&gt; Tools definitions rarely change between steps. Put them first, verbatim, and stop touching them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Append-only history.&lt;/strong&gt; Don't re-serialize the whole conversation each step. Keep a canonical transcript and &lt;em&gt;append&lt;/em&gt;; let the unchanged prefix stay cached.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inject volatile context &lt;em&gt;after&lt;/em&gt; the stable prefix.&lt;/strong&gt; Scratchpads, retrieved docs, and tool results are fine — as long as they sit below the system prompt + history, not above it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Route the easy 80% to a small model, but preserve the shared prefix.&lt;/strong&gt; Routing by scenario is smart. Just don't let the small model re-format the prefix; a different tokenizer can silently break the cache.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;One gateway, one canonical formatter.&lt;/strong&gt; When three sub-agents each format "the context" their own way, you get three incompatible prefixes and zero cache reuse. Centralize prompt assembly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  5 patterns that evict your cache (the O(n²) traps)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Re-sending the entire conversation every step.&lt;/strong&gt; Frameworks that replay full memory each turn pay O(n²) tokens over a session. The prefix can never stabilize.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Re-serializing history with a timestamp or UUID in the prefix.&lt;/strong&gt; A new &lt;code&gt;updated_at&lt;/code&gt; each call = a new prefix = no cache, forever.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Putting volatile content &lt;em&gt;above&lt;/em&gt; the stable prefix.&lt;/strong&gt; Current time, request id, trace id — if it's before the system prompt, it poisons every cache hit downstream.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixing tokenizers across models without a stable canonical form.&lt;/strong&gt; Switching models mid-loop without canonicalizing the prefix resets the cache and doubles your input cost.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No observability.&lt;/strong&gt; If you can't see &lt;em&gt;cache hit vs miss&lt;/em&gt; per request, you can't tell which of the above you're doing. You're flying blind on the single biggest cost lever.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The trace you're missing
&lt;/h2&gt;

&lt;p&gt;The fix that makes everything else measurable is boring but decisive: a &lt;strong&gt;per-request trace&lt;/strong&gt; that reports, for every call, whether the prefix hit cache and how many tokens were charged vs cached.&lt;/p&gt;

&lt;p&gt;Once you have that, the O(n²) traps show up as a line item. You stop guessing and start watching the cache-hit ratio the way you watch p99 latency. That's the difference between "we cut model cost" and "we cut agent cost."&lt;/p&gt;

&lt;h2&gt;
  
  
  Landing AI means making this the default
&lt;/h2&gt;

&lt;p&gt;"AI 落地" (getting AI into production) is sold as a model-access problem. It isn't. Access is solved. The hard part is the boring operational layer: warm caches, visible traces, sane routing — by default, not as a heroic refactor after the bill arrives.&lt;/p&gt;

&lt;p&gt;If you want a gateway that surfaces cache-hit/miss per request and keeps one canonical prefix across models, that's the whole point of what we're building at TokenLat: &lt;a href="https://tokenlat.com" rel="noopener noreferrer"&gt;https://tokenlat.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>machinelearning</category>
      <category>automation</category>
    </item>
    <item>
      <title>Why agentic systems should care about cache-hit pricing</title>
      <dc:creator>TokenLat</dc:creator>
      <pubDate>Fri, 07 Aug 2026 08:32:46 +0000</pubDate>
      <link>https://dev.to/tokenlat/why-agentic-systems-should-care-about-cache-hit-pricing-9j9</link>
      <guid>https://dev.to/tokenlat/why-agentic-systems-should-care-about-cache-hit-pricing-9j9</guid>
      <description>&lt;p&gt;The metric that quietly decides your agent bill isn't the input price of your model. It's how much you pay to read what you already sent.&lt;/p&gt;

&lt;p&gt;If you run multi-step agents, you've probably had this moment: a task you &lt;em&gt;expected&lt;/em&gt; to cost pennies comes back as a small surprise on the invoice. You didn't change models. You didn't prompt more. So where did the tokens go?&lt;/p&gt;

&lt;p&gt;Most of the time, they went to paying for the same context, again and again.&lt;/p&gt;

&lt;h2&gt;
  
  
  A 2-minute task can fire 40+ billable calls
&lt;/h2&gt;

&lt;p&gt;Here's a shape I keep seeing. An agent does a "2-minute" job:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reads a file&lt;/li&gt;
&lt;li&gt;drafts a plan&lt;/li&gt;
&lt;li&gt;calls a tool&lt;/li&gt;
&lt;li&gt;reflects on the result&lt;/li&gt;
&lt;li&gt;retries&lt;/li&gt;
&lt;li&gt;summarizes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each step is an LLM call. And each call re-sends the same scaffolding: the system prompt, the task description, and — critically — the growing conversation history. A step that adds 200 new tokens of &lt;em&gt;thinking&lt;/em&gt; can still carry 4,000 tokens of &lt;em&gt;context it already paid for once&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Multiply that across 40 steps and the math stops being about "model price." It's about &lt;strong&gt;how many times you re-pay for context you already have&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What cache-hit pricing actually is
&lt;/h2&gt;

&lt;p&gt;Normal input pricing charges you per token you send, every time. Cache-hit pricing changes the unit: if the provider already has your prefix cached (because you sent it recently and it hasn't expired), the &lt;em&gt;read&lt;/em&gt; of that cached prefix is billed at a deep discount instead of full input price.&lt;/p&gt;

&lt;p&gt;On a unified gateway this is visible per model. Two concrete examples from the model catalog:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DeepSeek-v4-Pro: &lt;strong&gt;¤10 / 1M tokens for a cached read&lt;/strong&gt; (¤ is the platform's billing unit)&lt;/li&gt;
&lt;li&gt;Qwen3.5-plus: &lt;strong&gt;¤20 / 1M tokens for a cached read&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those aren't the full input rates — they're the &lt;em&gt;cached-read&lt;/em&gt; rates, and that's the number that matters for agentic workloads, because agentic workloads are mostly repeats.&lt;/p&gt;

&lt;p&gt;The takeaway isn't "this model is cheaper." It's: &lt;strong&gt;for any loop that re-sends context, cached-read price is the real marginal cost, and most teams optimize for the wrong number.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The math that actually moves the bill
&lt;/h2&gt;

&lt;p&gt;Skip the exact figures and look at the shape. Say a loop runs 40 calls, and each carries ~4k tokens of repeated context plus ~200 tokens of new content.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pay full input on every repeated token: you're billed for 4k × 40 = 160k "new" tokens that were actually old.&lt;/li&gt;
&lt;li&gt;Pay cached-read on the repeated prefix: that 160k drops to a fraction — the cached-read rate instead of full input.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the two models above, cached reads land at ¤10–¤20 / 1M versus full input that's multiple times higher. The loop's cost doesn't go to zero, but the &lt;em&gt;repeat tax&lt;/em&gt; collapses. In agentic systems, the repeat tax is most of the bill — so this is where the 70%+ savings actually live, not in "pick a cheaper model."&lt;/p&gt;

&lt;h2&gt;
  
  
  You can't optimize what you can't see
&lt;/h2&gt;

&lt;p&gt;There's a trap here. Cache-hit pricing only helps if you can see hits and misses. A black-box API that just returns text hides the one number you need: &lt;strong&gt;was this token a cache hit or a fresh charge?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A request trace makes it observable. Each call should expose its stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REQUEST — what came in&lt;/li&gt;
&lt;li&gt;AUTH — who/what called&lt;/li&gt;
&lt;li&gt;ROUTE — which model served it&lt;/li&gt;
&lt;li&gt;RESPONSE — what came back&lt;/li&gt;
&lt;li&gt;METER — what it cost, including cache hit/miss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When every call shows its cache hit/miss and per-stage cost, the loop stops being a mystery. You can see &lt;em&gt;which step&lt;/em&gt; blows the budget and &lt;em&gt;whether your prefix is actually staying warm&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Routing + cache affinity is the real lever
&lt;/h2&gt;

&lt;p&gt;Cache-hit pricing is necessary but not sufficient. The other half is &lt;strong&gt;keeping the cache warm&lt;/strong&gt;, and that's a routing problem.&lt;/p&gt;

&lt;p&gt;The 80/20 pattern holds: route the easy 80% of calls to a small/fast model, keep frontier for the hard 20%. But the part people miss is &lt;em&gt;cache affinity&lt;/em&gt; — if you keep the same system prompt and stable prefix across the loop, the cache stays warm and the cheap reads keep hitting. Change the prefix on every step (reformat the history, rewrite the system prompt, shuffle the order) and you silently evict your own cache. You pay full input forever.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;model: "auto"&lt;/code&gt; style routing behind one OpenAI-compatible endpoint, the loop doesn't have to think about which model serves which step — but it still has to respect cache affinity, because that's what turns "cheap model" into "cheap &lt;em&gt;and&lt;/em&gt; cached."&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical cache-friendly checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Keep the system prompt and stable prefix byte-identical across loop steps&lt;/li&gt;
&lt;li&gt;Append new content; don't rebuild the whole context each time&lt;/li&gt;
&lt;li&gt;Prefer providers/models that expose cache-hit pricing and a request trace&lt;/li&gt;
&lt;li&gt;Watch cache hit rate per step, not just total spend&lt;/li&gt;
&lt;li&gt;Route by task, but preserve prefix stability so the cache survives&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The point
&lt;/h2&gt;

&lt;p&gt;Agentic cost isn't a model-selection problem. It's a &lt;strong&gt;repeat-tax&lt;/strong&gt; problem: how many times you pay to read context you already sent, and whether you can see it happening.&lt;/p&gt;

&lt;p&gt;Cache-hit pricing + request trace + cache-friendly routing is the combination that turns a scary agent bill into a boring one. Most teams optimize the first and ignore the other two — which is why their invoices still surprise them.&lt;/p&gt;

&lt;p&gt;If you want the routing playbook that pairs with this (the 80/20 split and how to keep the cache warm), it's at &lt;a href="https://tokenlat.com" rel="noopener noreferrer"&gt;https://tokenlat.com&lt;/a&gt; — but the idea stands on its own: &lt;strong&gt;stop counting input price. Start counting cache hits.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>The 80/20 routing playbook: cut your AI agent bill 70%+ without touching quality</title>
      <dc:creator>TokenLat</dc:creator>
      <pubDate>Fri, 31 Jul 2026 04:43:52 +0000</pubDate>
      <link>https://dev.to/tokenlat/the-8020-routing-playbook-cut-your-ai-agent-bill-70-without-touching-quality-21ai</link>
      <guid>https://dev.to/tokenlat/the-8020-routing-playbook-cut-your-ai-agent-bill-70-without-touching-quality-21ai</guid>
      <description>&lt;h1&gt;
  
  
  The 80/20 routing playbook: cut your AI agent bill 70%+ without touching quality
&lt;/h1&gt;

&lt;p&gt;Your agent's token bill is probably 5x higher than it needs to be — not because the models are expensive, but because of &lt;em&gt;routing discipline&lt;/em&gt;. Most teams wire every call to one frontier model and call it a day. This post is the practical fix: how to send the easy 80% of agent calls to cheap models, keep frontier for the hard 20%, and not lose a point of quality doing it.&lt;/p&gt;

&lt;p&gt;Everything below uses real numbers from a gateway that exposes 22 models across 8 providers behind one OpenAI-compatible API.&lt;/p&gt;




&lt;h2&gt;
  
  
  The default that's costing you
&lt;/h2&gt;

&lt;p&gt;Here's the shape of a typical agent loop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;classify the request&lt;/li&gt;
&lt;li&gt;extract structured fields&lt;/li&gt;
&lt;li&gt;pick a tool&lt;/li&gt;
&lt;li&gt;call the tool, parse the result&lt;/li&gt;
&lt;li&gt;summarize what happened&lt;/li&gt;
&lt;li&gt;decide the next step&lt;/li&gt;
&lt;li&gt;draft the reply&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Of those, maybe one or two steps actually need frontier-level reasoning. The rest are classification, extraction, and formatting — work that a fast, cheap model does &lt;em&gt;indistinguishably&lt;/em&gt; from a flagship. Yet most setups send all of it to &lt;code&gt;gpt-5.5&lt;/code&gt; (or whatever their default is) because it's the path of least resistance.&lt;/p&gt;

&lt;p&gt;That's the tax. You're paying flagship prices for steps that don't need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 80/20 split, with the math
&lt;/h2&gt;

&lt;p&gt;Route by &lt;em&gt;task difficulty&lt;/em&gt;, not by &lt;em&gt;model loyalty&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Easy 80%&lt;/strong&gt; — classification, extraction, summarization, short tool-formatting, routing decisions → a fast China-model tier&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Medium 15%&lt;/strong&gt; — coding, planning, multi-step reasoning → a strong reasoning tier&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hard 5%&lt;/strong&gt; — the genuinely gnarly frontier cases → flagship, reserved&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A blended-cost estimate (input tokens, per 1M):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;80% × ¤160   (cheap tier input)   = ¤128
15% × ¤560   (reasoning tier)     = ¤84
 5% × ¤7000  (flagship input)     = ¤350
---------------------------------------
blended input cost               ≈ ¤562 / 1M
vs. all-flagship                 = ¤7000 / 1M
savings                          ≈ 70%+ in this example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even with a more conservative split, &lt;strong&gt;70%+ cheaper is the floor&lt;/strong&gt; — and quality doesn't move, because the hard calls still go to frontier.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap: why "just use the cheapest model" backfires
&lt;/h2&gt;

&lt;p&gt;Naive cost-cutting picks one cheap model for everything. That fails for two reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Quality cliffs.&lt;/strong&gt; A ¤160/1M model is great at extraction and terrible at planning a 12-file refactor. Push hard tasks down and users notice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache invalidation (the silent tax).&lt;/strong&gt; This is the one almost nobody budgets for. Long agent conversations re-send the system prompt + tool definitions on &lt;em&gt;every&lt;/em&gt; turn. If you switch providers mid-conversation, you reset prompt-cache affinity and re-pay the full prefix each turn. A conversation that &lt;em&gt;should&lt;/em&gt; be cheap suddenly isn't.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The win isn't "use a cheap model" — it's &lt;strong&gt;routing discipline with cache affinity intact&lt;/strong&gt;: pin the easy 80% to a &lt;em&gt;stable&lt;/em&gt; cheap model so the cache stays warm, and only escalate to frontier for the calls that earn it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a real routing layer looks like
&lt;/h2&gt;

&lt;p&gt;With a unified gateway, this is roughly ten lines. One API, models swapped by &lt;code&gt;model:&lt;/code&gt; — no per-provider SDK juggling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;complexity&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;easy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;        &lt;span class="c1"&gt;# classify, extract, summarize
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TokenLat-deepseek-v4-Flash&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;   &lt;span class="c1"&gt;# ¤160/1M input
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;needs_reasoning&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;             &lt;span class="c1"&gt;# code, plan, multi-step
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TokenLat-deepseek-v4-Pro&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;     &lt;span class="c1"&gt;# ¤560/1M input, ¤10/1M cache read
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chatgpt-5.5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;                 &lt;span class="c1"&gt;# frontier, only the hard 5%
&lt;/span&gt;
&lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or skip the router entirely and let the gateway decide per call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;auto&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;          &lt;span class="c1"&gt;# gateway picks the right tier per request
&lt;/span&gt;    &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;model: "auto"&lt;/code&gt; is the zero-config version of the same idea — the gateway applies routing policy so you don't hand-roll it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real numbers from a 25-model gateway
&lt;/h2&gt;

&lt;p&gt;A unified gateway should show you its pricing up front. Per 1M tokens, in credits (¤), here's a slice (input / cache-read):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-deepseek-v4-Flash&lt;/code&gt; — cheap / fast tier → ¤160 / ¤40&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-qwen3.5-plus&lt;/code&gt; — general tier → ¤130 / ¤20&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-deepseek-v4-Pro&lt;/code&gt; — reasoning tier → ¤560 / &lt;strong&gt;¤10&lt;/strong&gt; (lowest cache-read)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-glm-5.1&lt;/code&gt; — Chinese-stable → ¤950 / ¤160&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-kimi-k3&lt;/code&gt; — flagship (China) → ¤3000 / ¤300&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gemini-3.1-pro&lt;/code&gt; — frontier → ¤2800 / ¤300&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;chatgpt-5.5&lt;/code&gt; — frontier → ¤7000 / ¤700&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The headline gap: cheap-tier input is ~44x cheaper than flagship input. That's the entire 80/20 argument in one line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache-hit pricing — the agentic loophole
&lt;/h2&gt;

&lt;p&gt;For agentic systems, the &lt;em&gt;input&lt;/em&gt; price is almost a distraction. What matters is the &lt;strong&gt;cache-read&lt;/strong&gt; price, because the static prefix (system prompt, tool schemas, retrieved context) gets re-sent every turn.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-deepseek-v4-Pro&lt;/code&gt; caches reads at &lt;strong&gt;¤10/1M&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TokenLat-qwen3.5-plus&lt;/code&gt; at &lt;strong&gt;¤20/1M&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So a long-running agent loop that pins a stable model and keeps its prefix cached can serve most turns at the cache-read rate — a fraction of the input rate. The providers that reset your cache on every switch quietly erase this saving. Cache affinity is a routing decision, not an afterthought.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make it visible
&lt;/h2&gt;

&lt;p&gt;You can't optimize what you can't see. Every request through a proper gateway should leave a trace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;REQUEST → AUTH → ROUTE(auto→text-pro) → RESPONSE → METER
region: SEA | status: 200 OK | latency: 842ms | tokens: 1,284 | cost: ¤0.0048
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Five stages, one line, per call. When a bill spikes, you see &lt;em&gt;which&lt;/em&gt; model, &lt;em&gt;which&lt;/em&gt; route, and &lt;em&gt;which&lt;/em&gt; request — instead of staring at a monthly total and guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't guess — measure quality
&lt;/h2&gt;

&lt;p&gt;The one thing this playbook assumes: you actually check that the cheap tier is good enough. Route a sample of real tasks through both tiers, score the outputs on &lt;em&gt;your&lt;/em&gt; success criteria, and only then commit the split. Most teams find the quality cliff is far smaller than they feared — and the ones where it isn't, they've already reserved frontier for.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;The takeaway:&lt;/strong&gt; the savings aren't in hunting for a cheaper model. They're in &lt;em&gt;routing the easy 80% to a stable cheap tier, keeping cache affinity, and escalating only the hard calls to frontier.&lt;/em&gt; Do that and 70%+ cheaper is routine — with quality intact.&lt;/p&gt;

&lt;p&gt;If you want to try this without wiring up eight providers yourself: TokenLat is a unified AI gateway for Malaysia &amp;amp; Southeast Asia — one OpenAI-compatible API across 22 models, with &lt;code&gt;auto&lt;/code&gt; routing and per-request cost traces. The model list above is live at &lt;a href="https://tokenlat.com" rel="noopener noreferrer"&gt;tokenlat.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What's your current cost per agent-task — single digits or scaling faster than you'd like? Curious how the 80/20 split would land on your workload.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Your agent's token bill is 5x too high — and it's not the model price</title>
      <dc:creator>TokenLat</dc:creator>
      <pubDate>Mon, 27 Jul 2026 09:45:27 +0000</pubDate>
      <link>https://dev.to/tokenlat/your-agents-token-bill-is-5x-too-high-and-its-not-the-model-price-2ng9</link>
      <guid>https://dev.to/tokenlat/your-agents-token-bill-is-5x-too-high-and-its-not-the-model-price-2ng9</guid>
      <description>&lt;p&gt;Most teams blame their model provider when the inference bill spikes. They're looking at the wrong line item.&lt;/p&gt;

&lt;p&gt;The real leak is &lt;em&gt;architecture&lt;/em&gt; — and it's the difference between a token bill that scales with value and one that scales with chaos. Here's what we see shipping agentic systems in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hidden multiplier: agent loops
&lt;/h2&gt;

&lt;p&gt;A "2-minute task" is never one call. An agent fires 30–60 tool calls per run, and most frameworks stuff the &lt;em&gt;entire&lt;/em&gt; conversation history into every prompt. So a job you'd estimate at ~4K tokens becomes 40 calls × 8K context = 320K tokens — billed at frontier rates.&lt;/p&gt;

&lt;p&gt;Frontier pricing &lt;em&gt;per call&lt;/em&gt; looks cheap. Multiplied by agent-loop iterations, it quietly becomes the largest line in your cloud bill.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 80/20 of inference
&lt;/h2&gt;

&lt;p&gt;Not every call needs a frontier model.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;~80% of agent traffic is routing, extraction, formatting, classification, summarization. Trivial. Leading efficient models — including top China models — handle these at near-parity.&lt;/li&gt;
&lt;li&gt;~20% is genuine reasoning, open-ended generation, ambiguous planning. That's where frontier earns its price.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Route the 80% to efficient models and reserve frontier for the 20%. &lt;strong&gt;Same output quality. A fraction of the bill.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A unified gateway beats a drawer of API keys
&lt;/h2&gt;

&lt;p&gt;The trap most teams hit: they wire 4 providers with 4 clients, then let a naïve router "roam" between them. On failover it loses cache affinity, re-embeds context, and your 1.5x cost target drifts back toward ~1x — or worse.&lt;/p&gt;

&lt;p&gt;A single &lt;strong&gt;OpenAI-compatible endpoint&lt;/strong&gt; across OpenAI + Gemini + leading China models fixes this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One client, one code path.&lt;/li&gt;
&lt;li&gt;Provider pinning holds cache locality; it only fails over on hard error, not price drift.&lt;/li&gt;
&lt;li&gt;Your application code never changes when you swap a model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  In SEA, "PDPA-aligned" is the baseline, not a premium
&lt;/h2&gt;

&lt;p&gt;For Malaysia and SEA teams, inference isn't just a cost question — it's a compliance one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PDPA requires 72-hour breach notification and a designated DPO.&lt;/li&gt;
&lt;li&gt;In-region data residency (SG-hosted) is now the default expectation, not a paid add-on.&lt;/li&gt;
&lt;li&gt;The adoption gap is real: ~93% of the workforce uses GenAI, but ~73% are stuck at L1 (experimenting, not in production). The blocker is almost always cost + compliance friction — not the models.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compliance stops being a tax and becomes table stakes when your gateway is PDPA-aligned by design.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers
&lt;/h2&gt;

&lt;p&gt;In our pricing analysis, frontier output runs on the order of &lt;strong&gt;100x&lt;/strong&gt; the cost of efficient China-model output per million tokens. Route the easy 80% there and blend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Up to 90%+ cheaper&lt;/strong&gt; on the routine 80%&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;70%+ lower blended bill&lt;/strong&gt; overall&lt;/li&gt;
&lt;li&gt;Quality on the 20% that matters: unchanged&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The fix is architecture, not negotiation
&lt;/h2&gt;

&lt;p&gt;You don't fix a 5x token bill by begging your provider for a discount. You fix it by routing, caching, and unifying — then letting compliance be the default instead of the exception.&lt;/p&gt;

&lt;p&gt;We break down agent cost architecture weekly. If you're shipping agents and your bill is climbing faster than your usage, come find us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discord: discord.gg/rxEtWG897V&lt;/li&gt;
&lt;li&gt;Site: tokenlat.com&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>costoptimization</category>
      <category>agents</category>
    </item>
  </channel>
</rss>
