<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[NeverPayTwice]]></title><description><![CDATA[NeverPayTwice]]></description><link>https://neverpaytwice.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 21 Nov 2026 14:39:19 GMT</lastBuildDate><atom:link href="https://neverpaytwice.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Claude Code: subscription or API? Work it out from your own logs]]></title><description><![CDATA[Originally published at neverpaytwice.com. Short answer: price one month of your real Claude Code usage at API rates and put it next to the plan price. If…]]></description><link>https://neverpaytwice.hashnode.dev/claude-code-subscription-or-api-work-it-out-from-your-own-logs</link><guid isPermaLink="true">https://neverpaytwice.hashnode.dev/claude-code-subscription-or-api-work-it-out-from-your-own-logs</guid><category><![CDATA[claude]]></category><category><![CDATA[llm]]></category><dc:creator><![CDATA[NeverPayTwice]]></dc:creator><pubDate>Tue, 17 Nov 2026 18:00:39 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published at</em> <a href="https://neverpaytwice.com/claude-code-subscription-vs-api"><em>neverpaytwice.com</em></a><em>.</em></p>
<p><strong>Short answer:</strong> price one month of your real Claude Code usage at API rates and put it next to the plan price. If the API figure is <strong>lower</strong> than the plan, paying per token is cheaper and has no usage limits. If it is <strong>higher</strong>, the plan is cheaper, as long as you stay inside its limits.</p>
<p>Anthropic does not publish plan limits in tokens, so nobody can tell you the break-even in tokens. What you can know is your own monthly cost at API rates. Claude Code keeps the numbers you need on your computer. Below: the plan prices, how to read the comparison, and a script that does it per month.</p>
<h2>What the plans cost</h2>
<p>Claude Code is included from Pro upward. Prices from Anthropic's pricing page, before tax:</p>
<table>
<thead>
<tr>
<th>Plan</th>
<th>Price</th>
<th>Usage, as Anthropic states it</th>
</tr>
</thead>
<tbody><tr>
<td>Pro</td>
<td>$20 a month ($17 a month billed yearly)</td>
<td>More usage than Free, every 5 hours and every week</td>
</tr>
<tr>
<td>Max</td>
<td>$100 a month</td>
<td>5× Pro usage every 5 hours and every week</td>
</tr>
<tr>
<td>Ultra</td>
<td>$200 a month</td>
<td>10× Pro usage every week; no 5-hour limit for verified accounts</td>
</tr>
<tr>
<td>API key</td>
<td>Per token, no monthly fee</td>
<td>No plan limit; you pay for every token</td>
</tr>
</tbody></table>
<p>Anthropic's own note on the limits: how fast you reach one depends on the model, how long your chats are and how large your files are. Max and Ultra also list $100 and $200 a month in API credits for building on the Claude Platform.</p>
<h2>How to read the comparison</h2>
<p>Take one full month. Price every response at the API rate for the model that produced it: new input, cache writes, cache reads and output each have their own price. Add it up. Then:</p>
<ul>
<li><strong>API total below the plan price:</strong> a plan costs you more than paying per token. Light or occasional use usually lands here.</li>
<li><strong>API total above the plan price:</strong> the plan saves you the difference, if your usage fits its limits. If you keep hitting limits, the next plan up or the API may be what you actually need.</li>
<li><strong>Near the line:</strong> look at more than one month. Usage swings a lot from month to month.</li>
</ul>
<p>An example with made-up numbers: a month that comes to $61 at API rates is $41 more than Pro, so Pro is cheaper if it covers that month. The same month is $39 less than Max, so Max would cost more than the API.</p>
<h2>Two mistakes that skew the number</h2>
<p><strong>Counting the logs as they are.</strong> Claude Code writes the same response to its logs several times, so a plain sum of the log lines can come out about twice as high, or more. That makes the API look far more expensive than it is. <a href="https://neverpaytwice.com/claude-code-token-count">Why Claude Code token counts are wrong</a> shows how to count each response once.</p>
<p><strong>Pricing every input token the same.</strong> Most of Claude Code's input is read from the prompt cache, which costs a small fraction of the input price, while cache writes cost more. Pricing it all as plain input inflates the total many times over. <a href="https://neverpaytwice.com/claude-prompt-caching-cost">The caching break-even math</a> has the multipliers.</p>
<h2>Run it on your own logs</h2>
<p>This script reads Claude Code's local logs (<code>~/.claude/projects</code>), keeps each response once, prices it at Anthropic's standard API rates and adds it up per calendar month. It works whether you are on a plan or an API key: the logs record the same usage either way. It prints numbers only and sends nothing anywhere. (<a href="https://neverpaytwice.com/claude_code_monthly_cost.py">Download it</a>, or get it with the other scripts <a href="https://github.com/neverpaytwice/ai-token-cost-scripts">on GitHub</a>.)</p>
<pre><code class="language-shell">python3 claude_code_monthly_cost.py
</code></pre>
<p>Example output (made-up numbers):</p>
<pre><code class="language-plaintext">Month      At API rates            Pro $20/mo           Max $100/mo         Ultra $200/mo
2026-09          $12.40     API cheaper by $8    API cheaper by $88   API cheaper by $188
2026-10          $61.30   plan cheaper by $41    API cheaper by $39   API cheaper by $139
2026-11         $236.40  plan cheaper by $216  plan cheaper by $136   plan cheaper by $36
A month that is still running is only partly counted.
</code></pre>
<p>We checked it against our other scripts on a real set of Claude Code logs: its total matches the caching script to the cent, and its per-response prices match the tested <a href="https://neverpaytwice.com/anthropic-api-cost-per-request">per-request cost function</a> on every model. It lists any model it has no price for instead of counting it as free. Standard rates only: the Batch API, US-only inference, fast mode and long-prompt prices are not applied.</p>
<p>Prefer not to run a script? The <a href="https://neverpaytwice.com/count">free Claude Code token counter</a> does the same counting in your browser and shows the total at API rates. Your files never leave your computer.</p>
<h2>Or let something keep the numbers for you</h2>
<p>NeverPayTwice is a small app we make. It reads your Claude Code logs the same careful way, shows your usage and its API-rate cost per day and per model, against a monthly budget you set, and flags every time you paid again for something you had already bought. It runs on your own computer and your usage data is not uploaded. Mac, Windows or Linux, $9.99 to start and $2.99 a month to keep (your first month is included).</p>
<p>Sources: Anthropic's <a href="https://claude.com/pricing">plans and pricing page</a> (plan prices, usage wording, API credits) and <a href="https://platform.claude.com/docs/en/about-claude/pricing">API pricing page</a>, checked November 14, 2026. Prices and plans can change; check the current pages if something doesn't match.</p>
<p>Try the <a href="https://neverpaytwice.com/app/?demo">demo with sample data</a>, no sign-up, or <a href="https://neverpaytwice.gumroad.com/l/neverpaytwice">get NeverPayTwice</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Does Claude prompt caching save money? The break-even math]]></title><description><![CDATA[Originally published at neverpaytwice.com. Short answer: usually yes, by a lot, but not always. Writing a prompt to the cache costs more than sending it…]]></description><link>https://neverpaytwice.hashnode.dev/does-claude-prompt-caching-save-money-the-break-even-math</link><guid isPermaLink="true">https://neverpaytwice.hashnode.dev/does-claude-prompt-caching-save-money-the-break-even-math</guid><category><![CDATA[claude]]></category><category><![CDATA[llm]]></category><dc:creator><![CDATA[NeverPayTwice]]></dc:creator><pubDate>Mon, 16 Nov 2026 16:53:53 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published at</em> <a href="https://neverpaytwice.com/claude-prompt-caching-cost"><em>neverpaytwice.com</em></a><em>.</em></p>
<p><strong>Short answer:</strong> usually yes, by a lot, but not always. Writing a prompt to the cache costs <strong>more</strong> than sending it normally (1.25× the input price for the 5-minute cache, 2× for the 1-hour cache). Reading it back costs far less (0.1× on most models, 0.05× on Opus 5.5 and Sonnet 5.5, 0.025× on Fable 5.1 and 5.2).</p>
<p>So the 5-minute cache pays off as soon as the cached part is <strong>read once</strong>. The 1-hour cache needs <strong>two reads</strong>. A cache that is written and never read makes that part of the prompt 25% or 100% more expensive. Below: the table, three ways it goes wrong, and a script that checks your own logs.</p>
<h2>How caching is billed</h2>
<p>When you mark part of a prompt with <code>cache_control</code>, the first request <strong>writes</strong> it to the cache and later requests that start with exactly the same text <strong>read</strong> it. Each is a separate line on the bill, priced from the model's input price:</p>
<table>
<thead>
<tr>
<th>What happens</th>
<th>Price</th>
</tr>
</thead>
<tbody><tr>
<td>Write, 5-minute cache (the default)</td>
<td>1.25 × input price</td>
</tr>
<tr>
<td>Write, 1-hour cache (<code>"ttl": "1h"</code>)</td>
<td>2 × input price</td>
</tr>
<tr>
<td>Read (a cache hit)</td>
<td>0.1 × input price on most models; 0.05× on Claude Opus 5.5 and Sonnet 5.5; 0.025× on Claude Fable 5.1 and 5.2</td>
</tr>
</tbody></table>
<p>Every read restarts the cache's lifetime at no extra cost. So requests that share a prefix and start less than 5 minutes apart keep the default cache alive for as long as they keep coming.</p>
<h2>The break-even point</h2>
<p>Take one cached prompt section that is written once and then read n times while the cache is alive. Measured in "the price of sending that section once":</p>
<pre><code class="language-plaintext">with caching:    write + n × read
without caching: n + 1
caching wins when n &gt; (write − 1) ÷ (1 − read)
</code></pre>
<p>For the 5-minute cache that is n &gt; 0.26 to 0.28 depending on the read price: <strong>one read</strong> is enough. For the 1-hour cache it is n &gt; 1.03 to 1.11 depending on the read price: <strong>two reads</strong>. What you save on the cached section, for a few values of n:</p>
<table>
<thead>
<tr>
<th>Cache · read</th>
<th>0 reads</th>
<th>1 read</th>
<th>2 reads</th>
<th>5 reads</th>
<th>20 reads</th>
</tr>
</thead>
<tbody><tr>
<td>5-min · 0.1×</td>
<td>−25%</td>
<td>32.5%</td>
<td>51.7%</td>
<td>70.8%</td>
<td>84.5%</td>
</tr>
<tr>
<td>5-min · 0.05×</td>
<td>−25%</td>
<td>35.0%</td>
<td>55.0%</td>
<td>75.0%</td>
<td>89.3%</td>
</tr>
<tr>
<td>5-min · 0.025×</td>
<td>−25%</td>
<td>36.3%</td>
<td>56.7%</td>
<td>77.1%</td>
<td>91.7%</td>
</tr>
<tr>
<td>1-hour · 0.1×</td>
<td>−100%</td>
<td>−5.0%</td>
<td>26.7%</td>
<td>58.3%</td>
<td>81.0%</td>
</tr>
<tr>
<td>1-hour · 0.05×</td>
<td>−100%</td>
<td>−2.5%</td>
<td>30.0%</td>
<td>62.5%</td>
<td>85.7%</td>
</tr>
<tr>
<td>1-hour · 0.025×</td>
<td>−100%</td>
<td>−1.2%</td>
<td>31.7%</td>
<td>64.6%</td>
<td>88.1%</td>
</tr>
</tbody></table>
<p>Negative means caching cost more than not caching. These percentages are for the cached part of the prompt only; new input and output tokens cost the same either way.</p>
<p><strong>Worked example.</strong> A 20,000-token system prompt on Claude Sonnet 5.5 ($2 per million input tokens), used by 10 requests within a few minutes. Without caching: 10 × 20,000 × $2 ÷ 1,000,000 = <strong>$0.40</strong>. With the 5-minute cache: one write (20,000 × $2 × 1.25 = $0.05) plus nine reads (9 × 20,000 × $0.10 = $0.018) = <strong>$0.068</strong>, 83% less.</p>
<h2>Three ways caching quietly costs you more</h2>
<ul>
<li><strong>The prefix keeps changing.</strong> The cache matches the start of the prompt exactly, byte for byte. A timestamp, a request ID or tools listed in a different order near the top means every request writes a new entry and none reads one. In the example above that is ten writes: $0.50 instead of $0.40, 25% more than not caching at all.</li>
<li><strong>Requests are further apart than the cache lasts.</strong> Requests every 10 minutes never hit a 5-minute cache, so each one pays for a write. Six requests over an hour: 6 × 1.25 = 7.5 "prompt prices" instead of 6. The 1-hour cache fits that pattern: one write and five reads is 2 + 5 × 0.05 = 2.25 on Sonnet 5.5, 62.5% less than not caching.</li>
<li><strong>The 1-hour cache for traffic that is already continuous.</strong> If requests come less than 5 minutes apart, each read keeps the default cache alive anyway. Paying 2× instead of 1.25× for the write buys nothing.</li>
</ul>
<p>One thing that does not cost you: a prompt shorter than the model's minimum (512 tokens on the current Claude models, up to 4,096 on some older ones) simply isn't cached, with no error and no write charge. You can tell because both cache fields come back as 0.</p>
<h2>How to see it in your own numbers</h2>
<p>Every response's <code>usage</code> block has the counts: <code>cache_creation_input_tokens</code> (written), <code>cache_read_input_tokens</code> (read) and <code>input_tokens</code> (neither). If the reads stay at zero across requests that should share a prefix, something at the start of the prompt is changing. A healthy setup reads many tokens for every token it writes.</p>
<p>This script adds it up from your logs and compares what you paid with what the same tokens would have cost with no caching. It reads JSON Lines files with a model and a usage block on each line (log <code>response.model</code> and <code>response.usage.to_dict()</code> from the Python SDK), and also Claude Code's own logs in <code>~/.claude/projects</code>, priced at API rates. It prints numbers only and sends nothing anywhere. (<a href="https://neverpaytwice.com/claude_cache_savings.py">Download it</a>, or get it with the other scripts <a href="https://github.com/neverpaytwice/ai-token-cost-scripts">on GitHub</a>.)</p>
<pre><code class="language-plaintext">python3 claude_cache_savings.py ~/.claude/projects
</code></pre>
<pre><code class="language-plaintext">Requests:              2
Input tokens:          40020  (50% read from cache, 50% written to cache)
Reads per written token: 1.0
You paid:              $0.0580
Without caching:       $0.0860
Caching saved:  $0.0280 (32.5%)
</code></pre>
<p>That sample is two Sonnet 5.5 requests that shared a 20,000-token prefix: one write, one read, the 32.5% from the table. The core of it:</p>
<pre><code class="language-plaintext">WRITE_5M, WRITE_1H = 1.25, 2.0

