<?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: Mohamed Abidi</title>
    <description>The latest articles on DEV Community by Mohamed Abidi (@hamaabidi).</description>
    <link>https://dev.to/hamaabidi</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%2F4184501%2F28183dc6-1d3a-4793-8c3b-488dad198bc7.jpg</url>
      <title>DEV Community: Mohamed Abidi</title>
      <link>https://dev.to/hamaabidi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hamaabidi"/>
    <language>en</language>
    <item>
      <title>Prompt caching with real numbers, and the bug that breaks it</title>
      <dc:creator>Mohamed Abidi</dc:creator>
      <pubDate>Fri, 13 Nov 2026 13:49:22 +0000</pubDate>
      <link>https://dev.to/hamaabidi/prompt-caching-with-real-numbers-and-the-bug-that-breaks-it-4fpe</link>
      <guid>https://dev.to/hamaabidi/prompt-caching-with-real-numbers-and-the-bug-that-breaks-it-4fpe</guid>
      <description>&lt;p&gt;You turn on prompt caching. The docs say cached tokens cost a tenth of the normal price, so you expect the input bill to drop by most of that.&lt;/p&gt;

&lt;p&gt;A month later the bill is higher than before.&lt;/p&gt;

&lt;p&gt;Nothing errored. No warning in the logs. The API accepted every request and answered every one correctly. It just never read the cache once, and on some providers a cache that is written and never read costs more than no cache at all.&lt;/p&gt;

&lt;p&gt;This post prices one workload three ways: no caching, caching that works, and caching that is silently broken. Then it covers what each provider charges, when caching loses money, and how to check in five minutes that yours is hitting.&lt;/p&gt;

&lt;p&gt;I ran into this from the other side. I was building a tool that shrinks an agent's tool output, and the obvious design was to go back and trim old results a few steps later, once you know what the agent ended up needing. It took me a while to see what that does to the bill: every trim rewrites the start of the conversation, so the cache I was counting on would never get read. I ended up deciding each result once and replaying it byte for byte after that, and I've read the cache fields on every response since.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;On a docs assistant with a 10,000-token fixed prefix, caching takes a request from &lt;strong&gt;$0.024 to $0.005&lt;/strong&gt; on Claude Sonnet 5.5. That's $2,400 a month down to $500 at 100,000 requests.&lt;/li&gt;
&lt;li&gt;Put a timestamp in the system prompt and the same setup costs &lt;strong&gt;$2,900&lt;/strong&gt;: every request pays the 1.25× write price and nothing is ever read back.&lt;/li&gt;
&lt;li&gt;The 5-minute cache pays off from the &lt;strong&gt;first reuse&lt;/strong&gt;. The 1-hour cache needs &lt;strong&gt;two&lt;/strong&gt;. Log the cache fields in the usage object, because a miss never raises an error.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is prompt caching?
&lt;/h2&gt;

&lt;p&gt;Prompt caching is a discount on the part of a request you already sent. The provider keeps the processed form of the start of your prompt, and a later request that starts with exactly the same content reads it back instead of processing it again.&lt;/p&gt;

&lt;p&gt;Two details decide everything else.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's a prefix.&lt;/strong&gt; The cache covers the prompt from its first token up to some point. It can't skip over a changed part and resume after it. One different token early in the prompt, and everything after it is a miss.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's exact.&lt;/strong&gt; The match is byte for byte. "Almost the same prompt" is a different prompt.&lt;/p&gt;

&lt;p&gt;So the layout rule is simple: stable content first (tool definitions, instructions, reference documents), changing content last (the user's question, fresh search results, today's date).&lt;/p&gt;

&lt;p&gt;It also doesn't change the answer. The model produces the same output it would have produced without the cache. Only the price and the time to first token move.&lt;/p&gt;

&lt;h2&gt;
  
  
  How much does prompt caching save?
&lt;/h2&gt;

&lt;p&gt;Take a concrete case. Say you run a docs assistant: users ask questions about your product and the model answers from instructions and reference pages you send along. These numbers are an illustration; swap in your own.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instructions, tool definitions and reference pages: &lt;strong&gt;10,000 tokens&lt;/strong&gt;, identical on every request&lt;/li&gt;
&lt;li&gt;The user's question: &lt;strong&gt;500 tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The answer: &lt;strong&gt;300 tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Volume: &lt;strong&gt;100,000 requests a month&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On Claude Sonnet 5.5, input costs $2 per million tokens, output $10, a 5-minute cache write $2.50 and a cache read $0.10 (&lt;a href="https://platform.claude.com/docs/en/about-claude/pricing" rel="noopener noreferrer"&gt;Anthropic's pricing page&lt;/a&gt;, checked November 9, 2026).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Prefix (10,000)&lt;/th&gt;
&lt;th&gt;Question (500)&lt;/th&gt;
&lt;th&gt;Answer (300)&lt;/th&gt;
&lt;th&gt;Per request&lt;/th&gt;
&lt;th&gt;Per month&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No caching&lt;/td&gt;
&lt;td&gt;$0.020&lt;/td&gt;
&lt;td&gt;$0.001&lt;/td&gt;
&lt;td&gt;$0.003&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.024&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$2,400&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache hit&lt;/td&gt;
&lt;td&gt;$0.001&lt;/td&gt;
&lt;td&gt;$0.001&lt;/td&gt;
&lt;td&gt;$0.003&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.005&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$500&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache write&lt;/td&gt;
&lt;td&gt;$0.025&lt;/td&gt;
&lt;td&gt;$0.001&lt;/td&gt;
&lt;td&gt;$0.003&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$0.029&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$2,900&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The middle row is the promise: 79% off the whole bill, because the prefix was 83% of it.&lt;/p&gt;

&lt;p&gt;The last row is the part people skip. Writing to the cache costs 25% more than a normal request. That premium is fine when you pay it once and read the prefix a thousand times. It is not fine when you pay it on every request.&lt;/p&gt;

&lt;p&gt;The cached part of the bill has more moving pieces than this (two cache lifetimes, different read prices per model). I wrote up &lt;a href="https://contextwaise.com/guides/anthropic-prompt-caching" rel="noopener noreferrer"&gt;how Anthropic bills cached tokens&lt;/a&gt; with the full table if you need a model other than Sonnet.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does each provider charge?
&lt;/h2&gt;

&lt;p&gt;The idea is the same everywhere; the rules aren't. One mid-range model per provider, USD per million tokens:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Provider (model)&lt;/th&gt;
&lt;th&gt;Turned on by&lt;/th&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;Cache write&lt;/th&gt;
&lt;th&gt;Cache read&lt;/th&gt;
&lt;th&gt;Shortest cacheable prefix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Anthropic (Claude Sonnet 5.5)&lt;/td&gt;
&lt;td&gt;a &lt;code&gt;cache_control&lt;/code&gt; field&lt;/td&gt;
&lt;td&gt;$2&lt;/td&gt;
&lt;td&gt;$2.50 (5 min) or $4 (1 hour)&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;td&gt;512 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenAI (GPT-6.1 Sol)&lt;/td&gt;
&lt;td&gt;automatic&lt;/td&gt;
&lt;td&gt;$2&lt;/td&gt;
&lt;td&gt;$2.50&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;td&gt;1,024 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google (Gemini 3.8 Flash)&lt;/td&gt;
&lt;td&gt;automatic; explicit caches optional&lt;/td&gt;
&lt;td&gt;$0.75&lt;/td&gt;
&lt;td&gt;no premium&lt;/td&gt;
&lt;td&gt;$0.075&lt;/td&gt;
&lt;td&gt;4,096 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DeepSeek (V4.1 Flash)&lt;/td&gt;
&lt;td&gt;automatic&lt;/td&gt;
&lt;td&gt;$0.30&lt;/td&gt;
&lt;td&gt;no premium&lt;/td&gt;
&lt;td&gt;$0.006&lt;/td&gt;
&lt;td&gt;none documented&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Sources: the pricing and caching pages of &lt;a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching" rel="noopener noreferrer"&gt;Anthropic&lt;/a&gt;, &lt;a href="https://developers.openai.com/api/docs/guides/prompt-caching" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt;, &lt;a href="https://ai.google.dev/gemini-api/docs/caching" rel="noopener noreferrer"&gt;Google&lt;/a&gt; and &lt;a href="https://api-docs.deepseek.com/quick_start/pricing" rel="noopener noreferrer"&gt;DeepSeek&lt;/a&gt;, checked between October 14 and November 9, 2026. DeepSeek's prices are its peak-hour prices; off-peak is half.&lt;/p&gt;

&lt;p&gt;Three things to take from the table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Automatic" doesn't mean "working".&lt;/strong&gt; On OpenAI, Gemini and DeepSeek you don't opt in, so you also never see a setting that says it's on. The only proof is the cached-token count in the response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The minimum is silent.&lt;/strong&gt; A prompt shorter than the minimum runs uncached with no error. A 2,000-token system prompt caches on Claude Sonnet 5.5 and GPT-6.1 Sol but not on Gemini 3.8 Flash. Older Claude models need 1,024 to 4,096 tokens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A write premium turns a broken cache into a cost.&lt;/strong&gt; Where writes cost the same as normal input, a miss costs you nothing extra. Where they cost 1.25× or 2×, a miss is a surcharge.&lt;/p&gt;

&lt;h2&gt;
  
  
  When does prompt caching cost more than no caching?
&lt;/h2&gt;

&lt;p&gt;Caching is a bet that the prefix will be read again before it expires. You pay the write premium up front and earn the discount on each reuse.&lt;/p&gt;

&lt;p&gt;For the cached prefix on Claude Sonnet 5.5, compared with sending it uncached every time:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Times the prefix is reused before it expires&lt;/th&gt;
&lt;th&gt;5-minute cache&lt;/th&gt;
&lt;th&gt;1-hour cache&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0 (written, never read)&lt;/td&gt;
&lt;td&gt;+25%&lt;/td&gt;
&lt;td&gt;+100%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;−35%&lt;/td&gt;
&lt;td&gt;+2.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;−55%&lt;/td&gt;
&lt;td&gt;−30%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;−75%&lt;/td&gt;
&lt;td&gt;−62.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;−89.3%&lt;/td&gt;
&lt;td&gt;−85.7%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The math behind one cell: with one reuse, uncached is 2 × the prefix price. Cached is 1.25 (the write) + 0.05 (the read) = 1.3. That's 35% less.&lt;/p&gt;

&lt;p&gt;So the 5-minute cache wins from the first reuse, and the 1-hour cache from the second. Anthropic refreshes the 5-minute cache for free on every hit, so steady traffic keeps it alive as long as requests keep coming.&lt;/p&gt;