def costs(model, usage, prices=PRICES):
    """(paid, without caching) in USD for one request, or None if the model has no price."""
    p = prices.get(model)
    if p is None:
        return None
    new_in = usage.get("input_tokens") or 0
    writes = usage.get("cache_creation_input_tokens") or 0
    w1h = (usage.get("cache_creation") or {}).get("ephemeral_1h_input_tokens") or 0
    w5 = max(0, writes - w1h)
    read = usage.get("cache_read_input_tokens") or 0
    out = usage.get("output_tokens") or 0
    paid = (new_in * p["input"] + w5 * p["input"] * WRITE_5M + w1h * p["input"] * WRITE_1H
            + read * p["cache_read"] + out * p["output"]) / 1_000_000
    no_cache = ((new_in + writes + read) * p["input"] + out * p["output"]) / 1_000_000
    return paid, no_cache
</code></pre>
<p>We tested it on 33 usage blocks across 11 models, including 1-hour cache writes: the cost it computes matches NeverPayTwice's own engine every time. It keeps one record per response when Claude Code logs the same response several times, and it lists any model it has no price for instead of counting it as free. It uses standard rates only; the Batch API, US-only inference and fast mode change prices and are not applied.</p>
<h2>Or let something record it for you</h2>
<p>NeverPayTwice is a small app we make. Its live meter sits on your own computer between your code and the API (<code>ANTHROPIC_BASE_URL=http://127.0.0.1:8098/anthropic</code>) and keeps a receipt for every request with new input, cache writes and cache reads priced separately, so you can see when cache writes are not followed by reads. It never blocks or changes a request, and API keys are never stored. It also flags every time you paid again for a request you had already bought. Works with Anthropic, OpenAI, Google Gemini and compatible APIs. Mac, Windows or Linux, $9.99 to start and $2.99 a month to keep (your first month is included).</p>
<p>Sources: Anthropic's <a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching">prompt caching guide</a> (write and read prices, cache lifetime and refresh, minimum lengths) and <a href="https://platform.claude.com/docs/en/about-claude/pricing">pricing page</a>, checked November 14, 2026. Prices can change; check the current pages if something doesn't match.</p>
<p>Try the <a href="https://neverpaytwice.com/app/?demo">demo with sample data</a>, no sign-up, or <a href="https://neverpaytwice.gumroad.com/l/neverpaytwice">get NeverPayTwice</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Claude thinking tokens: what they cost and how to spend less]]></title><description><![CDATA[Originally published at neverpaytwice.com. Short answer: thinking tokens are billed as output tokens, at the output price, whether or not you see them. On…]]></description><link>https://neverpaytwice.hashnode.dev/claude-thinking-tokens-what-they-cost-and-how-to-spend-less</link><guid isPermaLink="true">https://neverpaytwice.hashnode.dev/claude-thinking-tokens-what-they-cost-and-how-to-spend-less</guid><category><![CDATA[claude]]></category><category><![CDATA[llm]]></category><dc:creator><![CDATA[NeverPayTwice]]></dc:creator><pubDate>Mon, 16 Nov 2026 13:15:52 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published at</em> <a href="https://neverpaytwice.com/claude-thinking-tokens-cost"><em>neverpaytwice.com</em></a><em>.</em></p>
<p><strong>Short answer:</strong> thinking tokens are billed as output tokens, at the output price, whether or not you see them. On the newest Claude models thinking is on by default and its text comes back empty unless you ask for a summary, so it is easy to pay for a lot of it without noticing.</p>
<p>Each response tells you how much was thinking. The main way to spend less is the <code>effort</code> setting; on some models you can also switch thinking off.</p>
<h2>How thinking is billed</h2>
<p>Thinking is counted inside <code>usage.output_tokens</code>, and output is the most expensive kind of token: five times the input price on current Claude models. <code>usage.output_tokens_details.thinking_tokens</code> tells you how many of the output tokens were thinking.</p>
<p>Example: a Claude Sonnet 5.5 response with 400 output tokens, 150 of them thinking. Output costs $10 per million tokens, so the thinking cost 150 × $10 ÷ 1,000,000 = <strong>$0.0015</strong> and the visible answer $0.0025. Small for one response, but at the same ratio thinking is over a third of every output dollar you spend.</p>
<p><strong>Hidden is not free.</strong> On Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2 and other recent models, the default display setting returns thinking blocks with empty text. Setting <code>thinking: {"type": "adaptive", "display": "summarized"}</code> shows a readable summary instead. The display setting only changes what you see: the thinking happens, and is billed, the same either way.</p>
<h2>Can you turn thinking off?</h2>
<p>It depends on the model. From Anthropic's API reference:</p>
<table>
<thead>
<tr>
<th>Model</th>
<th>Thinking by default</th>
<th>Turning it off</th>
<th>Default effort</th>
</tr>
</thead>
<tbody><tr>
<td>Claude Opus 5.5</td>
<td>On</td>
<td>Not possible: <code>{"type": "disabled"}</code> returns an error. Lower the effort instead.</td>
<td>medium</td>
</tr>
<tr>
<td>Claude Sonnet 5.5</td>
<td>On</td>
<td><code>{"type": "between_tools"}</code>, at effort high or below. <code>disabled</code> returns an error.</td>
<td>high</td>
</tr>
<tr>
<td>Claude Haiku 5.5</td>
<td>On</td>
<td><code>{"type": "disabled"}</code>, at effort high or below</td>
<td>medium</td>
</tr>
<tr>
<td>Claude Fable 5.2</td>
<td>Always on</td>
<td>Not possible. Lower the effort instead.</td>
<td>high</td>
</tr>
<tr>
<td>Claude Opus 5</td>
<td>On</td>
<td><code>{"type": "disabled"}</code>, at effort high or below</td>
<td>high</td>
</tr>
<tr>
<td>Claude Opus 4.8 / 4.7</td>
<td>Off unless you set <code>{"type": "adaptive"}</code></td>
<td>Leave it out, or <code>disabled</code></td>
<td>high</td>
</tr>
</tbody></table>
<p>The old fixed thinking budget (<code>budget_tokens</code>) is gone on these models: sending it returns an error. Effort replaced it.</p>
<h2>Effort: the main dial</h2>
<p>Effort goes in <code>output_config</code> and takes <code>low</code>, <code>medium</code>, <code>high</code>, <code>xhigh</code> or <code>max</code>. It controls how deeply the model thinks and how many tokens it spends overall; lower effort also means fewer tool calls and shorter replies around them.</p>
<pre><code class="language-plaintext">response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    output_config={"effort": "low"},
    messages=[{"role": "user", "content": "Classify this ticket: ..."}],
)
print(response.usage)   # output_tokens includes the thinking
</code></pre>
<p>Anthropic's guidance: chat, classification and other high-volume, simple requests often do well at <code>low</code>, with <code>medium</code> as the step down where quality holds; coding and long multi-step agent work gain the most from higher effort. Try a lower effort on a sample of real requests and compare the answers before changing it everywhere, and judge cost per finished task: a cheaper request that needs a retry isn't cheaper.</p>
<h2>Two mistakes that make thinking cost more</h2>
<p><code>max_tokens</code> <strong>too low.</strong> Thinking counts toward <code>max_tokens</code>. If the limit is too tight, the response stops partway with <code>stop_reason: "max_tokens"</code>, you pay for every token it produced, and you have to run it again. Don't set it lower than the job needs.</p>
<p><strong>Changing effort in the middle of a conversation.</strong> Changing the top-level effort between turns invalidates the prompt cache for the conversation, so the next request pays full price for history that was cached. Pick an effort per kind of request and keep it. (On the newest models a per-message effort setting avoids this; it is in beta.)</p>
<h2>How much of your bill is thinking?</h2>
<p>Save each response's JSON as one line in a file (in Python, <code>message.to_json()</code>) and run our free bill-check script on it. One of the lines it prints is "thinking (billed as output)", with its dollar amount and share of the total. It prints numbers only and sends nothing anywhere. (<a href="https://neverpaytwice.com/claude_api_bill_check.py">Download it</a>, or get it with the other scripts <a href="https://github.com/neverpaytwice/ai-token-cost-scripts">on GitHub</a>.)</p>
<pre><code class="language-plaintext">python3 claude_api_bill_check.py responses.jsonl
</code></pre>
<p>If thinking is a large share and the requests are simple, effort is the first thing to test. The <a href="https://neverpaytwice.com/claude-api-bill-too-high">nine things to check when the bill is high</a> covers the other usual causes.</p>
<h2>Or let something watch the bill for you</h2>
<p>NeverPayTwice is a small app we make. It tracks your AI usage and its cost per day and per model against a monthly budget you set, flags every time you paid again for something you had already bought, and keeps a receipt for each AI purchase. It runs on your own computer; your usage data is not uploaded and API keys are never stored. Mac, Windows or Linux, $9.99 to start and $2.99 a month to keep (your first month is included).</p>
<p>Sources: Anthropic's API documentation on extended and adaptive thinking, the effort setting and model migration, and the <a href="https://platform.claude.com/docs/en/about-claude/pricing">API pricing page</a>, checked November 15, 2026. Model behaviour and prices change; check the current pages if something doesn't match.</p>
<p>Try the <a href="https://neverpaytwice.com/app/?demo">demo with sample data</a>, no sign-up, or <a href="https://neverpaytwice.gumroad.com/l/neverpaytwice">get NeverPayTwice</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Claude Batch API: half price, if you can wait]]></title><description><![CDATA[Originally published at neverpaytwice.com. Short answer: Anthropic's Message Batches API charges 50% of the standard price on all usage: input, output…]]></description><link>https://neverpaytwice.hashnode.dev/claude-batch-api-half-price-if-you-can-wait</link><guid isPermaLink="true">https://neverpaytwice.hashnode.dev/claude-batch-api-half-price-if-you-can-wait</guid><category><![CDATA[claude]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[NeverPayTwice]]></dc:creator><pubDate>Sun, 15 Nov 2026 19:22:15 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published at</em> <a href="https://neverpaytwice.com/claude-batch-api-cost"><em>neverpaytwice.com</em></a><em>.</em></p>
<p><strong>Short answer:</strong> Anthropic's Message Batches API charges <strong>50% of the standard price on all usage</strong>: input, output, cache writes and cache reads. You send up to 100,000 requests at once and collect the answers later. Most batches finish within an hour; a batch can take up to 24 hours.</p>
<p>If nobody is waiting for the answer (nightly jobs, classification, evaluations, backfills), batching halves that part of your bill with no change in quality. If a person is waiting, it isn't an option.</p>
<h2>Batch prices</h2>
<p>USD per million tokens, from Anthropic's batch processing page:</p>
<table>
<thead>
<tr>
<th>Model</th>
<th>Standard input / output</th>
<th>Batch input / output</th>
</tr>
</thead>
<tbody><tr>
<td>Claude Opus 5.5</td>
<td>$4 / $20</td>
<td>$2 / $10</td>
</tr>
<tr>
<td>Claude Sonnet 5.5</td>
<td>$2 / $10</td>
<td>$1 / $5</td>
</tr>
<tr>
<td>Claude Haiku 5.5 (prompts up to 100K tokens)</td>
<td>$0.10 / $0.50</td>
<td>$0.05 / $0.25</td>
</tr>
<tr>
<td>Claude Haiku 5.5 (prompts over 100K tokens)</td>
<td>$0.50 / $2.50</td>
<td>$0.25 / $1.25</td>
</tr>
<tr>
<td>Claude Fable 5.2</td>
<td>$8 / $40</td>
<td>$4 / $20</td>
</tr>
<tr>
<td>Claude Opus 4.8</td>
<td>$5 / $25</td>
<td>$2.50 / $12.50</td>
</tr>
<tr>
<td>Claude Sonnet 4.6</td>
<td>$3 / $15</td>
<td>$1.50 / $7.50</td>
</tr>
<tr>
<td>Claude Haiku 4.5</td>
<td>$1 / $5</td>
<td>$0.50 / $2.50</td>
</tr>
</tbody></table>
<p>An example: an Opus 5.5 request with 5,000 input tokens and 800 output tokens costs (5,000 × $4 + 800 × $20) ÷ 1,000,000 = <strong>$0.036</strong> at the standard rate and <strong>$0.018</strong> in a batch. Ten thousand of them a month: $360 or $180.</p>
<h2>What fits in a batch, and what doesn't</h2>
<ul>
<li><strong>Good fits:</strong> nightly or weekly summaries, tagging and classifying records, running evaluations, filling in old data, generating content in bulk. Anything where an answer in an hour, or by tomorrow, is fine.</li>
<li><strong>Bad fits:</strong> chat and anything else a person is waiting on, and agent loops where each step needs the previous answer. Each request in a batch is answered once, on its own; there is no back-and-forth inside a batch.</li>
<li><strong>Not available in a batch:</strong> streaming, fast mode (the <code>speed</code> setting), server-side fallbacks and <code>max_tokens: 0</code>. Almost everything else in the Messages API works, including tools, images and prompt caching.</li>
</ul>
<h2>The rules worth knowing</h2>
<ul>
<li><strong>Size:</strong> up to 100,000 requests or 256 MB per batch, whichever comes first.</li>
<li><strong>Time:</strong> most batches finish within an hour. A batch that isn't done after 24 hours expires, and the requests that never ran are marked <code>expired</code>.</li>
<li><strong>You don't pay for failures:</strong> requests that come back <code>errored</code>, <code>canceled</code> or <code>expired</code> aren't billed.</li>
<li><strong>Order:</strong> results can come back in any order. Give each request a <code>custom_id</code> and match on it, never on position.</li>
<li><strong>Results expire too:</strong> they can be downloaded for 29 days after the batch was created.</li>
<li><strong>No edits:</strong> a submitted batch can't be changed. Cancel it and send a new one.</li>
<li><strong>Separate limits:</strong> batches have their own rate limits and don't use up your normal Messages API limits.</li>
</ul>
<h2>Batching and prompt caching together</h2>
<p>The two discounts stack: a cache read inside a batch costs half the normal cache-read price. But requests in a batch run at the same time and in any order, so cache hits are best-effort; Anthropic says users typically see cache hit rates from 30% to 98%. To raise yours, put identical <code>cache_control</code> blocks in every request and share as much of the prompt as you can. Because a batch can run longer than five minutes, Anthropic also suggests the 1-hour cache for shared context. <a href="https://neverpaytwice.com/claude-prompt-caching-cost">The caching break-even math</a> shows when the 1-hour cache pays off.</p>
<h2>What a batch looks like</h2>
<p>In Python, with Anthropic's official SDK:</p>
<pre><code class="language-plaintext">import anthropic
from anthropic.types.message_create_params import MessageCreateParamsNonStreaming
from anthropic.types.messages.batch_create_params import Request

client = anthropic.Anthropic()
batch = client.messages.batches.create(requests=[
    Request(custom_id=f"item-{i}", params=MessageCreateParamsNonStreaming(
        model="claude-sonnet-5-5", max_tokens=1024,
        messages=[{"role": "user", "content": text}]))
    for i, text in enumerate(texts)
])
# later: when client.messages.batches.retrieve(batch.id).processing_status == "ended"
for r in client.messages.batches.results(batch.id):
    if r.result.type == "succeeded":
        print(r.custom_id, r.result.message.usage)
</code></pre>
<h2>What would batching save you?</h2>
<p>Save each response's JSON as one line in a file (in Python, <code>message.to_json()</code>). If you add a field such as <code>"job"</code> to each line, the script groups the totals by it, so you can see which jobs are worth moving. It prices every response at the standard and the batch rate. It also reads a batch results file, so you can check what a batch actually cost you. It prints numbers only and sends nothing anywhere. (<a href="https://neverpaytwice.com/claude_batch_savings.py">Download it</a>, or get it with the other scripts <a href="https://github.com/neverpaytwice/ai-token-cost-scripts">on GitHub</a>.)</p>
<pre><code class="language-plaintext">python3 claude_batch_savings.py responses.jsonl --by job
</code></pre>
<p>Example output (made-up data):</p>
<pre><code class="language-plaintext">job                    responses      standard    batch rate   difference
nightly-summaries           1200      $21.5327      $10.7664     $10.7664
evals                        500      $18.6521       $9.3261      $9.3261
chat                         300       $7.1660       $3.5830      $3.5830
total                       2000      $47.3508      $23.6754     $23.6754
</code></pre>
<p>Chat can't wait, so leave it out: moving the nightly summaries and the evals saves $20.09 of $47.35 here, about 42% of the whole bill.</p>
<p>We tested the script on hand-checked cases: its standard prices match our <a href="https://neverpaytwice.com/claude-api-bill-too-high">bill-check script</a> on every response, it reads both saved responses and batch result files, it leaves errored, canceled and expired batch results out of the totals, and it lists anything it can't price instead of counting it as free. Fast-mode responses are priced at the standard rate, since a batched copy would run at normal speed.</p>
<h2>Or let something watch the bill for you</h2>
<p>NeverPayTwice is a small app we make. It tracks your AI usage and its cost per day and per model against a monthly budget you set, flags every time you paid again for something you had already bought, and keeps a receipt for each AI purchase. It runs on your own computer; your usage data is not uploaded and API keys are never stored. Mac, Windows or Linux, $9.99 to start and $2.99 a month to keep (your first month is included).</p>
<p>Sources: Anthropic's <a href="https://platform.claude.com/docs/en/build-with-claude/batch-processing">batch processing page</a> (prices, limits, result types, caching) and <a href="https://platform.claude.com/docs/en/about-claude/pricing">API pricing page</a>, checked November 15, 2026. Prices can change; check the current pages if something doesn't match.</p>
<p>Try the <a href="https://neverpaytwice.com/app/?demo">demo with sample data</a>, no sign-up, or <a href="https://neverpaytwice.gumroad.com/l/neverpaytwice">get NeverPayTwice</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Why is my Claude API bill so high? 9 things to check]]></title><description><![CDATA[Originally published at neverpaytwice.com. Short answer: the usual causes are thinking tokens you never see but pay for as output, a prompt cache that…]]></description><link>https://neverpaytwice.hashnode.dev/why-is-my-claude-api-bill-so-high-9-things-to-check</link><guid isPermaLink="true">https://neverpaytwice.hashnode.dev/why-is-my-claude-api-bill-so-high-9-things-to-check</guid><category><![CDATA[claude]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[NeverPayTwice]]></dc:creator><pubDate>Sun, 15 Nov 2026 17:35:19 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published at</em> <a href="https://neverpaytwice.com/claude-api-bill-too-high"><em>neverpaytwice.com</em></a><em>.</em></p>
<p><strong>Short answer:</strong> the usual causes are thinking tokens you never see but pay for as output, a prompt cache that silently never hits, the whole conversation being sent again on every turn, and paying a premium you didn't need (fast mode, a bigger model, real-time instead of batch).</p>
<p>Every response tells you exactly what you paid for in its <code>usage</code> block. Save those blocks, and the free script below shows where the money went, which requests skipped the cache, and which ones it can't price.</p>
<h2>1. Thinking you never see is billed as output</h2>
<p>On current models thinking is on by default, and on Claude Opus 5.5 it can't be switched off. The thinking happens and is billed the same whether or not you display it, and on the newest models the default display shows nothing, so it is easy to miss. Thinking tokens are counted inside <code>output_tokens</code>, at the output price, which is five times the input price. <code>usage.output_tokens_details.thinking_tokens</code> tells you how much of the output was thinking.</p>
<p><strong>Fix:</strong> use the <code>effort</code> setting (<code>output_config.effort</code>). It controls how deeply the model thinks and how many tokens it spends overall. Simple tasks such as classification or short chat often do fine at <code>low</code>. Measure quality on real requests before and after. <a href="https://neverpaytwice.com/claude-thinking-tokens-cost">More on thinking costs</a>.</p>
<h2>2. The prompt cache never hits</h2>
<p>Caching works on an exact prefix: any change anywhere early in the prompt makes everything after it miss. A timestamp or request ID in the system prompt, JSON written with keys in a different order, or a tool list that changes between calls will each stop the cache from ever hitting, without any error. Prompts shorter than the model's minimum cacheable length (between 512 and 4,096 tokens, depending on the model) are not cached either.</p>
<p><strong>Check:</strong> if <code>cache_read_input_tokens</code> stays at zero on requests that share a long beginning, something is changing the prefix. Put stable content first and anything that varies after the last cache breakpoint. <a href="https://neverpaytwice.com/claude-prompt-caching-cost">The caching break-even math</a> shows when caching pays off.</p>
<h2>3. Every turn sends the whole conversation again</h2>
<p>The API keeps no memory between requests, so a chat or agent loop sends the full history every time. Turn 30 pays for turns 1 to 29 again as input. Without caching, the cost of a long conversation grows much faster than its length.</p>
<p><strong>Fix:</strong> cache the conversation so earlier turns are read from the cache at a fraction of the price, keep tool results short, and start fresh conversations when the old context no longer matters.</p>
<h2>4. Cache writes cost more than plain input</h2>
<p>Writing to the cache costs 1.25 times the input price for the 5-minute cache and 2 times for the 1-hour cache. If you write a lot to the cache and rarely read it back, caching costs you more than it saves. The 1-hour cache only pays off when the same prefix is read at least twice.</p>
<h2>5. Fast mode doubles the price</h2>
<p>Fast mode on Claude Opus 5.5 costs $8 per million input tokens and $40 per million output tokens, twice the standard rate. If <code>usage.speed</code> says <code>"fast"</code> on requests where nobody is waiting, you are paying double for speed you don't need.</p>
<h2>6. Work that could wait isn't batched</h2>
<p>The Message Batches API runs requests asynchronously at half the price. Nightly summaries, bulk classification, evaluations and backfills rarely need an answer in seconds. <a href="https://neverpaytwice.com/claude-batch-api-cost">Batch prices and limits</a>.</p>
<h2>7. A bigger model than the job needs</h2>
<p>Claude Opus 5.5 costs $4 / $20 per million input / output tokens; Claude Sonnet 5.5 costs $2 / $10, half as much; Claude Haiku 5.5 costs $0.10 / $0.50. But judge cost per finished task, not per request: a cheaper model that needs more retries or turns isn't cheaper. Lowering effort on the model you already use is often worth trying first.</p>
<h2>8. Long prompts on Haiku 5.5</h2>
<p>Claude Haiku 5.5's $0.10 / $0.50 price covers prompts up to 100,000 tokens. Above that it is $0.50 / $2.50, five times as much. A pipeline that occasionally sends a huge document to Haiku can cost far more than expected.</p>
<h2>9. Paying twice for the same answer</h2>
<p>Retries after timeouts, double-clicks and pipelines that re-run can send the same request more than once. The official SDKs also retry some failed requests automatically (twice by default). Each repeat that completes is billed as a new request. <a href="https://neverpaytwice.com/duplicate-ai-api-charges">How to spot duplicate AI API charges</a> has a script that finds them.</p>
<p>Smaller items that also change the price: US-only inference (<code>inference_geo: "us"</code>) adds 10%, and web search is charged per search on top of tokens.</p>
<h2>See where your own money goes</h2>
<p>Save each response's JSON as one line in a file (in Python, <code>message.to_json()</code> gives you that line), then run the script on the file. It prices every response at Anthropic's standard rates, splits the cost into new input, cache writes, cache reads, output and thinking, and lists the requests that sent a lot of new input with no cache reads. It prints numbers only and sends nothing anywhere. (<a href="https://neverpaytwice.com/claude_api_bill_check.py">Download it</a>, or get it with the other scripts <a href="https://github.com/neverpaytwice/ai-token-cost-scripts">on GitHub</a>.)</p>
<pre><code class="language-bash">python3 claude_api_bill_check.py responses.jsonl
</code></pre>
<p>Example output (made-up data: 400 responses, where the first 150 sent a 12,000-token system prompt without caching):</p>
<pre><code class="language-plaintext">400 responses, $14.8819 at standard API rates