&lt;p&gt;The losing cases are the ones with no reuse:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A feature that gets one request every ten minutes, on a 5-minute cache. Every request is a write.&lt;/li&gt;
&lt;li&gt;A per-user prefix (the user's own documents first) for users who ask one question and leave.&lt;/li&gt;
&lt;li&gt;A user who comes back after six minutes. The next request rewrites the whole history at the write price.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The one change that breaks it
&lt;/h2&gt;

&lt;p&gt;Here is the line that turns $500 a month into $2,900:&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;system&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Current time: {datetime.now().isoformat()}\n\n{INSTRUCTIONS}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks harmless. The model should know what time it is. But the timestamp is the first line of the prompt and it changes every second, so no two requests share a prefix. Each one writes 10,000 tokens to the cache at $2.50 per million, and no request ever reads them.&lt;/p&gt;

&lt;p&gt;The fix is to move the changing value after the stable part:&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;import&lt;/span&gt; &lt;span class="n"&gt;anthropic&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;anthropic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Anthropic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;response&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;messages&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="s2"&gt;"claude-sonnet-5-5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;INSTRUCTIONS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                    &lt;span class="c1"&gt;# identical on every request&lt;/span&gt;
        &lt;span class="s2"&gt;"cache_control"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ephemeral"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# cache everything up to here&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Current time: {now}\n\n{question}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# changes, so it goes last&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&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;The timestamp is the famous one. The same bug has quieter forms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A request ID or user name&lt;/strong&gt; near the top of the system prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tools in a different order.&lt;/strong&gt; Build the tool list from a set or an unordered map and the prefix differs between requests. Sort tools by name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JSON with unstable key order&lt;/strong&gt;, or floats formatted differently between runs. Same data, different bytes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Editing earlier turns.&lt;/strong&gt; Summarizing or trimming old messages changes the prefix from that point, so every later turn is written again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A/B testing the system prompt.&lt;/strong&gt; Two variants are two caches, each with half the traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How do I know my cache is hitting?
&lt;/h2&gt;

&lt;p&gt;Read the usage object. On Anthropic, total input is split into three fields, and each is billed at a different price:&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="no"&gt;PRICES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;# USD per 1M tokens, Claude Sonnet 5.5&lt;/span&gt;
    &lt;span class="s2"&gt;"input"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;2.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"cache_write"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;2.50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"cache_read"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"output"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;10.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;request_cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;input_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"input"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;                          &lt;span class="c1"&gt;# after the cache point&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_creation_input_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cache_write"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;   &lt;span class="c1"&gt;# written this request&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_read_input_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cache_read"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;        &lt;span class="c1"&gt;# read from the cache&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"output"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hit_rate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;input_tokens&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_creation_input_tokens&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_read_input_tokens&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_read_input_tokens&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Send the same request twice within a minute and look at the second response:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What you see on request 2&lt;/th&gt;
&lt;th&gt;What it means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;cache_read_input_tokens&lt;/code&gt; is most of the input&lt;/td&gt;
&lt;td&gt;Working&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;cache_creation_input_tokens&lt;/code&gt; is large again&lt;/td&gt;
&lt;td&gt;Something before the cache point changed. You're paying the premium every time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Both cache fields are 0&lt;/td&gt;
&lt;td&gt;The prompt is under the minimum length, or the marker is missing&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;OpenAI and Gemini report the same thing under other names: &lt;code&gt;cached_tokens&lt;/code&gt; in OpenAI's usage details, &lt;code&gt;cached_content_token_count&lt;/code&gt; in Gemini's usage metadata. If that number is zero on the second identical request, the prefix isn't stable.&lt;/p&gt;

&lt;p&gt;To find what changed, log a hash of the serialized prefix with each request. Two requests that should share a cache and have different hashes give you two strings to diff.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does caching fix an agent that keeps getting more expensive?
&lt;/h2&gt;

&lt;p&gt;Partly. An agent re-sends its whole conversation on every step, so caching the history is a large win. But every new tool result still enters the conversation at the write price, and is then read again on every later step.&lt;/p&gt;

&lt;p&gt;Here is one tool result I measured on a demo agent of mine: a test run of 7,209 tokens, most of it passing tests and progress bars around two failures. Priced on Claude Opus 5.5 ($4 input, $5 write, $0.20 read) over a 20-step run:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;How the result is handled&lt;/th&gt;
&lt;th&gt;Cost of that one result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No caching, full price on all 20 steps&lt;/td&gt;
&lt;td&gt;$0.577&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cached: written once, read 19 times&lt;/td&gt;
&lt;td&gt;$0.063&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cut to the 156 tokens about the failures, then cached&lt;/td&gt;
&lt;td&gt;$0.0014&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The token counts are measured; the prices and step count are an illustration. Caching takes 89% off. Not sending the noise takes off almost all of the rest. (Disclosure: I work on Contextwaise, which does that trimming, so weigh this section accordingly.)&lt;/p&gt;

&lt;p&gt;The order matters. Trim a result before it is first sent and the cache never knows. Trim it three steps later and you have edited the prefix, which is the bug from the previous section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is prompt caching the same as semantic caching?
&lt;/h2&gt;

&lt;p&gt;No, and the names get mixed up.&lt;/p&gt;

&lt;p&gt;Prompt caching reuses the model's work on an identical prefix and still generates a fresh answer. It can't return a wrong answer, only a cheaper one.&lt;/p&gt;

&lt;p&gt;Semantic caching sits in your own code. It stores whole responses and returns a stored one when a new question is similar enough to an old one. That skips the model call entirely, and it can be wrong: "how do I cancel my plan" and "how do I cancel my order" are close in meaning and need different answers.&lt;/p&gt;

&lt;p&gt;They stack. Use prompt caching by default, and add semantic caching only where questions repeat almost word for word and a stale answer is harmless.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do on Monday
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log the cached-token fields from the usage object for a day of real traffic. Compute the hit rate per endpoint.&lt;/li&gt;
&lt;li&gt;For any endpoint under about 80% on its second and later requests, hash the prefix and diff two requests. Look for a date, an ID or an unordered list.&lt;/li&gt;
&lt;li&gt;Reorder the prompt: tools, then fixed instructions, then reference material, then everything that changes.&lt;/li&gt;
&lt;li&gt;Check the prefix is above your model's minimum length. Under it, nothing is cached and nothing tells you.&lt;/li&gt;
&lt;li&gt;Count reuses before choosing a lifetime: bursts within minutes fit the 5-minute cache, two or more reads an hour fit the 1-hour cache, less than that and caching that segment loses money.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What's your cache hit rate on your busiest endpoint, and what was the thing that broke it when you first checked?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Gemini API cost: two prices double before January</title>
      <dc:creator>Mohamed Abidi</dc:creator>
      <pubDate>Fri, 23 Oct 2026 19:28:16 +0000</pubDate>
      <link>https://dev.to/hamaabidi/gemini-api-cost-two-prices-double-before-january-20m0</link>
      <guid>https://dev.to/hamaabidi/gemini-api-cost-two-prices-double-before-january-20m0</guid>
      <description>&lt;p&gt;If you picked Gemini 4 Argon this year because it cost the same as Claude Sonnet, check Google's pricing page again. On December 1, Argon goes from $2 to $4 per million input tokens and from $10 to $20 per million output tokens. Same model, same traffic, twice the invoice.&lt;/p&gt;

&lt;p&gt;Gemini 3.8 Flash follows on January 1: $0.75 to $1.50 input, $3.75 to $7.50 output.&lt;/p&gt;

&lt;p&gt;Price increases on an API are rare enough that most cost estimates don't plan for them. So let's take one concrete workload, price it on every current Gemini model before and after the change, and then look at the four things that move a Gemini bill more than the price list does: thinking tokens, caching, the Batch API and grounding.&lt;/p&gt;

&lt;p&gt;I maintain a Gemini price table for a cost calculator, so I re-check Google's pricing page every few weeks. In October, two rows had something I hadn't seen on an LLM price list before: a second price with a start date. No announcement in my inbox, no deprecation notice, just a footnote on the page.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A document pipeline of 300,000 requests a month costs &lt;strong&gt;$6,000 on Gemini 4 Argon today and $12,000 from December 1&lt;/strong&gt;. On Gemini 3.8 Flash: $2,250 today, $4,500 from January 1.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thinking tokens bill as output.&lt;/strong&gt; 1,500 thinking tokens per request add 75% to the Flash bill, and they don't appear in the answer.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Batch API cancels the increase exactly&lt;/strong&gt; (50% off) for work that can wait. A cached 5,000-token prefix cuts another 45–48%. Gemini 3.1 Flash-Lite runs the same job for $780.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How is the Gemini API billed?
&lt;/h2&gt;

&lt;p&gt;Per million tokens, input and output separately. Cached input costs 10% of the input price, the Batch API halves input and output, and Pro models charge more once a prompt passes 200,000 tokens. These are the paid-tier list prices from &lt;a href="https://ai.google.dev/gemini-api/docs/pricing" rel="noopener noreferrer"&gt;Google's pricing page&lt;/a&gt;, in USD per million tokens, checked October 14, 2026:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Cached input&lt;/th&gt;
&lt;th&gt;Scheduled change&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 4 Argon&lt;/td&gt;
&lt;td&gt;$2&lt;/td&gt;
&lt;td&gt;$10&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;td&gt;$4 / $20 from Dec 1, 2026&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.1 Pro Preview&lt;/td&gt;
&lt;td&gt;$2&lt;/td&gt;
&lt;td&gt;$12&lt;/td&gt;
&lt;td&gt;$0.20&lt;/td&gt;
&lt;td&gt;$4 / $18 over 200K tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.8 Flash&lt;/td&gt;
&lt;td&gt;$0.75&lt;/td&gt;
&lt;td&gt;$3.75&lt;/td&gt;
&lt;td&gt;$0.075&lt;/td&gt;
&lt;td&gt;$1.50 / $7.50 from Jan 1, 2027&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.5 Flash-Lite&lt;/td&gt;
&lt;td&gt;$0.30&lt;/td&gt;
&lt;td&gt;$2.50&lt;/td&gt;
&lt;td&gt;$0.03&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.1 Flash-Lite&lt;/td&gt;
&lt;td&gt;$0.25&lt;/td&gt;
&lt;td&gt;$1.50&lt;/td&gt;
&lt;td&gt;$0.025&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.5 Flash-Lite&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;td&gt;$0.40&lt;/td&gt;
&lt;td&gt;$0.01&lt;/td&gt;
&lt;td&gt;none (older generation)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Output is 5× input on Argon and Flash, 6× on Pro. That ratio matters later, when thinking tokens show up.&lt;/p&gt;

&lt;h2&gt;
  
  
  The example: a document extraction pipeline
&lt;/h2&gt;

&lt;p&gt;Say you run a pipeline that reads inbound documents (contracts, invoices, support emails) and extracts structured fields. It isn't an agent: one request per document, no back-and-forth. These numbers are an illustration; swap in your own.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instructions, JSON schema and a few worked examples: &lt;strong&gt;5,000 tokens&lt;/strong&gt;, identical on every request&lt;/li&gt;
&lt;li&gt;The document itself: &lt;strong&gt;3,000 tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The extracted JSON: &lt;strong&gt;400 tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Volume: &lt;strong&gt;10,000 documents a day&lt;/strong&gt;, so 300,000 a month&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's 8,000 input tokens and 400 output tokens per request. A month is 2.4 billion input tokens and 120 million output tokens.&lt;/p&gt;

&lt;p&gt;To get your own per-request numbers, paste a real prompt into a &lt;a href="https://contextwaise.com/tools/token-counter" rel="noopener noreferrer"&gt;token counter&lt;/a&gt; that counts for Gemini, Claude and GPT. Gemini averages about 4 characters per token in English, so a 3,000-token document is roughly 12,000 characters.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does it cost on each Gemini model?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Monthly today&lt;/th&gt;
&lt;th&gt;After the increase&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 4 Argon&lt;/td&gt;
&lt;td&gt;$4,800&lt;/td&gt;
&lt;td&gt;$1,200&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$6,000&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;$12,000&lt;/strong&gt; (Dec 1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.1 Pro Preview&lt;/td&gt;
&lt;td&gt;$4,800&lt;/td&gt;
&lt;td&gt;$1,440&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$6,240&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;no change&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.8 Flash&lt;/td&gt;
&lt;td&gt;$1,800&lt;/td&gt;
&lt;td&gt;$450&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$2,250&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;$4,500&lt;/strong&gt; (Jan 1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.5 Flash-Lite&lt;/td&gt;
&lt;td&gt;$720&lt;/td&gt;
&lt;td&gt;$300&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$1,020&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;no change&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.1 Flash-Lite&lt;/td&gt;
&lt;td&gt;$600&lt;/td&gt;
&lt;td&gt;$180&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$780&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;no change&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 2.5 Flash-Lite&lt;/td&gt;
&lt;td&gt;$240&lt;/td&gt;
&lt;td&gt;$48&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$288&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;no change&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three things stand out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input is 77–80% of the bill on the bigger models.&lt;/strong&gt; The 400-token answer is the cheap part. The 5,000 tokens of instructions you send 300,000 times a month are not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The ranking flips on December 1.&lt;/strong&gt; Today Argon is slightly cheaper than Gemini 3.1 Pro for this job ($6,000 vs $6,240). From December 1 it costs almost twice as much ($12,000 vs $6,240). If 3.1 Pro passes your evals, it's the cheaper strong model from then on. It's still labelled Preview, so weigh that too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flash-Lite is 2–8× cheaper than Flash.&lt;/strong&gt; Extraction into a fixed schema is the kind of task small models often handle. Run your eval set on 3.1 Flash-Lite before assuming you need Flash.&lt;/p&gt;

&lt;p&gt;I checked the table with this &lt;a href="https://contextwaise.com/gemini-api-pricing" rel="noopener noreferrer"&gt;Gemini API cost calculator&lt;/a&gt;, entering 8,000 input and 400 output tokens at 300,000 requests a month. It also shows the post-increase prices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is my Gemini bill higher than the math?
&lt;/h2&gt;

&lt;p&gt;Usually because of one of three things the table above doesn't include.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Thinking tokens
&lt;/h3&gt;

&lt;p&gt;Gemini's newer models think before they answer, and &lt;a href="https://ai.google.dev/gemini-api/docs/thinking" rel="noopener noreferrer"&gt;thinking tokens&lt;/a&gt; are billed as output at the full output price. They don't show up in the response text, so you only see them in the usage metadata.&lt;/p&gt;

&lt;p&gt;Say Gemini 3.8 Flash thinks for 1,500 tokens before writing the 400-token JSON. Output per request goes from 400 to 1,900 tokens:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Gemini 3.8 Flash&lt;/th&gt;
&lt;th&gt;Output tokens / month&lt;/th&gt;
&lt;th&gt;Output cost&lt;/th&gt;
&lt;th&gt;Monthly total&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No thinking&lt;/td&gt;
&lt;td&gt;120M&lt;/td&gt;
&lt;td&gt;$450&lt;/td&gt;
&lt;td&gt;$2,250&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1,500 thinking tokens&lt;/td&gt;
&lt;td&gt;570M&lt;/td&gt;
&lt;td&gt;$2,137.50&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;$3,937.50&lt;/strong&gt; (+75%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same, from Jan 1&lt;/td&gt;
&lt;td&gt;570M&lt;/td&gt;
&lt;td&gt;$4,275&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$7,875&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Field extraction rarely needs long reasoning. Set a low thinking budget (or thinking level, depending on the model) in the request config, and compare accuracy on your eval set with thinking low and off.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Grounding with Google Search
&lt;/h3&gt;

&lt;p&gt;Grounding is billed per search, not per token. Gemini 3 and newer models share 5,000 free search requests a month, then $14 per 1,000. If every one of the 300,000 documents triggered one search, that's (300,000 − 5,000) × $14 / 1,000 = &lt;strong&gt;$4,130 a month&lt;/strong&gt;, more than the whole Flash bill. A grounded request can trigger more than one search, so treat that as a floor. Turn grounding on only for the requests that need fresh facts.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Long prompts on Pro
&lt;/h3&gt;

&lt;p&gt;Gemini 3.1 Pro bills the whole request at $4 input and $18 output once the prompt passes 200,000 tokens. This pipeline never gets close, but a "just send the whole repo" coding tool or a long chat history does. Gemini 2.5 Pro has the same threshold ($1.25 → $2.50 input).&lt;/p&gt;

&lt;h2&gt;
  
  
  Does caching lower Gemini API cost?
&lt;/h2&gt;

&lt;p&gt;Yes, and this pipeline is close to the ideal case: the same 5,000-token prefix starts every request. Cached input costs 10% of the input price.&lt;/p&gt;

&lt;p&gt;Gemini has two kinds of &lt;a href="https://ai.google.dev/gemini-api/docs/caching" rel="noopener noreferrer"&gt;context caching&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Implicit caching&lt;/strong&gt; is automatic. When a request starts with the same tokens as a recent one, those tokens are billed at the cached price. Nothing to set up, no storage fee, but hits aren't guaranteed. Put the fixed instructions first and the document last, or nothing matches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit caching&lt;/strong&gt; stores a prefix you create, for a time you choose, with guaranteed hits and a storage fee per million tokens per hour: $0.50 on Gemini 3.8 Flash. Gemini 4 Argon supports implicit caching only.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The prefix has to be long enough to cache: 4,096 tokens on these models. A 2,000-token system prompt doesn't qualify, which is one reason to keep your worked examples in the prefix rather than trimming them to save tokens.&lt;/p&gt;

&lt;p&gt;If all 5,000 prefix tokens hit the cache:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Without caching&lt;/th&gt;
&lt;th&gt;With the prefix cached&lt;/th&gt;
&lt;th&gt;Saved&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 4 Argon (today)&lt;/td&gt;
&lt;td&gt;$6,000&lt;/td&gt;
&lt;td&gt;$3,150&lt;/td&gt;
&lt;td&gt;47.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 4 Argon (from Dec 1)&lt;/td&gt;
&lt;td&gt;$12,000&lt;/td&gt;
&lt;td&gt;$6,300&lt;/td&gt;
&lt;td&gt;47.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.8 Flash (today)&lt;/td&gt;
&lt;td&gt;$2,250&lt;/td&gt;
&lt;td&gt;$1,237.50&lt;/td&gt;
&lt;td&gt;45%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On Flash, an explicit cache for that prefix costs 0.005M tokens × $0.50 × 720 hours = &lt;strong&gt;$1.80 a month&lt;/strong&gt; to keep warm. For a pipeline that runs all day, buying guaranteed hits is an easy call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does the Batch API cancel the price increase?
&lt;/h2&gt;

&lt;p&gt;For this pipeline, exactly. The &lt;a href="https://ai.google.dev/gemini-api/docs/batch-mode" rel="noopener noreferrer"&gt;Batch API&lt;/a&gt; takes 50% off input and output for jobs submitted asynchronously, and the increase is 2×:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Standard, after increase&lt;/th&gt;
&lt;th&gt;Batch, after increase&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 4 Argon&lt;/td&gt;
&lt;td&gt;$12,000&lt;/td&gt;
&lt;td&gt;$6,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini 3.8 Flash&lt;/td&gt;
&lt;td&gt;$4,500&lt;/td&gt;
&lt;td&gt;$2,250&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The catch is latency. Google targets a 24-hour turnaround (often much sooner), so batch only fits work nobody is waiting on: nightly extraction, backfills, evals, classification. If documents land in a queue anyway, a few hours' delay is often invisible to users. Batch also stacks with caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is the Gemini API free?
&lt;/h2&gt;

&lt;p&gt;Partly. Gemini 3.8 Flash, the Flash-Lite models and the Gemini 2.5 models have a free tier in Google AI Studio and the API, within rate limits. Gemini 4 Argon and Gemini 3.1 Pro are paid only.&lt;/p&gt;

&lt;p&gt;The catch is data: on the free tier, Google may use your prompts and responses to improve its products. On the paid tier it doesn't. The free tier is fine for prototyping. For customer documents like the ones in this example, you want the paid tier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Price your own requests
&lt;/h2&gt;

&lt;p&gt;Every response carries &lt;code&gt;usage_metadata&lt;/code&gt;. Log it, then price it. With the Python &lt;code&gt;google-genai&lt;/code&gt; SDK:&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;PRICES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;# USD per 1M tokens, Gemini 3.8 Flash until Dec 31, 2026
&lt;/span&gt;    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;input&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;output&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;3.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cache_read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.075&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;request_cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cached_content_token_count&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;fresh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt_token_count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;cached&lt;/span&gt;        &lt;span class="c1"&gt;# prompt count includes cached tokens
&lt;/span&gt;    &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;candidates_token_count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;thoughts_token_count&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;fresh&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;input&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cache_read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;output&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two fields catch people out: &lt;code&gt;thoughts_token_count&lt;/code&gt; is billed as output even though it isn't in the answer, and &lt;code&gt;cached_content_token_count&lt;/code&gt; tells you whether implicit caching is actually hitting. If it's zero on the second request with the same prefix, your prefix isn't stable.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do before December 1
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log &lt;code&gt;usage_metadata&lt;/code&gt; for a day of real traffic. Get average input, output, thinking and cached tokens per request.&lt;/li&gt;
&lt;li&gt;Reprice it at the new prices: $4 / $20 for Argon, $1.50 / $7.50 for 3.8 Flash. Put that number in next quarter's budget, not today's.&lt;/li&gt;
&lt;li&gt;If you're on Argon, run your eval set on Gemini 3.1 Pro and on a Flash model. From December 1, Pro costs half of Argon's input price and 60% of its output price.&lt;/li&gt;
&lt;li&gt;Move anything nobody waits on to the Batch API. For async work, that undoes the increase.&lt;/li&gt;
&lt;li&gt;Put the fixed instructions first, check that cached tokens show up from the second request, and set a thinking budget on simple tasks.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Are you moving off Argon before December 1, or absorbing the increase? I'm curious what your evals say about 3.1 Pro versus Argon on the same job.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>gemini</category>
      <category>llm</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Claude API cost: I priced one AI agent on every model</title>
      <dc:creator>Mohamed Abidi</dc:creator>
      <pubDate>Tue, 20 Oct 2026 12:59:25 +0000</pubDate>
      <link>https://dev.to/hamaabidi/claude-api-cost-i-priced-one-ai-agent-on-every-model-29b</link>
      <guid>https://dev.to/hamaabidi/claude-api-cost-i-priced-one-ai-agent-on-every-model-29b</guid>
      <description>&lt;p&gt;Every Claude pricing page gives you the same thing: a table of dollars per million tokens. Sonnet 5.5 is $2 in and $10 out. Fine. But nobody ships "a million tokens". You ship a support agent, a coding assistant, a RAG endpoint, and you want to know what it will cost next month.&lt;/p&gt;

&lt;p&gt;The per-token price doesn't answer that, because the number that decides your bill isn't on the price list: how many tokens your app sends per request, and how fast that number grows.&lt;/p&gt;

&lt;p&gt;So let's price one concrete agent, step by step, on every current Claude model. Then we'll see where the money actually goes, and which two settings change the answer.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A 5-step support agent at 30,000 conversations a month costs &lt;strong&gt;$3,690 on Sonnet 5.5&lt;/strong&gt;, $7,380 on Opus 5.5, $18,450 on Fable 5.1 and $184.50 on Haiku 5.5.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;88% of that is input tokens&lt;/strong&gt;, not the answer: every step re-sends the system prompt, the tools and everything said so far.&lt;/li&gt;
&lt;li&gt;Prompt caching cuts the same bill by &lt;strong&gt;61–67%&lt;/strong&gt; (Sonnet: $3,690 → $1,289). Model choice moves it 100×.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How does Claude API pricing work?
&lt;/h2&gt;

&lt;p&gt;Every request is billed on two counts: the tokens it reads (input) and the tokens it writes (output). Output costs 5× input on every current Claude model. Here are the list prices, in USD per million tokens, from &lt;a href="https://platform.claude.com/docs/en/about-claude/pricing" rel="noopener noreferrer"&gt;Anthropic's pricing page&lt;/a&gt;, checked October 14, 2026:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Cached read&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Fable 5.1&lt;/td&gt;
&lt;td&gt;$10&lt;/td&gt;
&lt;td&gt;$50&lt;/td&gt;
&lt;td&gt;$0.25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Opus 5.5&lt;/td&gt;
&lt;td&gt;$4&lt;/td&gt;
&lt;td&gt;$20&lt;/td&gt;
&lt;td&gt;$0.20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Sonnet 5.5&lt;/td&gt;
&lt;td&gt;$2&lt;/td&gt;
&lt;td&gt;$10&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Haiku 5.5&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;td&gt;$0.50&lt;/td&gt;
&lt;td&gt;$0.01&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two discounts sit on top: prompt caching (repeated input billed at the "cached read" price) and the &lt;a href="https://platform.claude.com/docs/en/build-with-claude/batch-processing" rel="noopener noreferrer"&gt;Batch API&lt;/a&gt; (50% off everything, for work that can wait up to 24 hours).&lt;/p&gt;

&lt;p&gt;That table is all a price list can tell you. The rest depends on your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  The example: a 5-step support agent
&lt;/h2&gt;

&lt;p&gt;Say you run a support agent. A user asks a billing question, and the agent works through it in 5 model calls: look up the account, fetch the invoice, check the refund status, and so on. These numbers are an illustration; swap in your own.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System prompt + tool definitions: &lt;strong&gt;6,000 tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The user's question: &lt;strong&gt;200 tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Each step, the model writes &lt;strong&gt;300 tokens&lt;/strong&gt; (a tool call or the answer)&lt;/li&gt;
&lt;li&gt;Each tool returns &lt;strong&gt;2,000 tokens&lt;/strong&gt; (JSON from your billing API)&lt;/li&gt;
&lt;li&gt;Volume: &lt;strong&gt;1,000 conversations a day&lt;/strong&gt;, so 30,000 a month&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The trap is that an agent doesn't send "the new stuff" on each call. The Messages API is stateless, so every call re-sends the whole conversation so far:&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;calls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6_200&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2_300&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="c1"&gt;# [6200, 8500, 10800, 13100, 15400]
&lt;/span&gt;
&lt;span class="n"&gt;input_tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;calls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# 54,000 per conversation
&lt;/span&gt;&lt;span class="n"&gt;output_tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;     &lt;span class="c1"&gt;# 1,500 per conversation
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fifth call reads 15,400 tokens to write 300. Across the conversation, input outweighs output 36 to 1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiykyhq4nsi97rembild6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiykyhq4nsi97rembild6.png" alt="Vintage travel-poster illustration of three pack-laden donkeys climbing a winding mountain path above a turquoise lake, representing the growing context carried through successive AI agent calls." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What does it cost per month on each Claude model?
&lt;/h2&gt;

&lt;p&gt;Multiply: 54,000 input tokens × 30,000 conversations = 1.62 billion input tokens a month. 1,500 output tokens × 30,000 = 45 million output tokens.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Input&lt;/th&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Monthly total&lt;/th&gt;
&lt;th&gt;Per conversation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Fable 5.1&lt;/td&gt;
&lt;td&gt;$16,200&lt;/td&gt;
&lt;td&gt;$2,250&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$18,450&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;$0.615&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Opus 5.5&lt;/td&gt;
&lt;td&gt;$6,480&lt;/td&gt;
&lt;td&gt;$900&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$7,380&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;$0.246&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Sonnet 5.5&lt;/td&gt;
&lt;td&gt;$3,240&lt;/td&gt;
&lt;td&gt;$450&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$3,690&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;$0.123&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Haiku 5.5&lt;/td&gt;
&lt;td&gt;$162&lt;/td&gt;
&lt;td&gt;$22.50&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$184.50&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;$0.006&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Input is 87.8% of the bill on every model, because the input/output price ratio is the same 5× across the lineup. If you've been trimming your answers to save money, you've been optimizing the 12%.&lt;/p&gt;

&lt;p&gt;The spread between models is the other lesson: Fable 5.1 costs exactly 100× Haiku 5.5 for the same traffic. Whether Haiku can actually resolve your billing questions is a question for your eval set, not the price list. But if it passes on even half your traffic, routing that half is the biggest saving available.&lt;/p&gt;

&lt;p&gt;To check this table, I entered one conversation as one "request" (54,000 input, 1,500 output, 30,000 a month) into this &lt;a href="https://contextwaise.com/claude-api-pricing" rel="noopener noreferrer"&gt;Claude API cost calculator&lt;/a&gt;, which prices every model side by side. A spreadsheet works too; the formula is below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is the Claude API so expensive?
&lt;/h2&gt;

&lt;p&gt;It usually isn't the price per token. It's three things that multiply it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Re-sent context.&lt;/strong&gt; Every agent step re-reads the system prompt, the tool schemas and every earlier tool result. In the example, the same 6,000-token system prompt is billed 5 times per conversation, 150,000 times a month.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fat tool results.&lt;/strong&gt; The 2,000-token tool result is the biggest line in the example. Raw JSON from an API carries IDs, timestamps, null fields and nested metadata the model never uses, and it stays in the context for every later step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hidden output.&lt;/strong&gt; Extended thinking is billed as output tokens. A model that "thinks" for 2,000 tokens before a 300-token answer bills 2,300 output tokens at the output price.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One more, which catches people comparing models: Claude 4.7 and later use a tokenizer that produces about 30% more tokens for the same text. A lower price per token on a newer model can still mean a similar bill. Count a real prompt on the model you'll use before you compare.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does prompt caching change?
&lt;/h2&gt;

&lt;p&gt;Prompt caching bills a repeated prompt prefix at the cached-read price. In an agent loop, almost everything is a repeated prefix: call 3 starts with everything call 2 sent.&lt;/p&gt;

&lt;p&gt;With a cache marker at the end of each call (and enough traffic that the shared 6,000-token system prompt stays warm), each conversation reads 44,600 tokens from cache and writes only the new 9,400. Cache writes cost 1.25× input on the 5-minute cache, so I've included them (calculators that leave writes out, including the one above, show a slightly lower number):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Without caching&lt;/th&gt;
&lt;th&gt;With caching&lt;/th&gt;
&lt;th&gt;Saved&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Fable 5.1&lt;/td&gt;
&lt;td&gt;$18,450&lt;/td&gt;
&lt;td&gt;$6,109.50&lt;/td&gt;
&lt;td&gt;67%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Opus 5.5&lt;/td&gt;
&lt;td&gt;$7,380&lt;/td&gt;
&lt;td&gt;$2,577.60&lt;/td&gt;
&lt;td&gt;65%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Sonnet 5.5&lt;/td&gt;
&lt;td&gt;$3,690&lt;/td&gt;
&lt;td&gt;$1,288.80&lt;/td&gt;
&lt;td&gt;65%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Haiku 5.5&lt;/td&gt;
&lt;td&gt;$184.50&lt;/td&gt;
&lt;td&gt;$71.13&lt;/td&gt;
&lt;td&gt;61%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On Sonnet 5.5, a cached read costs $0.10 per million tokens against $2 uncached, 95% off. What's left of the bill is mostly cache writes and output.&lt;/p&gt;

&lt;p&gt;Caching has rules that can silently turn it off (a timestamp in the system prompt, a reordered tool list, a user who comes back after 6 minutes). That's tomorrow's post in this series. For a cost estimate, the point is simpler: &lt;strong&gt;an uncached agent estimate is roughly 3× too high in this scenario&lt;/strong&gt;, so don't kill a project on it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpkovpnuoeyxolvuvms6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpkovpnuoeyxolvuvms6d.png" alt="Vintage gouache illustration of a stone granary containing stacked grain sacks beside terraced green fields and a turquoise lake. A farmer carries one new sack toward the granary, symbolizing cached context being reused instead of processed again." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The threshold that changes the cheapest model
&lt;/h2&gt;

&lt;p&gt;Haiku 5.5 has a long-context tier: prompts over 100,000 input tokens are billed at $0.50 input and $2.50 output, 5× its normal price. Other current Claude models bill their full context window at standard prices.&lt;/p&gt;

&lt;p&gt;Five steps never get close. But agents that loop (coding agents, research agents) do. In the example, the context grows 2,300 tokens per step, so &lt;strong&gt;step 42&lt;/strong&gt; is the first call over 100,000 tokens. From there, every Haiku call costs 5× more, and the gap to Sonnet shrinks from 20× to 4×.&lt;/p&gt;

&lt;p&gt;If your agent runs long, either keep the context under the threshold (summarize or drop old tool results) or price Haiku at its long-context rate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your own formula
&lt;/h2&gt;

&lt;p&gt;Log the &lt;code&gt;usage&lt;/code&gt; object every response returns, then price it:&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;PRICES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;# USD per 1M tokens, Sonnet 5.5
&lt;/span&gt;    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;input&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;2.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;output&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;10.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cache_read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cache_write&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;2.50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# 5-minute write = 1.25× input
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;request_cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;input_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;input&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;output&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_read_input_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cache_read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache_creation_input_tokens&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;PRICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cache_write&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;input_tokens&lt;/code&gt; in the response counts only the uncached part, so the four fields add up without double counting. Sum &lt;code&gt;request_cost&lt;/code&gt; per conversation and you have the number that matters: &lt;strong&gt;cost per resolved task&lt;/strong&gt;, not cost per token. The field names are in the &lt;a href="https://platform.claude.com/docs/en/api/messages" rel="noopener noreferrer"&gt;Messages API reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is the Claude API free, or included in Claude Pro?
&lt;/h2&gt;

&lt;p&gt;No to both. The API is pay-as-you-go per token; new accounts may receive trial credit. Claude Pro and Max subscriptions cover the Claude apps, and API usage is billed separately (&lt;a href="https://claude.com/pricing" rel="noopener noreferrer"&gt;Claude plans&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do Monday morning
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log &lt;code&gt;usage&lt;/code&gt; for 100 real conversations and compute average input and output tokens &lt;strong&gt;per conversation&lt;/strong&gt;, not per call.&lt;/li&gt;
&lt;li&gt;Price that on two models: the one you use and the next one down. Run your eval set on the cheaper one.&lt;/li&gt;
&lt;li&gt;Turn on prompt caching and check that &lt;code&gt;cache_read_input_tokens&lt;/code&gt; is most of the input from the second call on.&lt;/li&gt;
&lt;li&gt;Look at your largest tool result and cut the fields the model never reads.&lt;/li&gt;
&lt;li&gt;If any run goes past ~40 steps, check where its context crosses a pricing threshold.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What does one task cost in your app, and how many model calls does it take? I'm curious how far real agents are from the 5-step example.&lt;/p&gt;

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