Where the money went:
  new input                    $    7.5466   50.7%
  output (not thinking)        $    3.5290   23.7%
  thinking (billed as output)  $    3.2231   21.7%
  cache reads                  $    0.5232    3.5%
  cache writes (5 min)         $    0.0600    0.4%
  cache writes (1 hour)        $    0.0000    0.0%

By model:
  claude-opus-5-5              $   12.7058
  claude-sonnet-5-5            $    2.1761

Prompt tokens read from cache: 57.9%
150 responses sent 10,000+ new input tokens with no cache reads (lines: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ...)
</code></pre>
<p>In this example, half the bill is new input, and the 150 uncached requests are where it came from. Thinking is over a fifth of the bill, so effort is worth testing too.</p>
<p>We tested the script on hand-checked cases: its per-response prices match our tested <a href="https://neverpaytwice.com/anthropic-api-cost-per-request">per-request cost function</a> to the cent, it skips lines that aren't responses, and it lists anything it can't price instead of counting it as free: models it has no price for, fast mode on models other than Opus 5.5, and Haiku 5.5 prompts over 100,000 tokens. Batch and US-only prices are not applied.</p>
<h2>Or let something watch the bill for you</h2>
<p>NeverPayTwice is a small app we make. It tracks your AI usage and its cost per day and per model against a monthly budget you set, flags every time you paid again for something you had already bought, and keeps a receipt for each AI purchase. It runs on your own computer; your usage data is not uploaded and API keys are never stored. Mac, Windows or Linux, $9.99 to start and $2.99 a month to keep (your first month is included).</p>
<p>Sources: Anthropic's <a href="https://platform.claude.com/docs/en/about-claude/pricing">API pricing page</a> and API documentation on thinking, effort, prompt caching, fast mode and message batches, checked November 15, 2026. Prices can change; check the current pages if something doesn't match.</p>
<p>Try the <a href="https://neverpaytwice.com/app/?demo">demo with sample data</a>, no sign-up, or <a href="https://neverpaytwice.gumroad.com/l/neverpaytwice">get NeverPayTwice</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Why your Claude Code token count is wrong (and how to get the real number)]]></title><description><![CDATA[Originally published at neverpaytwice.com. Short answer: Claude Code writes each AI response to its log several times, and every copy carries the full…]]></description><link>https://neverpaytwice.hashnode.dev/why-your-claude-code-token-count-is-wrong-and-how-to-get-the-real-number</link><guid isPermaLink="true">https://neverpaytwice.hashnode.dev/why-your-claude-code-token-count-is-wrong-and-how-to-get-the-real-number</guid><category><![CDATA[claude]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[NeverPayTwice]]></dc:creator><pubDate>Sun, 15 Nov 2026 17:18:17 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published at</em> <a href="https://neverpaytwice.com/claude-code-token-count"><em>neverpaytwice.com</em></a><em>.</em></p>
<p><strong>Short answer:</strong> Claude Code writes each AI response to its log several times, and every copy carries the full token count. If you add up every line, you count most responses two or more times.</p>
<p>On the made-up sample log in our free scripts repo (30 responses, each logged 2 to 4 times, as Claude Code does), a plain sum says <strong>5.3M tokens</strong>. The real figure is <strong>1.8M</strong>. To get the right number, count each response once. <a href="https://neverpaytwice.com/count">Our free counter</a> does that in your browser, or use the short script below.</p>
<h2>Where Claude Code keeps its usage logs</h2>
<p>Claude Code keeps a local log of every session. They live in a hidden folder in your home directory:</p>
<table>
<thead>
<tr>
<th>System</th>
<th>Folder</th>
</tr>
</thead>
<tbody><tr>
<td>Mac and Linux</td>
<td><code>~/.claude/projects</code></td>
</tr>
<tr>
<td>Windows</td>
<td><code>%USERPROFILE%\.claude\projects</code></td>
</tr>
</tbody></table>
<p>Inside there is one folder per project, holding <code>.jsonl</code> files (mostly one per session). Each line is one JSON event. Lines for AI responses carry a <code>usage</code> block with four token counts:</p>
<ul>
<li><code>input_tokens</code>: new input sent to the model</li>
<li><code>output_tokens</code>: what the model wrote back</li>
<li><code>cache_creation_input_tokens</code>: input written to the prompt cache</li>
<li><code>cache_read_input_tokens</code>: input read back from the cache (much cheaper than new input)</li>
</ul>
<h2>Why adding up the logs gives the wrong answer</h2>
<p>It looks simple: add the <code>usage</code> numbers on every line. But three things in how the logs are written make that total too high.</p>
<ul>
<li><strong>One response, several lines.</strong> A single response is written once per content block: thinking, text, and each tool call. Every one of those lines repeats the usage of the whole response. A response with a thinking block, some text and two tool calls can appear four times.</li>
<li><strong>Resumed sessions copy their history.</strong> When you resume a session, earlier lines can be copied into a new log file, so the same response shows up in more than one file.</li>
<li><strong>Early lines are incomplete.</strong> While a response streams, the first lines can carry a partial output count. Only the last one is final, so even picking "any one line" can under-count output.</li>
</ul>
<p>None of this means you were billed twice. Each response is one request to the API. The over-count only appears when you total the log lines yourself, for example to estimate spending or build a dashboard.</p>
<h2>How to count correctly</h2>
<p>Every response line carries a <code>message.id</code> and a <code>requestId</code>. Together they identify one response. So:</p>
<ul>
<li>Keep one record per (<code>message.id</code>, <code>requestId</code>) pair, across all files.</li>
<li>For its output tokens, use the largest value seen for that pair (the final streaming count).</li>
<li>Skip lines that are not real responses: <code>"model": "&lt;synthetic&gt;"</code> and API error messages.</li>
</ul>
<h2>A short script to do it yourself</h2>
<p>This Python 3 script follows the rules above. It only reads your logs and prints three numbers. (<a href="https://neverpaytwice.com/count_claude_code_tokens.py">Download it</a>, or get it with the other scripts <a href="https://github.com/neverpaytwice/ai-token-cost-scripts">on GitHub</a>.)</p>
<pre><code class="language-python">import json, pathlib, sys

root = pathlib.Path(sys.argv[1]) if len(sys.argv) &gt; 1 else pathlib.Path.home() / ".claude" / "projects"
best, plain = {}, 0

for f in sorted(root.rglob("*.jsonl")):
    n = 0
    for line in f.open(encoding="utf-8", errors="replace"):
        try:
            o = json.loads(line)
        except ValueError:
            continue
        if not isinstance(o, dict):
            continue
        n += 1
        m = o.get("message")
        if o.get("type") != "assistant" or not isinstance(m, dict) or not m.get("usage"):
            continue
        if m.get("model") == "&lt;synthetic&gt;" or o.get("isApiErrorMessage"):
            continue
        u = m["usage"]
        t = [u.get("input_tokens") or 0, u.get("output_tokens") or 0,
             u.get("cache_creation_input_tokens") or 0, u.get("cache_read_input_tokens") or 0]
        plain += sum(t)
        if m.get("id") or o.get("requestId"):
            key = (m.get("id") or "", o.get("requestId") or "")
        else:
            key = (str(f), n)
        if key not in best:
            best[key] = t
        else:
            best[key][1] = max(best[key][1], t[1])  # keep the final (largest) output count

real = sum(sum(t) for t in best.values())
print(f"{len(best):,} responses in {root}")
print(f"Plain sum of the logs: {plain:,} tokens")
print(f"Real usage:            {real:,} tokens" + (f"  (the plain sum is {plain / real:.2f}x too high)" if real else ""))
</code></pre>
<p>Run it with <code>python3 count_claude_code_tokens.py</code> (on Windows: <code>py count_claude_code_tokens.py</code>). We checked it against our app's engine on our own logs and on sample data: the totals match exactly.</p>
<h2>Turning tokens into dollars</h2>
<p>Token types are priced differently: output costs several times more than input, cache writes cost a little more than input, and cache reads cost much less. Multiply each type by your model's published per-million price, using the de-duplicated counts. On a subscription plan this shows what the same usage would cost at API rates, not what you paid.</p>
<h2>Want this every day, across every AI company?</h2>
<p>NeverPayTwice is a small app we make. It keeps this honest count up to date for Claude Code, and for any AI API you route through its live meter (Anthropic, OpenAI, Google Gemini and compatible APIs). It also flags every time you paid again for an answer you had already bought, and keeps a receipt for each purchase. It runs on your own computer (Mac, Windows or Linux), and your usage data is not uploaded. $9.99 to start and $2.99 a month to keep (your first month is included).</p>
<p>Try the <a href="https://neverpaytwice.com/app/?demo">demo with sample data</a>, no sign-up, or <a href="https://neverpaytwice.gumroad.com/l/neverpaytwice">get NeverPayTwice</a>.</p>
]]></content:encoded></item></channel></rss>