<?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: Altrouter</title>
    <description>The latest articles on DEV Community by Altrouter (@altrouter).</description>
    <link>https://dev.to/altrouter</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%2F4074301%2F00e625c9-3bcb-454b-8d4c-605837486a82.png</url>
      <title>DEV Community: Altrouter</title>
      <link>https://dev.to/altrouter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/altrouter"/>
    <language>en</language>
    <item>
      <title>Markdown is 3% of a long LLM answer and 22% of a short one</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Thu, 26 Nov 2026 12:00:02 +0000</pubDate>
      <link>https://dev.to/altrouter/markdown-is-3-of-a-long-llm-answer-and-22-of-a-short-one-pmj</link>
      <guid>https://dev.to/altrouter/markdown-is-3-of-a-long-llm-answer-and-22-of-a-short-one-pmj</guid>
      <description>&lt;p&gt;Ask a chat model a simple question through the API and you often get back a small document: a heading, a bold "Short answer", a numbered list, a tip in a quote block. If your app renders markdown, that looks nice. If it shows the reply as plain text, or reads it aloud, or stores it in a database, the user sees stray &lt;code&gt;**&lt;/code&gt; and &lt;code&gt;###&lt;/code&gt;, and you paid for every one of them.&lt;/p&gt;

&lt;p&gt;I wanted to know how much of the bill that formatting actually is. The answer depends almost entirely on one thing: how short the answer is.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads or writes; APIs bill per million of them. &lt;strong&gt;Output&lt;/strong&gt; tokens are the ones the model writes, and they cost 2 to 8 times more than &lt;strong&gt;input&lt;/strong&gt; tokens, the ones you send. &lt;strong&gt;Markdown&lt;/strong&gt; is the lightweight formatting syntax most chat models use by default: &lt;code&gt;#&lt;/code&gt; for headings, &lt;code&gt;**&lt;/code&gt; for bold, &lt;code&gt;-&lt;/code&gt; for bullets, backticks for code. A &lt;strong&gt;tokenizer&lt;/strong&gt; is the program that splits text into tokens; I used tiktoken with the &lt;code&gt;o200k_base&lt;/code&gt; encoding. Other vendors' tokenizers split text differently, so their percentages will differ somewhat.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I measured it
&lt;/h3&gt;

&lt;p&gt;I took three kinds of markdown and made a plain-text copy of each that keeps every word, number, URL and line of code, and removes only the syntax: heading marks, bold and italic markers, backticks, code fences, bullet markers, quote marks, table pipes and table separator rows. Links became &lt;code&gt;text (url)&lt;/code&gt;, so nothing readable was lost. Images and HTML tags were removed from both versions, since neither shows up in a plain-text UI.&lt;/p&gt;

&lt;p&gt;The three samples:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The 58 dev.to articles I've written so far, about 98,000 tokens of prose-heavy markdown with tables and code.&lt;/li&gt;
&lt;li&gt;The markdown README of every Python package installed on my machine that has one (9 packages, about 17,700 tokens). These are denser: lists, inline code, headings.&lt;/li&gt;
&lt;li&gt;One short answer in the style chat models give by default: two headings, three numbered steps with bold leads, two bullets, a quote-block tip. I wrote it myself, so treat it as an illustration, not a sample.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Prices are list prices from the catalog snapshot of the LLM gateway I work on: gpt-5.6 at $2 per million input tokens and $12 per million output.&lt;/p&gt;

&lt;h3&gt;
  
  
  What the syntax costs
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Text&lt;/th&gt;
&lt;th&gt;Markdown tokens&lt;/th&gt;
&lt;th&gt;Syntax share&lt;/th&gt;
&lt;th&gt;Syntax cost on gpt-5.6&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;58 articles&lt;/td&gt;
&lt;td&gt;98,125&lt;/td&gt;
&lt;td&gt;3.4%&lt;/td&gt;
&lt;td&gt;$165 per 1M answers of 400 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9 package READMEs&lt;/td&gt;
&lt;td&gt;17,661&lt;/td&gt;
&lt;td&gt;8.5%&lt;/td&gt;
&lt;td&gt;$410 per 1M answers of 400 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Short formatted answer&lt;/td&gt;
&lt;td&gt;125&lt;/td&gt;
&lt;td&gt;21.6%&lt;/td&gt;
&lt;td&gt;$324 per 1M answers of 125 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In long text the markup is a rounding error. Each piece of syntax costs only one to three tokens: &lt;code&gt;**Add a timeout.**&lt;/code&gt; is 6 tokens against 4 without the asterisks, a &lt;code&gt;###&lt;/code&gt; heading adds one, a bullet adds one, a code fence two or three. A 400-token paragraph with a heading and a few bold words barely notices.&lt;/p&gt;

&lt;p&gt;A short answer is different, because the markup doesn't shrink with the text. A two-line step still gets its bold lead and its list number. In my 125-token example, 27 tokens are syntax, more than a fifth of what you pay for. Table separator rows are the single most expensive item: &lt;code&gt;|---|---|---|&lt;/code&gt; is 7 tokens of pure decoration.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix: ask for plain text when you show plain text
&lt;/h3&gt;

&lt;p&gt;If your interface doesn't render markdown, say so in the system prompt. &lt;code&gt;Reply in plain text. Do not use markdown formatting.&lt;/code&gt; is 11 tokens, billed at input price on every call. On gpt-5.6 that's $22 per million calls; if it removes the 27 syntax tokens from an answer like my example, it saves $324 per million calls. On a cheap model like claude-haiku-5.5 ($0.10 / $0.50) the numbers are $1.10 against $13.50. On every priced chat model in that catalog output costs at least twice as much as input, so 11 input tokens that remove 27 output tokens always come out ahead.&lt;/p&gt;

&lt;p&gt;You can check the share on your own replies before you change anything:&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;re&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tiktoken&lt;/span&gt;

&lt;span class="n"&gt;enc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tiktoken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_encoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"o200k_base"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;reply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"### Steps\n\n1. **Add a timeout.** Pass `timeout=10`.\n- It can *hang forever*.\n"&lt;/span&gt;
&lt;span class="n"&gt;plain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"^#+\s+|^\s*[-*+]\s+"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;M&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\*\*|`|(?&amp;lt;!\w)\*(?=\S)|(?&amp;lt;=\S)\*(?!\w)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plain&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reply&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="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plain&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&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;"{100 * (a - b) / a:.0f}% markdown"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It prints &lt;code&gt;25 18 28% markdown&lt;/code&gt;. Run it over a few hundred real responses from your logs and you'll know whether the instruction is worth a line in your prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;The big caveat: I measured the syntax, not the length. The plain-text copies contain exactly the same words. In practice, a model told not to use markdown may also write a different answer, shorter or longer, and that difference could easily outweigh a few asterisks. I didn't call any model to check that, so test it on your own prompts and compare the output token counts in the &lt;code&gt;usage&lt;/code&gt; field of the responses.&lt;/p&gt;

&lt;p&gt;Models don't always obey the instruction. Some keep putting numbered lists or bold text in answers anyway, especially for step-by-step questions. If stray symbols must never reach the user, you still need a strip step on your side, and that step costs nothing in tokens.&lt;/p&gt;

&lt;p&gt;Finally, if your app renders markdown, keep it. Headings and lists make long answers easier to read, and at 3-9% of a long reply they're cheap. This only pays off when the formatting is thrown away, and it pays the most on short answers, which are exactly the ones where formatting helps the reader least.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>429 Error in GPT-6.2 Astra: Moving Agents to Sol</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Thu, 26 Nov 2026 07:18:14 +0000</pubDate>
      <link>https://dev.to/altrouter/429-error-in-gpt-62-astra-moving-agents-to-sol-lj9</link>
      <guid>https://dev.to/altrouter/429-error-in-gpt-62-astra-moving-agents-to-sol-lj9</guid>
      <description>&lt;p&gt;Production agents suddenly start throwing 429 Too Many Requests errors. RPM and TPM dashboards show normal levels. The account balance has funds. You check the logs and see the API rejecting requests without an obvious reason.&lt;/p&gt;

&lt;p&gt;We will break down the mechanics of the new OpenAI limits and rebuild the request logic to keep the system alive under reduced quotas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why GPT-6.2 Astra hits limits 40 percent faster
&lt;/h2&gt;

&lt;p&gt;On November 26, 2026, developers faced massive API rejections. The changes took effect without prior announcement. The update &lt;a href="https://emergent.sh/news/openai-cuts-gpt-6-2-usage-astra-sol-hit" rel="noopener noreferrer"&gt;crashed production&lt;/a&gt; for many teams relying on the new models for their business logic.&lt;/p&gt;

&lt;p&gt;OpenAI officially confirmed the cause of the failures. At the launch of GPT-6.2, the quota calculation algorithm had a bug and undercounted usage. After fixing the bug, Astra users began hitting limits 40 percent faster. Sol users hit the ceiling 25 percent faster. &lt;a href="https://finance.biggo.com/news/6010dcbc-ff76-4328-a997-960e1494c23a" rel="noopener noreferrer"&gt;Finance Biggo reports&lt;/a&gt; this data.&lt;/p&gt;

&lt;p&gt;Official announcements lack information about the availability of the new models in the EU and compliance with local regulations. Developers &lt;a href="https://news.ycombinator.com/item?id=50535230" rel="noopener noreferrer"&gt;discuss&lt;/a&gt; the release timing on Hacker News. Thread participants suspect OpenAI rushed the models out before the Anthropic IPO. The system safety card at &lt;code&gt;deploymentsafety.openai.com&lt;/code&gt; returned an error at the time of release.&lt;/p&gt;

&lt;p&gt;As compensation for the sudden service interruption, OpenAI promised to give paid plan users one additional quota reset. &lt;a href="https://explainx.ai/blog/openai-gpt-6-2-astra-sol-billing-mistake-usage-limits-40-percent-faster-banked-reset-november-2026" rel="noopener noreferrer"&gt;ExplainX writes&lt;/a&gt; this one-time promotion provides only a temporary break for Go, Plus, Pro, and Business tiers.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 429 error trap triggers at normal RPM and TPM
&lt;/h2&gt;

&lt;p&gt;Standard limits for flagship models are 15,000 RPM and 40,000,000 TPM. &lt;a href="https://www.developersdigest.tech/rate-limits/openai" rel="noopener noreferrer"&gt;Developers Digest confirms&lt;/a&gt; these numbers. Developers configure throttling to these values and expect stable operation.&lt;/p&gt;

&lt;p&gt;Now the &lt;code&gt;slow_down&lt;/code&gt; error returns even when strictly observing basic limits. The trigger reacts to the traffic growth rate. If the request volume grows by more than 50 percent in 15 minutes after reaching 1 million tokens per minute, the API blocks access. The blocking mechanics are &lt;a href="https://www.elser.ai/news/gpt-6-astra-api-errors" rel="noopener noreferrer"&gt;described on Elser AI&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is the math for a real example. In the first minute, the agent consumed exactly 1 million tokens. A surge of tasks arrived at the fifteenth minute. Consumption reached 1.51 million tokens. The basic limit of 40 million TPM is still very far away. The system sees a jump greater than 50 percent and returns a 429 error. A detailed breakdown of the limits mechanics is available in the text about the &lt;a href="https://altrouter.ai/en/blog/oshibka-429-rate-limit/" rel="noopener noreferrer"&gt;429 error&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Developers have to write custom retry logic. Standard exponential backoff works poorly here. The agent must track its own consumption within a 15-minute window and artificially slow down new requests when approaching the danger zone.&lt;/p&gt;

&lt;p&gt;Example implementation using the official OpenAI 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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"YOUR_API_KEY"&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;safe_completion&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="n"&gt;current_tpm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_15m_growth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current_tpm&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;last_15m_growth&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.45&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&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;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&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;"gpt-6.2-astra"&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="n"&gt;messages&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hidden reasoning costs eat up the Astra price cut
&lt;/h2&gt;

&lt;p&gt;The base price for 1 million GPT-6.2 Astra input tokens dropped by 20 percent to 8 dollars. &lt;a href="https://industrycontents.com/news-desk/openai-gpt-6-2-astra-sol-price-cut-cyber-limits/" rel="noopener noreferrer"&gt;Industry Contents confirms&lt;/a&gt; this fact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fezm1kdbtj158bnldz5v0.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fezm1kdbtj158bnldz5v0.webp" alt="A bottomless white piggy bank with a blue coin falling into it" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Astra model spends a massive amount of tokens on internal reasoning. These hidden reasoning tokens are billed at the output price. The high generation cost completely negates the savings from cheaper input.&lt;/p&gt;

&lt;p&gt;We can calculate the cost of one agent iteration. The task requires analyzing text and returning a short JSON. The input prompt takes 5,000 tokens. The Astra model generates 2,000 tokens of internal reasoning and 100 tokens of the final response. The developer pays for 2,100 output tokens at the rate of 40 dollars per million. This equals 0.084 dollars per call. If the agent makes one hundred such calls per hour, it accumulates 201.60 dollars per day. One agent will burn over 6,000 dollars in a month of continuous work.&lt;/p&gt;

&lt;p&gt;The GPT-6.2 Sol model is positioned as the workhorse for agents. &lt;a href="https://munderdiffl.in/blog/gpt-6-2-astra-and-sol/" rel="noopener noreferrer"&gt;Munder Diffl writes&lt;/a&gt; it costs four times less than Astra. The Sol model outputs the result directly and costs 2 dollars for input and 10 dollars for output.&lt;/p&gt;

&lt;p&gt;Developers &lt;a href="https://news.ycombinator.com/item?id=50535230" rel="noopener noreferrer"&gt;share opinions&lt;/a&gt; in a Hacker News discussion. Thread participants call Sol an excellent tool for production accounts. One commenter notes the Luna model became a lifesaver against token shortages. Many considered Astra 6.2 itself a failure due to a 5 percentage point lag behind Claude Fable 5.2 in the FrontierBench benchmark. Other commenters express surprise at the lack of comparison with Gemini 4 Carbon in scientific tests.&lt;/p&gt;

&lt;p&gt;Here is a price comparison per 1 million tokens. We took the official OpenAI rates from the &lt;a href="https://cloudinsight.cc/en/blog/gpt-6-2-astra-sol-guide" rel="noopener noreferrer"&gt;Cloud Insight guide&lt;/a&gt;. Discounted prices are taken from our altrouter catalog for &lt;a href="https://altrouter.ai/en/models/gpt-6.2-astra/" rel="noopener noreferrer"&gt;GPT-6.2 Astra&lt;/a&gt;.&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 (official)&lt;/th&gt;
&lt;th&gt;Input (altrouter)&lt;/th&gt;
&lt;th&gt;Cache (official)&lt;/th&gt;
&lt;th&gt;Output (official)&lt;/th&gt;
&lt;th&gt;Output (altrouter)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GPT-6 Astra&lt;/td&gt;
&lt;td&gt;$10.00&lt;/td&gt;
&lt;td&gt;$8.50&lt;/td&gt;
&lt;td&gt;No data&lt;/td&gt;
&lt;td&gt;$50.00&lt;/td&gt;
&lt;td&gt;$42.50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPT-6.2 Astra&lt;/td&gt;
&lt;td&gt;$8.00&lt;/td&gt;
&lt;td&gt;$6.80&lt;/td&gt;
&lt;td&gt;$0.40&lt;/td&gt;
&lt;td&gt;$40.00&lt;/td&gt;
&lt;td&gt;$34.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPT-6.2 Sol&lt;/td&gt;
&lt;td&gt;$2.00&lt;/td&gt;
&lt;td&gt;No data&lt;/td&gt;
&lt;td&gt;$0.10&lt;/td&gt;
&lt;td&gt;$10.00&lt;/td&gt;
&lt;td&gt;No data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The output price difference between Astra and Sol reaches 30 dollars per million tokens. Choosing Sol becomes a matter of budget survival for an agent constantly generating intermediate steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requests over 272 thousand tokens trigger the price doubling rule
&lt;/h2&gt;

&lt;p&gt;The context window of the new models holds 1,050,000 tokens. &lt;a href="https://www.aipricing.guru/news/openai-gpt-6-2-astra-sol-api-pricing-november-2026/" rel="noopener noreferrer"&gt;AI Pricing Guru clarifies&lt;/a&gt; the input maximum is 922,000 tokens. The model returns up to 128,000 tokens as output.&lt;/p&gt;

&lt;p&gt;Loading large documents has become dangerous due to the doubling rule. OpenAI changes the billing for requests with a context of more than 272,000 input tokens. The price for input tokens and cache doubles. The cost of output tokens increases by 1.5 times for the entire request. &lt;a href="https://cloudinsight.cc/en/blog/gpt-6-2-astra-sol-guide" rel="noopener noreferrer"&gt;Cloud Insight confirms&lt;/a&gt; this mechanism.&lt;/p&gt;

&lt;p&gt;We can calculate the cost of one heavy request to Astra. We send 300,000 input tokens and receive 10,000 output tokens.&lt;br&gt;
Without the doubling rule, the input would cost 2.40 dollars. We multiplied 0.3 million by 8 dollars. The output would cost 0.40 dollars. The total is 2.80 dollars.&lt;br&gt;
With the doubling rule, the input price becomes 16 dollars per million. Our 300,000 tokens will cost 4.80 dollars. The output price rises to 60 dollars per million. This means 10,000 tokens cost 0.60 dollars. The total is 5.40 dollars for a single API call. The difference is almost double.&lt;/p&gt;

&lt;p&gt;Expenses double out of nowhere if the agent works with large codebases. Analyzing logs or searching for bugs in a repository often requires passing hundreds of files at once. Context optimization is described in our article about reducing token costs.&lt;/p&gt;

&lt;p&gt;Developers will have to implement a strict prompt length limit at the application level. You must forcibly truncate the text if it exceeds 270,000 tokens. Another option requires implementing vector databases and RAG technology. The system searches for relevant code snippets and passes only them instead of loading the entire codebase into the context. This saves the budget from a sharp cost increase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background mode saves budget at the cost of interactivity
&lt;/h2&gt;

&lt;p&gt;OpenAI introduced Background mode with execution windows of 2h and 8h. &lt;a href="https://hermes-ai.net/news/openai-cuts-gpt-6-2-astra-api-costs-40-for-overnight-background-jobs/" rel="noopener noreferrer"&gt;Hermes AI reports&lt;/a&gt; this approach saves up to 40 percent on token costs.&lt;/p&gt;

&lt;p&gt;The mode is perfectly suited for overnight tasks, log parsing, background analytics, and document processing. The developer sends a batch of requests and retrieves the result a few hours later.&lt;/p&gt;

&lt;p&gt;We can calculate the savings. A background task consuming 10 million input tokens and 2 million output tokens on the Astra model would cost 160 dollars at the standard rate. The 40 percent discount in the 8-hour window reduces the price to 96 dollars. The savings amount to 64 dollars on a single batch.&lt;/p&gt;

&lt;p&gt;This method has a clear downside. Background mode is unfit for real-time tasks. You will have to pay full price for generation speed.&lt;/p&gt;

&lt;p&gt;The Ultrafast mode for GPT-6.2 Astra costs 3 times the standard rate until February 28, 2027. The price will jump to 6 times the base rate after this date. &lt;a href="https://www.layer3labs.io/guides/gpt-6-2-pricing" rel="noopener noreferrer"&gt;Layer3 Labs cites&lt;/a&gt; these figures in their review. Running fast agents will require massive budgets. Cheap tasks move to the background, while response speed requires paying prohibitive rates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merging ChatGPT and Codex limits will block parallel work
&lt;/h2&gt;

&lt;p&gt;The quota situation will get more complicated in December 2026. OpenAI plans to merge the limits for ChatGPT and Codex into a single tokenized quota, affecting Work accounts as well. &lt;a href="https://meteoraweb.com/en/news/chatgpt-and-codex-shared-usage-limits-from-december" rel="noopener noreferrer"&gt;Meteora Web warns&lt;/a&gt; users will lose the ability to switch to Codex when the main chat limits are exhausted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F79h6kspnusszu62m7kud.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F79h6kspnusszu62m7kud.webp" alt="A double power outlet with someone trying to plug in two overly wide plugs" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Active code generation will block agents running in an adjacent window. A direct conflict of interest arises within the ecosystem of a single account. The idea of multimodal productivity collapses. One heavy process eats up the shared token pool and stops the other tools.&lt;/p&gt;

&lt;p&gt;Developers will have to separate accounts for different tasks. Using a single key to test prompts in a sandbox and run production agents will lead to mutual blockages. The 429 error will occur due to a live person's actions in the web interface, stopping automated background processes. Teams face complex work configuring billing and distributing quotas across different departments. You will have to create separate projects in the OpenAI dashboard and strictly limit the spending of each key. A detailed breakdown of key management is available in the material about model routing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to move to Sol and how to split context on Monday
&lt;/h2&gt;

&lt;p&gt;The old GPT-5.6 Sol and Terra models will be disabled on December 23, 2026. &lt;a href="https://www.neoteo.com/en/gpt-62-sol-rolls-out-in-chatgpts-regular-chat" rel="noopener noreferrer"&gt;NeoTeo confirms&lt;/a&gt; the deprecation date. Code needs updating right now.&lt;/p&gt;

&lt;p&gt;Routine agent tasks should be moved to GPT-6.2 Sol. Parsing, classification, data extraction, and simple user responses must go through the cheap model. The fourfold price difference pays off any time spent rewriting prompts.&lt;/p&gt;

&lt;p&gt;You should keep the Astra model only for final decision-making or complex code writing. The context size requires strict control. You must split the prompt into parts to bypass the price doubling rule if it exceeds 272,000 tokens.&lt;/p&gt;

&lt;p&gt;Background mode must be implemented for all non-interactive tasks. Analytics gathering and document processing should run with an 8-hour delay. This is the only reliable way to offset the 40 percent quota drop after the November billing fix.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Updating a chat summary after every reply made my 4-turn chats 84% more expensive</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Wed, 25 Nov 2026 12:00:02 +0000</pubDate>
      <link>https://dev.to/altrouter/updating-a-chat-summary-after-every-reply-made-my-4-turn-chats-84-more-expensive-4pah</link>
      <guid>https://dev.to/altrouter/updating-a-chat-summary-after-every-reply-made-my-4-turn-chats-84-more-expensive-4pah</guid>
      <description>&lt;p&gt;You've built a chatbot, and you've learned that chat APIs have no memory: every turn you send the system prompt and the whole conversation again, so long chats get expensive fast. The usual fix is a running summary. Instead of the full history, you send a short summary of what was said so far.&lt;/p&gt;

&lt;p&gt;The obvious way to build it is to update the summary after every reply. It's simple and the summary is always fresh. On short chats it's also the most expensive option, because the summary is text the model writes, and written text is billed at a much higher price.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads or writes; APIs bill per million of them. &lt;strong&gt;Input&lt;/strong&gt; tokens are what you send, &lt;strong&gt;output&lt;/strong&gt; tokens are what the model writes back, and output usually costs several times more. A &lt;strong&gt;list price&lt;/strong&gt; is the vendor's official price per million tokens, before any discount. A &lt;strong&gt;turn&lt;/strong&gt; is one user message plus one assistant reply. A &lt;strong&gt;summarizer call&lt;/strong&gt; is a separate API request whose only job is to rewrite the conversation into a shorter text.&lt;/p&gt;

&lt;h3&gt;
  
  
  The setup
&lt;/h3&gt;

&lt;p&gt;I modeled a support chat with round numbers: a 400-token system prompt, 60-token user messages, 250-token replies and a 250-token summary (about 200 words). The summarizer instruction, counted with tiktoken (&lt;code&gt;o200k_base&lt;/code&gt;), is 83 tokens. Prices are list prices from the catalog snapshot of the LLM gateway I work on: gpt-5.6 at $2 per million input tokens and $12 per million output.&lt;/p&gt;

&lt;p&gt;I compared three strategies for the same conversation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Full history.&lt;/strong&gt; Send everything, every turn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summary after every reply.&lt;/strong&gt; After each answer, ask the model to merge the last turn into the summary. The next turn sends the system prompt, the summary, the last turn word for word and the new message.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summary when ten turns pile up.&lt;/strong&gt; Send full history until there are ten unsummarized turns, then fold all but the last two into the summary in one call.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What it costs
&lt;/h3&gt;

&lt;p&gt;Total cost of one conversation on gpt-5.6, chat and summarizer on the same model:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Turns&lt;/th&gt;
&lt;th&gt;Full history&lt;/th&gt;
&lt;th&gt;Summary after every reply&lt;/th&gt;
&lt;th&gt;Summary when 10 turns pile up&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;$0.0194&lt;/td&gt;
&lt;td&gt;$0.0357 (+84%)&lt;/td&gt;
&lt;td&gt;$0.0194 (no summary yet)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;$0.0671&lt;/td&gt;
&lt;td&gt;$0.0916 (+37%)&lt;/td&gt;
&lt;td&gt;$0.0671 (no summary yet)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;$0.1962&lt;/td&gt;
&lt;td&gt;$0.1849 (−6%)&lt;/td&gt;
&lt;td&gt;$0.1584 (−19%)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;$0.9555&lt;/td&gt;
&lt;td&gt;$0.4647 (−51%)&lt;/td&gt;
&lt;td&gt;$0.4229 (−56%)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The per-reply summary only becomes cheaper than doing nothing at turn 19. Most support chats are over long before that.&lt;/p&gt;

&lt;p&gt;The reason is the output price. Each per-reply summarizer call reads 643 tokens and writes 250. Those 250 output tokens cost as much as 1,500 input tokens, so 70% of the call's price is the summary text itself. The whole call costs $0.0043, more than the very first chat turn ($0.0039). On a short chat you pay that every turn to avoid resending a history that was still small.&lt;/p&gt;

&lt;p&gt;The batched version has the same per-call problem, but it pays it rarely and only when it buys something. Its first summarizer call costs $0.0081: it reads eight turns (2,480 tokens) and replaces them with 250. From then on every turn sends about 2,230 fewer input tokens, which saves $0.0045 per turn. The call has paid for itself after two more turns: the conversation is 5% more expensive at turn 11, 1% cheaper at turn 12, and 19% cheaper at turn 20. A chat that ends before turn 11 never triggers it and costs exactly what full history costs.&lt;/p&gt;

&lt;p&gt;Moving the summary to a cheaper model shifts both curves. With gpt-5.6-mini ($0.20 / $1.20) writing summaries for a gpt-5.6 chat, the per-reply version is still 7% more expensive at four turns but cheaper from turn 6, and the batched one is cheaper from the first summary. The batched version on claude-sonnet-5.5 with claude-haiku-5.5 as the summarizer is also cheaper from its first summary.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix: summarize when it's needed, not on a schedule
&lt;/h3&gt;

&lt;p&gt;Check the size before each turn and summarize only when the history has grown:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_messages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_msg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_turns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""turns: list of (user, assistant) pairs not yet in the summary."""&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;max_turns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;old&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;turns&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;turns&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="n"&gt;keep&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;keep&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;old&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# one call, only here&lt;/span&gt;
    &lt;span class="n"&gt;msgs&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;"system"&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;system&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;"system"&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="s2"&gt;"Conversation so far: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;msgs&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;u&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="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"assistant"&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;a&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;new_msg&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;

&lt;span class="n"&gt;fake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;old&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;"{len(old)} earlier turns about a refund"&lt;/span&gt;
&lt;span class="n"&gt;turns&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="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"q{i}"&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;"a{i}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_messages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"You are support."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"q10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fake&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msgs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running it prints &lt;code&gt;7 8 earlier turns about a refund&lt;/code&gt;: the system prompt, the summary, two recent turns (four messages) and the new message. Ten turns is a starting point. A count of tokens works better than a count of turns if your messages vary a lot in length, and the &lt;code&gt;usage&lt;/code&gt; field of each response tells you the real input size.&lt;/p&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;A summary loses detail. The model may drop an order number or a setting the user mentioned on turn 3, and with the batched version that loss happens in one jump, not gradually. I didn't measure answer quality, only price. If your bot must quote exact details from early in the chat, test summaries on real conversations first, or keep key facts in a separate structured field instead.&lt;/p&gt;

&lt;p&gt;Prompt caching changes the math. Many vendors bill a repeated prefix at a discount. Full history is a prefix that only grows, so it caches well, while every new summary changes the prefix and breaks the cache. The catalog I used has no cache prices, so none of this is in the table.&lt;/p&gt;

&lt;p&gt;Finally, all token sizes here are assumptions, and the break-even points move with them. Longer replies make summarizing pay off sooner; a summary close to the size of the turns it replaces never pays off. Plug your own numbers from &lt;code&gt;usage&lt;/code&gt; into the same comparison before you pick a threshold.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>Text copied out of a PDF cost me 31% more tokens than the same text cleaned up</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Tue, 24 Nov 2026 12:00:02 +0000</pubDate>
      <link>https://dev.to/altrouter/text-copied-out-of-a-pdf-cost-me-31-more-tokens-than-the-same-text-cleaned-up-3h2l</link>
      <guid>https://dev.to/altrouter/text-copied-out-of-a-pdf-cost-me-31-more-tokens-than-the-same-text-cleaned-up-3h2l</guid>
      <description>&lt;p&gt;You build a tool that answers questions about documents. Users upload contracts, manuals and papers, almost all of them PDFs. You extract the text, put it in the prompt, and it works. The answers are fine, so you never look closely at the text you send.&lt;/p&gt;

&lt;p&gt;You should, because text that comes out of a PDF is not the text the author wrote. It's what a page layout leaves behind, and the model bills you for every piece of that layout.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads; APIs bill per million of them. I counted with tiktoken and &lt;code&gt;o200k_base&lt;/code&gt;, the tokenizer OpenAI's current models use. &lt;strong&gt;Input&lt;/strong&gt; tokens are what you send to the model. A &lt;strong&gt;list price&lt;/strong&gt; is the vendor's official price per million tokens, before any discount. &lt;strong&gt;Text extraction&lt;/strong&gt; means pulling the characters out of a PDF, with a library or by copy-paste. A PDF stores where each line sits on the page, not where paragraphs begin and end. So what you get back is lines, not paragraphs.&lt;/p&gt;

&lt;h3&gt;
  
  
  The measurement
&lt;/h3&gt;

&lt;p&gt;I needed a long, real English document, so I used the GNU GPL version 3: 5,644 words, 122 paragraphs. Joined into one line per paragraph, it is &lt;strong&gt;6,701 tokens&lt;/strong&gt;. That's the clean baseline.&lt;/p&gt;

&lt;p&gt;Then I added the usual PDF extraction artifacts one at a time, each on top of the previous ones. I simulated them in a script, because this is what extractors commonly produce. It is not the output of one particular tool:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What the extracted text contains&lt;/th&gt;
&lt;th&gt;Tokens&lt;/th&gt;
&lt;th&gt;vs clean&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Line breaks every ~70 characters&lt;/td&gt;
&lt;td&gt;7,194&lt;/td&gt;
&lt;td&gt;+7.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+ words split with a hyphen at line end&lt;/td&gt;
&lt;td&gt;7,273&lt;/td&gt;
&lt;td&gt;+8.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+ ligature characters (ﬁ, ﬂ, ﬀ)&lt;/td&gt;
&lt;td&gt;7,494&lt;/td&gt;
&lt;td&gt;+11.8%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+ a page header and number every 50 lines&lt;/td&gt;
&lt;td&gt;7,650&lt;/td&gt;
&lt;td&gt;+14.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+ double spaces from justified text&lt;/td&gt;
&lt;td&gt;8,749&lt;/td&gt;
&lt;td&gt;+30.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each row is small on its own, and each has a simple cause in the tokenizer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line breaks.&lt;/strong&gt; The tokenizer stores a space plus a common word as one token: " the" is one token. A newline doesn't merge that way, so "\nthe" is two. Every one of the 682 line breaks costs about one extra token. You don't need a PDF to see this: the GPL-3 file as it ships in Linux distributions, wrapped by hand at about 72 characters, is 7,446 tokens, 11% more than the same text unwrapped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Split words.&lt;/strong&gt; "computer" is one token. "compu-\nter" is four: &lt;code&gt;comp&lt;/code&gt;, &lt;code&gt;u&lt;/code&gt;, &lt;code&gt;-\n&lt;/code&gt;, &lt;code&gt;ter&lt;/code&gt;. The 65 split words cost 79 tokens more than the same text with plain line breaks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ligatures.&lt;/strong&gt; Typesetting software often merges "fi" or "fl" into one special character. "file" is one token. With the ligature it's two, because the tokenizer has rarely seen that character inside a word. Here 91 ligatures cost 221 extra tokens, about 2.4 each.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Page headers.&lt;/strong&gt; A running title and page number cost about 12 tokens per page. That's the smallest effect here, and it's also repeated text that tells the model nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Double spaces.&lt;/strong&gt; Justified text stretches lines to the margin. Some extractors turn that stretched space into two or more space characters. Each extra space is one more token. In my simulation one inter-word space in four was doubled, which added 1,057 tokens, the biggest single row. Your extractor may produce fewer of these, or many more.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it adds up to
&lt;/h3&gt;

&lt;p&gt;All together, the same document goes from 6,701 to 8,749 tokens. The model reads 2,048 tokens of layout.&lt;/p&gt;

&lt;p&gt;Suppose your tool sends a document this size 1,000 times a day. At gpt-5.6's list price of $2 per million input tokens (from the catalog snapshot of the LLM gateway I work on), that's $402 a month for clean text and $525 for raw extracted text: +$122.88 for nothing. claude-sonnet-5.5 has the same input price, so the gap is the same. On gemini-3.8-flash it's +$46, on gpt-5.6-mini +$12, on claude-haiku-5.5 +$6. I'm only counting the document, not the question or the answer.&lt;/p&gt;

&lt;p&gt;The fix runs before the API call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_pdf_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"NFKC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c1"&gt;# ligature characters -&amp;gt; plain letters&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"(\w)-\n(\w)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\1\2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# compu-\nter -&amp;gt; computer&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"(?&amp;lt;!\n)\n(?!\n)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# line break inside a paragraph -&amp;gt; space&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"[ \t]+"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;              &lt;span class="c1"&gt;# runs of spaces -&amp;gt; one space&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\n{3,}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\n\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;clean_pdf_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"The modiﬁed  program is a compu-\nter program,\nnot a docu-\nment."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;NFKC&lt;/code&gt; is a standard Unicode normalization that, among other things, turns a ligature character back into ordinary letters. The other lines join split words, turn single line breaks into spaces and collapse repeated spaces. A blank line stays, so paragraphs survive. With one extra pattern to remove the page header (that pattern depends on your document), the fully broken GPL text came back to 6,703 tokens, two more than the original.&lt;/p&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;The cleaner guesses, and some guesses are wrong. A word that really has a hyphen, like "general-purpose", gets glued into "generalpurpose" when the line happens to break at that hyphen. Where a page break fell exactly between two paragraphs, my run merged them: 122 paragraphs became 119. Lists, tables and code lose their line structure completely, because to the regex a line break is a line break. &lt;code&gt;NFKC&lt;/code&gt; also rewrites other characters: superscript ² becomes 2 and ½ becomes "1⁄2", which matters in technical and financial text.&lt;/p&gt;

&lt;p&gt;It doesn't solve the hard PDF problems either. Text in two columns can come out interleaved line by line, and scanned pages contain no text at all until you run OCR. Removing extra tokens doesn't fix a jumbled reading order.&lt;/p&gt;

&lt;p&gt;Finally, the artifacts here are simulated on one document and counted with one tokenizer. Claude and Gemini tokenize differently, and real extractors vary a lot, especially with spaces. Before you trust my percentages, count your own: run your extractor on a few real uploads, count tokens before and after cleaning, and read one cleaned page with your own eyes.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>Token prices lie: why cheap reasoning models bankrupt you</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Tue, 24 Nov 2026 07:16:18 +0000</pubDate>
      <link>https://dev.to/altrouter/token-prices-lie-why-cheap-reasoning-models-bankrupt-you-ef</link>
      <guid>https://dev.to/altrouter/token-prices-lie-why-cheap-reasoning-models-bankrupt-you-ef</guid>
      <description>&lt;p&gt;The API bill arrives. The final amount completely misses the forecast. A developer moved autonomous agents to a new budget model, expected a massive drop in expenses, and paid twice as much as before. Database logs show short answers of a couple of paragraphs. The provider's billing charges for hundreds of thousands of tokens.&lt;/p&gt;

&lt;p&gt;The low price per million tokens is completely wiped out by architectural bugs. Small reasoning models often get stuck in loops. They hit the maximum limit with hidden thoughts and burn the budget for nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hidden thoughts are sold at output rates
&lt;/h2&gt;

&lt;p&gt;Providers highlight the cost of input tokens in large print when they announce new models. A developer sees the low price and decides to migrate. The mistake happens because of pricing rules. Reasoning tokens are always &lt;a href="https://safeguard.sh/resources/blog/meter-thinking-tokens-reasoning-cost-in-llm-bills" rel="noopener noreferrer"&gt;billed at the output rate&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A short visible response hides huge costs for internal thinking. Output tokens cost several times more than input tokens. Generating each new word requires sequential calculations, while input text is processed in parallel. Providers bake the cost of these calculations into the output token price.&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 tokens (per 1M)&lt;/th&gt;
&lt;th&gt;Output tokens (per 1M)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;OpenAI o1&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.burnwise.io/ai-pricing/model/o1" rel="noopener noreferrer"&gt;$15.00&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;$60.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenAI o3-mini&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.prompthub.us/models/o3-mini" rel="noopener noreferrer"&gt;$1.10&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;$4.40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude 3.7 Sonnet&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.anthropic.com/news/claude-3-7-sonnet" rel="noopener noreferrer"&gt;$3.00&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;$15.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DeepSeek R1&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.burnwise.io/ai-pricing/model/deepseek-r1" rel="noopener noreferrer"&gt;$0.55&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;$2.19&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The official price of DeepSeek R1 looks low. They ask just over half a dollar for one million input tokens. The model generates a massive volume of internal text when solving a complex task. Billing charges the amount from the output tokens column for every generated character of reasoning.&lt;/p&gt;

&lt;p&gt;Users discuss the architecture of such neural networks in Hacker News threads. Reasoning models rely on reinforcement learning and verifiable rewards. The neural network tries to find the right solution path through multiple attempts. Each attempt generates new tokens. The provider passes the cost of these attempts to the client. The developer pays for the drafts the neural network writes and erases during its work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hidden context increases request price by 80 times
&lt;/h2&gt;

&lt;p&gt;Let us calculate the real cost of a single request using specific numbers. Suppose an agent analyzes a server log and returns a short structured response. The visible final text takes exactly 50 tokens. The model dives into thinking and generates 4000 hidden tokens before delivering the answer. Four thousand tokens equal several pages of dense text.&lt;/p&gt;

&lt;p&gt;Take the pricing of the &lt;a href="https://altrouter.ai/en/models/o3/" rel="noopener noreferrer"&gt;o3 model&lt;/a&gt; in the mini version. The output token price is 4.40 dollars per million.&lt;br&gt;
We add 4000 reasoning tokens and 50 response tokens. We get 4050 output tokens.&lt;br&gt;
We multiply 4050 by 4.40. We get 17820.&lt;br&gt;
We divide the result by one million. The final request price is 0.01782 dollars.&lt;/p&gt;

&lt;p&gt;Now we calculate the cost of the exact same response without hidden reasoning.&lt;br&gt;
We multiply 50 tokens by 4.40. We get 220.&lt;br&gt;
We divide by one million. The price drops to 0.00022 dollars.&lt;/p&gt;

&lt;p&gt;The presence of hidden context increased the cost of a basic task by exactly 80 times. The developer planned to pay fractions of a cent and pays almost two cents for each call. Such overpayments quickly eat up the project's monthly budget during mass data processing. A detailed API bill breakdown confirms these calculations.&lt;/p&gt;

&lt;p&gt;We can compare this approach with using a regular model. A developer takes GPT-4o-mini and writes a detailed system prompt. They ask the model to reason step by step and output the logic directly into the response.&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;openai&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;openai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.altrouter.ai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ar-YOUR_API_KEY"&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;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&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;"gpt-4o-mini"&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;"system"&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="s2"&gt;"Analyze the log. Reason step by step. Output the logic in &amp;lt;thought&amp;gt; tags, then give the answer."&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="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="s2"&gt;"Error 500 at /login"&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;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The length of such a response rarely exceeds 500 tokens. The output token price for GPT-4o-mini is 0.60 dollars per million. We multiply 500 by 0.60 and divide by a million. The request will cost 0.0003 dollars. The cost difference reaches tens of times in favor of the classic model without hidden thoughts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Infinite loops burn limits without answers
&lt;/h2&gt;

&lt;p&gt;The high price for long thoughts makes sense for solving complex mathematical problems. The real issue arises during failures. Small reasoning models suffer from a specific bug. The model starts solving a task, loses the logical thread and &lt;a href="https://habr.com/ru/companies/airi/articles/1111066/" rel="noopener noreferrer"&gt;falls into an infinite loop&lt;/a&gt;. It repeats the exact same phrase until the token limit is completely exhausted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwkq4w1d2zam61m1ahqof.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwkq4w1d2zam61m1ahqof.webp" alt="A robot vacuum cleaner has rubbed a deep circular rut into a glossy dark floor" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The neural network's internal monologue turns into endless repetition of the same checks. The model opens a thinking tag. It writes a hypothesis, rejects it, rewrites it and rejects it again. The text fills with phrases like "need to check again", "let's try another approach", "this doesn't work, let's check again". The process stops only when it hits the maximum token parameter.&lt;/p&gt;

&lt;p&gt;Researchers from AIRI tested this behavior on real data. They ran 6000 prompts through the open Qwen3.5-0.8B model. The measurement results showed the frequency of the problem. The model gets stuck in a loop in 25% of all responses. Generation completely hits the hard token limit in 33% of cases. The budget burns entirely. The application receives no useful result. Requests hang in processing until a system timeout triggers.&lt;/p&gt;

&lt;p&gt;The AIRI team managed to fix this flaw. They collected a dataset with examples of correct reasoning and examples of loops. Then they trained a special Qwen3.5-Unloop version using the DPO method. The algorithm penalized the neural network for repetitions. They managed to reduce the share of garbage failures on the 4B version from 23.8% to 1.6%.&lt;/p&gt;

&lt;p&gt;Training a custom model requires massive computing power. Hacker News readers discuss courses on building reasoning models from scratch. They agree that a home enthusiast lacks the GPUs for proper training. Theoretical courses provide an understanding of the architecture, while practical application requires industrial clusters. Developers have to use ready-made APIs and tolerate the bugs of base versions. Users note that building a model from scratch is like assembling a CPU with a soldering iron: interesting, but inapplicable in real business.&lt;/p&gt;

&lt;p&gt;Large-scale independent benchmarks with failure rates for other models do not exist yet. Developers do not know the exact share of garbage loops for DeepSeek R1 or distilled Llama models in a real production environment. You have to bake the risk of looping into the application architecture by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agent scenarios multiply the cost of a mistake
&lt;/h2&gt;

&lt;p&gt;The cost of looping multiplies by the number of model calls in agent scenarios. Such generation becomes the most expensive possible. The budget burns entirely due to automatic retries.&lt;/p&gt;

&lt;p&gt;Agents work in cycles. The program sends a request and receives a response. Then it parses the data and makes the next decision. The agent receives the response and tries to extract JSON from it. The parser breaks if the model loops. An endless text with reasoning arrives instead of JSON. The agent catches an exception and sends the request again. The loop-prone model goes into endless reasoning again. The cycle repeats five times before a hard abort. The program burns the budget of five full token limits in one second.&lt;/p&gt;

&lt;p&gt;Let us calculate the losses from one failed cycle. The agent sends a request to the o3-mini model. The model goes into endless reasoning and hits the 100,000 output token limit. We multiply 100,000 by 4.40 dollars and divide by a million. One failed call costs 0.44 dollars. The parser breaks, and the agent repeats the request five times. We multiply 0.44 by 5. The program burns 2.20 dollars in a few seconds of work. A thousand such errors will cost 2200 dollars.&lt;/p&gt;

&lt;p&gt;Hidden tokens inflate costs in large-scale benchmarks to tens of thousands of dollars. The &lt;a href="https://arxiv.org/html/2508.00912v1" rel="noopener noreferrer"&gt;OpenAI o3 model&lt;/a&gt; spent a massive budget in one ARC-AGI test. The amount exceeded 66,000 dollars for 111 million tokens. More than 60% went exclusively to hidden reasoning tokens. The test required multiple attempts to solve complex logical problems. Each attempt generated new branches of thought.&lt;/p&gt;

&lt;p&gt;The developer pays for thousands of garbage cycles instead of the expected savings. Using a cheap reasoning model mathematically costs more than calling an expensive flagship model without built-in reasoning. An agent will &lt;a href="https://altrouter.ai/en/blog/ai-agent-undobench-error-cost/" rel="noopener noreferrer"&gt;multiply the cost of a mistake&lt;/a&gt;, and the allocated funds will run out in a couple of hours of work.&lt;/p&gt;

&lt;p&gt;Looping hurts execution speed. Generating thirty thousand tokens takes several minutes. The user waits for an answer while the agent hangs waiting. Then the connection drops due to a timeout. The developer pays for the computation. The client gets a server error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Streaming hides billing
&lt;/h2&gt;

&lt;p&gt;Tracking wasted money is technically difficult due to network behavior. Most modern applications use streaming for fast text output. The server sends the response in small chunks via Server-Sent Events.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6lof6nfpwh4k3wpnbt38.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6lof6nfpwh4k3wpnbt38.webp" alt="A thick package is tightly stuck in the narrow slot of a minimalist mailbox" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The breakdown of hidden tokens &lt;a href="https://safeguard.sh/resources/blog/meter-thinking-tokens-reasoning-cost-in-llm-bills" rel="noopener noreferrer"&gt;appears in the final event&lt;/a&gt; &lt;code&gt;message_delta&lt;/code&gt; during streaming. Parsers interrupt the stream prematurely and fail to record these costs.&lt;/p&gt;

&lt;p&gt;The final chunk contains a statistics block. It looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"chatcmpl-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"chat.completion.chunk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"choices"&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;span class="nl"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"prompt_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"completion_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"completion_tokens_details"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"reasoning_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"total_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4065&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;Local logs remain empty if the network drops before receiving this packet. Serverless functions make the problem worse. If a function has a ten-second execution time limit, it will forcefully terminate before the model finishes its long reasoning. The neural network provider will have time to generate and bill thousands of tokens. The developer's server will simply shut down and save no cost data.&lt;/p&gt;

&lt;p&gt;The developer looks at their database and sees zero spent tokens. The provider's server successfully finished generation and recorded 30,000 reasoning tokens in billing. The internal &lt;a href="https://altrouter.ai/en/blog/chatgpt-api/" rel="noopener noreferrer"&gt;API usage statistics&lt;/a&gt; radically diverge from the real bill at the end of the month.&lt;/p&gt;

&lt;p&gt;Local monitoring tools become useless. They rely on data from interrupted connections and underestimate real expenses. The developer continues to scale the system with false confidence in its low cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hard limits save you from overpaying
&lt;/h2&gt;

&lt;p&gt;Vendors offer different approaches to controlling reasoning. The Claude 3.7 Sonnet model works as a hybrid. A developer can enable extended thinking mode and set a hard budget. The limit &lt;a href="https://simonw.substack.com/p/claude-37-sonnet-extended-thinking" rel="noopener noreferrer"&gt;is configurable in a range&lt;/a&gt; from 1024 to 128,000 tokens.&lt;/p&gt;

&lt;p&gt;We can calculate the minimum request cost with thinking mode enabled. The output token for Claude 3.7 Sonnet costs 15 dollars per million. We multiply the minimum threshold of 1024 tokens by 15 and divide by a million. We get 0.01536 dollars. Each request will cost at least a cent and a half just for the thinking process. The final answer might consist of a single word, and the price will remain the same.&lt;/p&gt;

&lt;p&gt;The minimum threshold makes the hybrid mode unprofitable for simple tasks. The model will reserve and spend a thousand tokens on thinking if an agent needs to extract a date from text. The provider set this threshold on purpose. A neural network needs space for full context analysis, and short reasoning yields no quality improvement.&lt;/p&gt;

&lt;p&gt;Claude 3.7 Sonnet and DeepSeek R1 models &lt;a href="https://www.deeplearning.ai/the-batch/claude-3-7-sonnet-introduces-hybrid-reasoning-and-extended-thinking" rel="noopener noreferrer"&gt;fully expose&lt;/a&gt; reasoning tokens to the user. You can read the logs and understand the cause of a failure. The visible thinking process allows you to quickly catch loops during the testing phase. A developer sees repeating phrases and interrupts the script execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closed models hide failures
&lt;/h2&gt;

&lt;p&gt;OpenAI systems work differently. The closed o1 and o3-mini models completely hide internal tokens from the developer. You cannot analyze the reasoning text or filter out garbage loops on the fly. The user gets only the final answer and a bill for tens of thousands of tokens.&lt;/p&gt;

&lt;p&gt;Neither vendor documentation nor aggregators describe a refund process for generations. Failures hit the limit due to the looping bug, and money is deducted permanently. You have de facto already paid for these tokens. The provider spent computing power generating text, even if that text consisted of a single repeating phrase.&lt;/p&gt;

&lt;p&gt;The closed reasoning process strips the engineer of debugging tools. You cannot look at the problematic step. The model goes into an infinite loop, and the developer cannot see the cause. You cannot adjust the system prompt to bypass the bottleneck. You have to act blind and hope for the provider's internal filters.&lt;/p&gt;

&lt;p&gt;The developer receives a massive bill and cannot prove a technical failure on the neural network's side. Technical support sees the spent tokens but does not see their content. You will have to pay for the burned tokens in full.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose a strict prompt over built-in reasoning
&lt;/h2&gt;

&lt;p&gt;A cheap model will easily drain a project's balance. Using a regular model with a smart Chain-of-Thought prompt is mathematically better for stable streaming and agent tasks. The developer writes out the logic steps in text and strictly controls the response length. This saves you from unpredictable loops.&lt;/p&gt;

&lt;p&gt;Enabling built-in reasoning makes sense when you have strict control mechanisms. You should check the provider documentation first. The risk of overpaying drops significantly if the API lets you set a strict limit on thinking. The developer sets an upper token boundary and protects the budget from infinite loops.&lt;/p&gt;

&lt;p&gt;Then you need to check the network parser code. It must correctly wait for the final chunks with billing and write them to the database. Local analytics must match the billing data.&lt;/p&gt;

&lt;p&gt;You should look for versions with loop protection when working with open weights. Models trained to reject loops save server compute resources.&lt;/p&gt;

&lt;p&gt;A low token price will turn into regular payments for endless repetitions of a single word without these measures.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The user typed "thanks!" — 2 tokens. My chatbot sent the model 588.</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Mon, 23 Nov 2026 12:00:02 +0000</pubDate>
      <link>https://dev.to/altrouter/the-user-typed-thanks-2-tokens-my-chatbot-sent-the-model-588-1725</link>
      <guid>https://dev.to/altrouter/the-user-typed-thanks-2-tokens-my-chatbot-sent-the-model-588-1725</guid>
      <description>&lt;p&gt;You build a support chatbot. A user asks four questions, gets four good answers, and writes "thanks!". Your bot sends that to the model like any other message, the model replies "You're welcome!", and the conversation ends politely.&lt;/p&gt;

&lt;p&gt;That last exchange carried no information in either direction, and it was billed like a real question. In my test chat it cost more than the user's first one.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads; APIs bill per million of them. I counted with tiktoken and &lt;code&gt;o200k_base&lt;/code&gt;, the tokenizer OpenAI's current models use. &lt;strong&gt;Input&lt;/strong&gt; tokens are what you send, &lt;strong&gt;output&lt;/strong&gt; tokens are what the model writes back. A &lt;strong&gt;system prompt&lt;/strong&gt; is the block of instructions you put at the start of every conversation. A chat API is &lt;strong&gt;stateless&lt;/strong&gt;: it remembers nothing between calls, so to continue a conversation you send the whole conversation again. A &lt;strong&gt;list price&lt;/strong&gt; is the vendor's official price per million tokens, before any discount.&lt;/p&gt;

&lt;h3&gt;
  
  
  The measurement
&lt;/h3&gt;

&lt;p&gt;I wrote a synthetic support chat for a made-up shipping-label service: a 241-token system prompt, four questions about refunding an unused label, and four answers of two to five sentences, the length the prompt asks for. Then the user writes "thanks!" (2 tokens) and the bot answers "You're welcome! If anything else comes up, just ask." (12 tokens).&lt;/p&gt;

&lt;p&gt;Every call sends the system prompt, every earlier message, and the new one. I counted only the message text, not the few formatting tokens the chat format adds per message, so the real numbers are slightly higher.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Call&lt;/th&gt;
&lt;th&gt;Input tokens&lt;/th&gt;
&lt;th&gt;Output tokens&lt;/th&gt;
&lt;th&gt;Cost on gpt-5.6&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Question 1&lt;/td&gt;
&lt;td&gt;264&lt;/td&gt;
&lt;td&gt;57&lt;/td&gt;
&lt;td&gt;$0.00121&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Question 2&lt;/td&gt;
&lt;td&gt;338&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;td&gt;$0.00159&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Question 3&lt;/td&gt;
&lt;td&gt;426&lt;/td&gt;
&lt;td&gt;93&lt;/td&gt;
&lt;td&gt;$0.00197&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Question 4&lt;/td&gt;
&lt;td&gt;534&lt;/td&gt;
&lt;td&gt;52&lt;/td&gt;
&lt;td&gt;$0.00169&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"thanks!"&lt;/td&gt;
&lt;td&gt;588&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;$0.00132&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To read two tokens of gratitude, the model read 588. That is the largest input of the whole conversation, because "thanks!" comes last and carries everything before it. The prices are gpt-5.6's list price, $2 per million input and $12 per million output, from the catalog snapshot of the LLM gateway I work on.&lt;/p&gt;

&lt;p&gt;The thank-you costs 9% more than the first question. It's cheaper than the later questions only because its reply is short: output is six times more expensive per token, and the long answers to questions 2 and 3 are what make those calls expensive. In the thank-you call, input is 89% of the cost. On claude-haiku-5.5, claude-sonnet-5.5 and gemini-3.8-flash, where output is five times the input price, the thank-you is 18% more expensive than the first question.&lt;/p&gt;

&lt;p&gt;The longer the chat, the worse the ratio. After eight exchanges instead of four, the same "thanks!" goes out with 933 tokens of input and costs $0.00201, more than any of the four questions in the table.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it adds up to
&lt;/h3&gt;

&lt;p&gt;In my chat the thank-you is 20 to 22% of what the four real answers cost together, depending on the model. Suppose your bot handles 10,000 conversations a day and 30% of them end with a thank-you; that share is my assumption, so count your own. Then on gpt-5.6 the conversations cost $1,938 a month and the thank-yous add $118.80 on top (+6.1%). On gpt-5.6-mini it's $11.88, on claude-haiku-5.5 $5.83, on claude-sonnet-5.5 $116.64.&lt;/p&gt;

&lt;p&gt;That's not a disaster, but it's money spent on nothing, and it is the easiest line on the bill to remove. A message like "thanks!" doesn't need a model. You can answer it yourself:&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;re&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;

&lt;span class="no"&gt;CLOSERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"thanks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"thank you"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"thx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ty"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"thanks a lot"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ok thanks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="s2"&gt;"great thanks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"cheers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"thank you so much"&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;is_closer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"NFKC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"[^\w\s]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# drop punctuation and emoji&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&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="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;CLOSERS&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Thank you 🙏"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ok, thanks!!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"thanks, but it still doesn't work"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;is_closer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&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 function lowercases the message, removes punctuation and emoji, and checks whether what's left is exactly one of the known phrases. If it is, your code shows a fixed reply like "You're welcome!" and makes no API call. "Thank you 🙏" and "ok, thanks!!" match; "thanks, but it still doesn't work" doesn't, because it's not an exact match, so it goes to the model as it should. The exact match is deliberate: a looser rule like "contains thanks" would also catch "no thanks" and "thanks! one more question".&lt;/p&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;It removes one call per conversation, not the reason that call was expensive. Every real question still goes out with the whole history attached. If your chats are long, trimming old messages or summarizing them saves far more than skipping the thank-you.&lt;/p&gt;

&lt;p&gt;A fixed reply is the same every time, and some users will notice. If your product's tone matters, keep a few variants and pick one at random, or accept the model call as the price of sounding human.&lt;/p&gt;

&lt;p&gt;The phrase list is English and will miss things. Users write "thank u", "tysm", "спасибо", or "thanks, that fixed it". Every miss just falls through to the model, so the cost of a short list is a smaller saving, not a broken bot. Log the messages your bot answers itself and check them once in a while, to make sure no real question got a "You're welcome!".&lt;/p&gt;

&lt;p&gt;Finally, the chat is synthetic and counted with one tokenizer. Claude and Gemini tokenize text differently, and if your provider caches repeated prompt prefixes, the history in each call can be billed at a lower rate. Your system prompt and answer length also change the numbers. To check your own bot, find a conversation that ended with a thank-you and look at the input token count of that last call.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>Self-hosted LLM vs API: calculating the breakeven point</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Mon, 23 Nov 2026 07:11:43 +0000</pubDate>
      <link>https://dev.to/altrouter/self-hosted-llm-vs-api-calculating-the-breakeven-point-3240</link>
      <guid>https://dev.to/altrouter/self-hosted-llm-vs-api-calculating-the-breakeven-point-3240</guid>
      <description>&lt;p&gt;Renting a server with a single RTX 4090 graphics card costs &lt;a href="https://computecomparison.com/guides/real-time-inference-cost-guide" rel="noopener noreferrer"&gt;about $317 a month&lt;/a&gt;. API requests for the Llama 3.1 8B model on OpenRouter start &lt;a href="https://computeprices.com/providers/openrouter/models/llama-3-1-8b" rel="noopener noreferrer"&gt;from $0.05 per 1 million tokens&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;A self-hosted server pays off only with continuous 24/7 generation. Any pause in operation makes buying tokens significantly cheaper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calculating hardware rental costs against buying tokens
&lt;/h2&gt;

&lt;p&gt;Developers often view dropping an API provider as direct savings. In practice, renting a bare chip eats up more budget due to the radical drop in token prices over recent years. Provider price wars have pushed inference costs to an absolute minimum.&lt;/p&gt;

&lt;p&gt;An RTX 4090 server costs $0.44 for every hour of operation. Multiply $0.44 by 24 hours to get $10.56 a day. Multiply that by 30 days to get $316.80 a month. Round it up to $317. &lt;/p&gt;

&lt;p&gt;A monthly rent of $317 equals buying 6.34 billion tokens for Llama 3.1 8B at $0.05 per million. You divide 317 by 0.05 and multiply by a million. &lt;/p&gt;

&lt;p&gt;To justify the hardware rental, the server must generate 211 million tokens every single day. Divide 6.34 billion by 30 days. The hardware has to crunch requests 24/7 without weekends at a speed of 2442 tokens per second. Loading a server with this volume of tasks at the start of a project is practically impossible. Most applications generate short responses, consuming hundreds of tokens per call. You can only accumulate billions of tokens during massive text processing.&lt;/p&gt;

&lt;p&gt;For local tests without complex terminal setup, there is &lt;a href="https://www.gpupartner.com/blog/beginners-guide-local-ai-inkling-qwen-unsloth" rel="noopener noreferrer"&gt;Unsloth Desktop&lt;/a&gt;. The software allows sharing model access over a local network. A developer downloads the app, selects a model, and gets a ready endpoint. Transferring this experience to rented servers in production requires accounting for night downtime. A local computer can be turned off. A rented server continues to consume money every second.&lt;/p&gt;

&lt;h2&gt;
  
  
  VRAM requirements for different models
&lt;/h2&gt;

&lt;p&gt;The 16-bit Llama 3.1 8B model requires about 16 GB of memory. It fits perfectly on a single RTX 4090 with 24 GB on board. This leaves room for the context window and request batching. Batching allows processing multiple requests simultaneously, which increases server throughput.&lt;/p&gt;

&lt;p&gt;The Llama 4 Scout model requires &lt;a href="https://computecomparison.com/guides/fine-tuning-llama-cost-guide" rel="noopener noreferrer"&gt;about 28 GB of VRAM&lt;/a&gt; to run with QLoRA quantization. This volume does not fit into a single consumer card. It fits on two RTX 4090s or one A100 40GB server card. Renting an A100 instance on RunPod costs &lt;a href="https://www.koyeb.com/blog/best-serverless-gpu-platforms-for-ai-apps-and-inference-in-2026" rel="noopener noreferrer"&gt;$2.72 per hour&lt;/a&gt;. Multiply 2.72 by 720 hours a month to get $1958. The sum looks massive for a small project.&lt;/p&gt;

&lt;p&gt;The API for Llama 4 Scout costs on average &lt;a href="https://llamaapipricing.com/llama-4-api-pricing/" rel="noopener noreferrer"&gt;between $0.15 and $0.50&lt;/a&gt; per 1 million tokens at third-party hosting providers. The difference in fixed costs is huge. Renting an A100 pays off only with giant traffic volumes.&lt;/p&gt;

&lt;p&gt;Running large models with 70B parameters or more requires professional hardware. The Qwen 2.5 72B model takes up about 140 GB of memory when using full weights. It needs an H100 80GB level graphics card, which costs &lt;a href="https://computecomparison.com/guides/real-time-inference-cost-guide" rel="noopener noreferrer"&gt;from $2.49 per hour&lt;/a&gt; to rent. &lt;/p&gt;

&lt;p&gt;The API for Qwen 2.5 72B costs &lt;a href="https://computeprices.com/providers/together-ai/models/qwen-2-5-72b" rel="noopener noreferrer"&gt;from $0.35 to $1.20&lt;/a&gt; per 1 million tokens depending on the provider. Together AI charges $1.20 for this model. With H100 rental prices starting at $2.49 per hour, the server must generate 2.07 million tokens every hour just to break even. You divide 2.49 by 1.20. More details about pricing are written in our article about neural network API prices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Breakeven point using a vectorization pipeline
&lt;/h2&gt;

&lt;p&gt;The breakeven point occurs at a specific mathematical mark. The calculation depends on the task type and the chosen model. Text vectorization shows this boundary perfectly.&lt;/p&gt;

&lt;p&gt;The breakeven point for renting an RTX 4090 at $317 a month compared to the OpenAI text-embedding-3-small API comes at a stable volume of &lt;a href="https://computecomparison.com/guides/rag-pipeline-cost-guide" rel="noopener noreferrer"&gt;about 1.06 million requests per day&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Before reaching the 1.06 million daily requests mark, using an API is cheaper and requires no maintenance. The API cost curve goes above the fixed server cost only after crossing this threshold. Vectorizing a medium-sized knowledge base rarely demands millions of daily requests. Usually, the base is indexed once. Then only new documents and user queries are vectorized. The main token volume is spent during the initial data load phase.&lt;/p&gt;

&lt;p&gt;Cheap APIs often have strict limits on requests per minute. Providers rarely write about this on their main pricing pages. When the threshold is reached, the service returns an error, which you can read about in the article on &lt;a href="https://altrouter.ai/en/blog/oshibka-429-rate-limit/" rel="noopener noreferrer"&gt;/en/blog/oshibka-429-rate-limit/&lt;/a&gt;. Rate limits force developers to switch to more expensive plans or spin up their own servers to bypass the restrictions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downtime impact and hidden infrastructure costs
&lt;/h2&gt;

&lt;p&gt;The load schedule breaks ideal utilization calculations. Startups with uneven traffic have pronounced peaks during the day and deep drops at night. Users sleep, and the server sits idle. Rent is charged every hour regardless of the actual payload.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Febhtvmgx1ywg9iyd5c1v.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Febhtvmgx1ywg9iyd5c1v.webp" alt="Server unit peacefully lying on a soft white pillow" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the server is idle at night or during traffic dips, the breakeven point shifts significantly. With a 12-hour downtime, you will need to generate twice as many tokens during active hours to justify the fixed rental fee. The server continues to consume money even without requests. The zero operational overhead of an API beats renting hardware under an erratic load schedule.&lt;/p&gt;

&lt;p&gt;Hidden infrastructure costs change the calculations even more. Comparisons usually feature only bare metal versus token prices. They do not factor in an engineer's salary. Setting up vLLM takes time from a qualified specialist. The same goes for debugging CUDA crashes and configuring a load balancer. &lt;/p&gt;

&lt;p&gt;API providers have implemented automatic prompt caching. This reduces the cost of repeating tokens by 50 to 90 percent. System instructions or heavy context in RAG systems cost pennies. You will have to configure your own server for prefix caching manually, allocating precious VRAM for this task. The memory fills up with cache, leaving less room for the actual generation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quality degradation when quantizing large models
&lt;/h2&gt;

&lt;p&gt;Running heavy neural networks on cheap hardware requires compromises. To squeeze Qwen 2.5 72B into affordable graphics cards, the model must be heavily quantized to 4-bit. Quantization trims the precision of floating-point numbers. The model weights take up less space but lose some information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fidnqmxf8f3uympjarm2r.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fidnqmxf8f3uympjarm2r.webp" alt="Scissors cutting metal contacts on a microchip" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sources stay silent about quality degradation during such compression. The responses of a local server with a quantized model will be worse than those from an API provider. Providers spin full weights in FP16 or BF16 formats on H100 clusters. They can afford to keep giant models in RAM without compression.&lt;/p&gt;

&lt;p&gt;Saving on rent turns into a drop in response accuracy. Complex logical tasks require full weights, which are available via API without buying expensive servers. The neural network starts confusing facts and writing less coherent code. A developer spends hours debugging prompts, trying to make the quantized model work properly. The project loses users due to low generation quality. The cheapskate pays twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generation speed and latency
&lt;/h2&gt;

&lt;p&gt;Time to first token is highly important for interactive applications. Standard GPU inference using vLLM provides a time to first token of &lt;a href="https://computecomparison.com/guides/real-time-inference-cost-guide" rel="noopener noreferrer"&gt;50-200 ms&lt;/a&gt; for 7B size models. The time depends heavily on the current server load. A request queue increases latency. One heavy request blocks the processing of the rest.&lt;/p&gt;

&lt;p&gt;Achieving a latency of less than 100 ms during inference requires &lt;a href="https://computecomparison.com/guides/real-time-inference-cost-guide" rel="noopener noreferrer"&gt;using specialized Groq LPU chips&lt;/a&gt; or self-hosting on an H100 with the TensorRT-LLM library. Setting up TensorRT-LLM takes days and demands a deep understanding of the CUDA architecture.&lt;/p&gt;

&lt;p&gt;Groq chips deliver a generation speed of 500 to 800 tokens per second. A rented RTX 4090 is physically incapable of showing such throughput due to memory bus limitations. Providers with optimized hardware beat a budget solution in speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interruptible instances and the hybrid approach
&lt;/h2&gt;

&lt;p&gt;Server costs can be optimized at high traffic volumes. Using interruptible spot instances on platforms like Vast.ai allows &lt;a href="https://computecomparison.com/guides/real-time-inference-cost-guide" rel="noopener noreferrer"&gt;reducing GPU inference costs by 66%&lt;/a&gt; compared to on-demand pricing.&lt;/p&gt;

&lt;p&gt;Instead of $0.44 an hour for an RTX 4090, you are charged about $0.15. The risk lies in the possible termination of the machine at any moment. The provider gives the capacity to another client when the bid goes up. For production, you build an architecture with a minimal pool of permanent servers and spot machines for peak loads. A load balancer redirects traffic when a node drops. Setting up such a system requires time and experience.&lt;/p&gt;

&lt;p&gt;Using a hybrid approach lets you &lt;a href="https://computecomparison.com/guides/batch-processing-cost-guide" rel="noopener noreferrer"&gt;save 50 to 70 percent of the budget&lt;/a&gt; compared to using only a managed API. Complex tasks go to the paid API. Massive simple tasks are sent to your own server with spot instances. Request routing reduces the total cost of the system. The developer balances between reliability and price.&lt;/p&gt;

&lt;h2&gt;
  
  
  Task splitting via API
&lt;/h2&gt;

&lt;p&gt;The hybrid approach is easy to implement in practice. Heavy tasks of image or video generation are more profitable to send to an API, leaving only text routing to the local server.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;qwen-image-3&lt;/code&gt; model is available in the catalog at a cost of $0.0276 per image. Local image generation requires a separate graphics card and complicates load balancing. An API call solves this problem with a single function.&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;requests&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="c1"&gt;# Example of calling the qwen-image-3 model via API&lt;/span&gt;
&lt;span class="c1"&gt;# The local server does not waste VRAM on generating images&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.altrouter.ai/images/generations"&lt;/span&gt;
&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bearer ar-..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"qwen-image-3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"prompt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Server rack with graphics cards, neon lighting, 4k"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"resolution"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1K"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"response_format"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"async"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;False&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;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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 code sends a text description to the provider's server. The provider allocates capacity to generate the image. Then it returns a link. The local RTX 4090 continues to process user text requests at this moment without speed drops. Task splitting increases the fault tolerance of the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  The decision making rule
&lt;/h2&gt;

&lt;p&gt;Choosing between an API and renting a server comes down to evaluating resource utilization. &lt;/p&gt;

&lt;p&gt;Switching to rented graphics cards makes sense under stable and high load. The server must not sit idle at night or on weekends. &lt;/p&gt;

&lt;p&gt;Paying for tokens saves the budget during uneven traffic. A developer pays exactly for the consumed volume.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Choosing an API&lt;/th&gt;
&lt;th&gt;Choosing a self-hosted server&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Daily volume&lt;/td&gt;
&lt;td&gt;Under 1.06 million requests&lt;/td&gt;
&lt;td&gt;Over 1.06 million requests stably&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Load schedule&lt;/td&gt;
&lt;td&gt;Peaks by day, idle by night&lt;/td&gt;
&lt;td&gt;Even load without drops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrastructure&lt;/td&gt;
&lt;td&gt;No dedicated DevOps&lt;/td&gt;
&lt;td&gt;Resources available to set up vLLM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hardware requirements&lt;/td&gt;
&lt;td&gt;Groq LPU speed needed&lt;/td&gt;
&lt;td&gt;RTX 4090 speed is enough&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Response quality&lt;/td&gt;
&lt;td&gt;Full FP16 weights needed&lt;/td&gt;
&lt;td&gt;4-bit quantization is acceptable&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>MCP token prices: why agents burn your budget</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Sun, 22 Nov 2026 13:35:46 +0000</pubDate>
      <link>https://dev.to/altrouter/mcp-token-prices-why-agents-burn-your-budget-197m</link>
      <guid>https://dev.to/altrouter/mcp-token-prices-why-agents-burn-your-budget-197m</guid>
      <description>&lt;p&gt;The local agent is built and ready. You connect it to the file system and the browser. You also plug in a database. A simple task runs. The agent takes fifteen steps and delivers the result. The API bill arrives later. The total is three times higher than expected. The model barely even called the tools.&lt;/p&gt;

&lt;p&gt;Connecting a typical stack of four MCP servers adds tens of thousands of overhead tokens to every single message. We will calculate this tax on specific models and break down the math behind caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  How many tokens servers burn before the first prompt
&lt;/h2&gt;

&lt;p&gt;Every connected MCP server loads its tool definitions into the context window during every interaction. This happens regardless of whether the functions are called. The mechanism &lt;a href="https://airia.com/blog/how-mcp-tool-calls-drive-hidden-ai-token-costs-and-context-window-inflation/" rel="noopener noreferrer"&gt;drives context inflation&lt;/a&gt;. Measuring nine popular MCP servers showed a volume of 38,900 tokens for 116 tools. This takes up &lt;a href="https://pub.towardsai.net/how-much-context-do-mcp-servers-actually-cost-we-measured-38-900-tokens-bd6187ca140d" rel="noopener noreferrer"&gt;19.4% of a 200k context window&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A typical four-server configuration &lt;a href="https://www.jdhodges.com/blog/claude-code-mcp-server-token-costs/" rel="noopener noreferrer"&gt;adds about 7,000 tokens&lt;/a&gt; of overhead per message. Heavy builds can burn over 50,000 tokens. The developer pays for this volume at every step of the agent's reasoning. Language models lack memory between requests. The entire chat history and all available tools are sent again with every request. If an agent takes ten steps to solve a task, an array of tens of thousands of tokens will be sent and billed ten times.&lt;/p&gt;

&lt;h2&gt;
  
  
  Paying for JSON Schema syntax instead of instructions
&lt;/h2&gt;

&lt;p&gt;Measuring a Notion server with 24 tools reveals a total cost of 17,500 tokens. Out of this volume, &lt;a href="https://pub.towardsai.net/how-much-context-do-mcp-servers-actually-cost-we-measured-38-900-tokens-bd6187ca140d" rel="noopener noreferrer"&gt;93.6% pays for the JSON Schema structure&lt;/a&gt;. The text description for the model takes up a tiny fraction. You pay for curly braces, quotes, and indentation. Service keys like &lt;code&gt;properties&lt;/code&gt; and &lt;code&gt;type&lt;/code&gt; also add to the bill.&lt;/p&gt;

&lt;p&gt;A standard text description of a function takes two lines. Translating this description into a format understood by tool calling requires creating a nested structure. Every parameter gets its own type and description. It also gets a required status. If a tool accepts an array of objects, the schema grows rapidly. Nested structures demand duplicated service keys. The model is forced to process this markup on every call. The main enemy of your budget hides in syntactic garbage, completely overshadowing detailed instructions.&lt;/p&gt;

&lt;p&gt;In our model, the ratio of schema volume to useful user task was 69 to 1. Tokens were counted using the tiktoken &lt;code&gt;o200k_base&lt;/code&gt;. Claude and Gemini use different tokenizers. Vendors do not publish exact benchmarks for the compression efficiency of specific JSON Schema syntax. Numbers might differ slightly depending on the API. The order of magnitude always remains the same. The volume of service markup crushes the volume of useful text. There are no exact public measurements of Time-To-First-Token speed degradation from parsing exactly 20,000 or 40,000 schema tokens during a cache miss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Weight comparison of real servers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Server&lt;/th&gt;
&lt;th&gt;Tools&lt;/th&gt;
&lt;th&gt;Tokens per message&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Playwright (JD Hodges measurement)&lt;/td&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;~3442&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gmail (JD Hodges measurement)&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;~2640&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Repositories (our model)&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;11,121&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser (our model)&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;5826&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;File system (our model)&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;2353&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database (our model)&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;1513&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SQLite (JD Hodges measurement)&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;385&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Gmail server &lt;a href="https://www.jdhodges.com/blog/claude-code-mcp-server-token-costs/" rel="noopener noreferrer"&gt;consumes disproportionately many tokens&lt;/a&gt; due to complex definitions. Just the &lt;code&gt;gmail_create_draft&lt;/code&gt; tool costs 820 tokens. An email client requires passing multiple flags and recipient arrays. You also have to pass body formats. The Playwright server &lt;a href="https://www.jdhodges.com/blog/claude-code-mcp-server-token-costs/" rel="noopener noreferrer"&gt;works more efficiently&lt;/a&gt; per function. It takes 3,442 tokens for 22 tools. The SQLite database costs a mere 385 tokens for six simple functions.&lt;/p&gt;

&lt;p&gt;In our model, GitHub-level repositories take 11,121 tokens for 40 tools. This equals 278 tokens per tool. The browser requires 5,826 tokens for 25 tools, hitting 233 tokens each. The file system adds 2,353 tokens for 12 tools, at 196 tokens a piece. The database costs 1,513 tokens for 8 tools, coming to 189 tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calculating the tax on 15 agent steps
&lt;/h2&gt;

&lt;p&gt;We modeled a typical 15-step agent cycle to estimate real costs. The system prompt takes 1,500 tokens. The user task weighs 300 tokens. Each step adds 800 tokens of tool output and 200 tokens of the model's own response to the history. The schemas of all connected tools are sent in every request.&lt;/p&gt;

&lt;p&gt;Our model includes four servers. These are repositories, browser, file system, and database. The total comes to 85 tools. They occupy 20,813 tokens in every request. Without MCP schemas, 15 steps generate 132,000 input tokens. With schemas, the volume grows to 444,195 tokens. The difference is 3.37 times. The schema share reaches 70% of the total input volume.&lt;/p&gt;

&lt;p&gt;If we calculate using the price for &lt;a href="https://altrouter.ai/en/models/claude-sonnet-5.5/" rel="noopener noreferrer"&gt;claude-sonnet-5.5&lt;/a&gt;, one task without schemas costs $0.2499. With schemas, the price rises to $0.7806. The MCP tax is $0.5307. On a volume of 10,000 tasks, the overpayment will be $5,307. The &lt;a href="https://altrouter.ai/en/models/gpt-6.2-sol/" rel="noopener noreferrer"&gt;gpt-6.2-sol&lt;/a&gt; model shows the exact same numbers. Without schemas, the task costs $0.2499, while with schemas it costs $0.7806. The overpayment for ten thousand tasks equals $5,307.&lt;/p&gt;

&lt;p&gt;For the cheaper &lt;a href="https://altrouter.ai/en/models/deepseek-v4.1-flash/" rel="noopener noreferrer"&gt;deepseek-v4.1-flash&lt;/a&gt; model, the base task price is $0.0360. With schemas, it grows to $0.1140. The MCP tax equals $0.0780. The overpayment for 10,000 tasks will be $780.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://altrouter.ai/en/models/claude-opus-5.5/" rel="noopener noreferrer"&gt;claude-opus-5.5&lt;/a&gt; model shows the highest absolute figures. Without schemas, a task costs $0.4998. With schemas, the price jumps to $1.5613. The tax is $1.0615. On ten thousand tasks, the budget will lose $10,615.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://altrouter.ai/en/models/gemini-3.8-flash/" rel="noopener noreferrer"&gt;gemini-3.8-flash&lt;/a&gt; model spends $0.0937 per task without schemas. With schemas, it comes to $0.2927. The tax takes $0.1990. The overpayment for 10,000 tasks will be $1,990.&lt;/p&gt;

&lt;p&gt;The tax is noticeable even on the fast &lt;a href="https://altrouter.ai/en/models/claude-haiku-5.5/" rel="noopener noreferrer"&gt;claude-haiku-5.5&lt;/a&gt;. The base costs $0.0125. Schemas push the price to $0.0390. The overpayment is $0.0265 for every cycle. In all cases, the cost increases by 212 to 217 percent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the client sends schemas with every message
&lt;/h2&gt;

&lt;p&gt;The protocol architecture requires constant data transmission. The client requests the tool list via the &lt;code&gt;tools/list&lt;/code&gt; endpoint at the start of the session. Then it &lt;a href="https://mcpplaygroundonline.com/blog/mcp-token-counter-optimize-context-window" rel="noopener noreferrer"&gt;forwards these definitions&lt;/a&gt; to the language model in the payload of every individual message.&lt;/p&gt;

&lt;p&gt;The protocol supports updating the list by the server through the &lt;code&gt;listChanged&lt;/code&gt; event. There is currently no standardized mechanism to disable unnecessary schemas at the LLM's own initiative. Developers have to write custom architectural wrappers. Anthropic engineers state directly that loading all definitions upfront and passing intermediate results through the context window &lt;a href="https://www.anthropic.com/research/code-execution-with-mcp" rel="noopener noreferrer"&gt;slows down agents and increases costs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Internal model routing through tools like AltRouter helps lower the base token price, but it fails to solve the context volume problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  How prompt caching affects bloated bills
&lt;/h2&gt;

&lt;p&gt;Providers offer discounts for caching long contexts. Anthropic bills cache writes with a five-minute lifespan at a &lt;a href="https://tensormesh.ai/learn/anthropic-prompt-caching-pricing/" rel="noopener noreferrer"&gt;1.25x multiplier&lt;/a&gt; of the base input token price. A write with a one-hour lifespan costs 2x. Reading from the cache costs 0.1x of the base. This provides a &lt;a href="https://tensormesh.ai/learn/anthropic-prompt-caching-pricing/" rel="noopener noreferrer"&gt;90% discount&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F796vtt9e4z1xm4t6tl55.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F796vtt9e4z1xm4t6tl55.webp" alt="A minimalist white piggy bank is caught in a metal mousetrap" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Anthropic API caches data &lt;a href="https://www.prometheusconsulting.ai/blog/anthropic-prompt-caching-pricing/" rel="noopener noreferrer"&gt;in a strict order&lt;/a&gt;. Tool definitions go first, followed by the system prompt, followed by messages. Tool schemas are static. They always enter the cache first. This makes Claude architecturally favorable for heavy MCP builds.&lt;/p&gt;

&lt;p&gt;In our calculation for claude-sonnet-5.5, we applied prefix caching from the system prompt and schemas. The price of a 15-step cycle dropped from $0.7806 to $0.3122. The savings amounted to 60%. The MCP tax with caching shrank to an acceptable +25% instead of the initial +212%.&lt;/p&gt;

&lt;p&gt;This method breaks during infrequent calls. The caching advice fails if requests to the agent are sent less often than once every five minutes. The context is invalidated. The cache resets. You pay the 1.25x write multiplier for the entire volume of bloated schema syntax. The prefix with schemas ends up costing 25% more than completely disabling the cache. This is a bet on a high request frequency within a single session.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting all tools versus implementing dynamic loading
&lt;/h2&gt;

&lt;p&gt;An excess of tools clutters the context with garbage and raises the risk of errors. The model starts getting confused among dozens of similar functions. Reddit discussions note that completely abandoning the preloading of all schemas &lt;a href="https://www.reddit.com/r/mcp/comments/1xdj52q/i_counted_the_tokens_in_the_tool_definitions_of/" rel="noopener noreferrer"&gt;reduces the number of definition tokens by 96.1%&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0ztvvfnb3ttxeljo9roi.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0ztvvfnb3ttxeljo9roi.webp" alt="An incredibly thick multitool with dozens of open blades lies on the floor" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The progressive disclosure pattern solves the bloated context issue. It allows you to &lt;a href="https://www.solo.io/blog/mcp-progressive-disclosure" rel="noopener noreferrer"&gt;load only a lightweight index&lt;/a&gt; of tools into the context. Full schemas with long JSON structures are requested via a separate call only when necessary.&lt;/p&gt;

&lt;p&gt;The agent receives a short list of available capabilities. If it needs a database, it calls a function to get the database schema. Only after this does the full structure with parameters enter the context. This requires an extra step from the model. The cost of one extra call pays off by saving tens of thousands of tokens on all subsequent steps.&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="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"YOUR_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;tools&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;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"get_tool_schema"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Get the full JSON schema for the required toolset"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"input_schema"&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;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="s2"&gt;"server_name"&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;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="s2"&gt;"enum"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"browser"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"filesystem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"database"&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;span class="s2"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"server_name"&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;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;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="s2"&gt;"Read the config.json file"&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;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before building an agent, you should check the actual weight of your integrations. The mcp-xray utility lets you &lt;a href="https://medium.com/@irregularbi/your-mcp-server-has-a-token-tax-mcp-xray-tells-you-exactly-how-much-c93041c80af1" rel="noopener noreferrer"&gt;measure the token tax&lt;/a&gt; of a specific server before doing any work. It shows the exact context cost per turn.&lt;/p&gt;

&lt;p&gt;If we disable three unnecessary servers in our model and leave only the file system, the cycle price for claude-sonnet-5.5 will be $0.3099. This is 60% cheaper than the version with all servers at $0.7806. You need to connect tools for a specific task instead of keeping them in reserve. Dynamic schema loading saves money more reliably than hoping to hit a five-minute cache window. &lt;a href="https://altrouter.ai/en/blog/kitesurf-optimizatsiya-tokenov-agentov/" rel="noopener noreferrer"&gt;Agent token optimization&lt;/a&gt; begins with an audit of connected servers.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A 10-email thread holds 487 tokens of actual text. With quoted replies the model reads 5,068.</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Sun, 22 Nov 2026 12:00:01 +0000</pubDate>
      <link>https://dev.to/altrouter/a-10-email-thread-holds-487-tokens-of-actual-text-with-quoted-replies-the-model-reads-5068-40f</link>
      <guid>https://dev.to/altrouter/a-10-email-thread-holds-487-tokens-of-actual-text-with-quoted-replies-the-model-reads-5068-40f</guid>
      <description>&lt;p&gt;You build a small tool that summarizes support tickets. Each ticket is an email thread, and your help desk stores every message the way it arrived. You join the messages, send them to a model, and get a good summary back. The token count in the response is about ten times what you expected from looking at the conversation.&lt;/p&gt;

&lt;p&gt;Nothing went wrong. The model read exactly what you sent, and most of it was the same text, copied again and again by the mail client.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads; APIs bill per million of them. A &lt;strong&gt;tokenizer&lt;/strong&gt; is the program that cuts text into tokens; I used tiktoken with &lt;code&gt;o200k_base&lt;/code&gt;, the one OpenAI's current models use. &lt;strong&gt;Input&lt;/strong&gt; tokens are what you send, &lt;strong&gt;output&lt;/strong&gt; tokens are what the model writes back, and output usually costs five or six times more per token. A &lt;strong&gt;quoted reply&lt;/strong&gt; is the previous message pasted under your answer, each line starting with &lt;code&gt;&amp;gt;&lt;/code&gt;, under a line like "On Mon, Nov 3, Dana wrote:". A &lt;strong&gt;list price&lt;/strong&gt; is the vendor's official price per million tokens, before any discount.&lt;/p&gt;

&lt;h3&gt;
  
  
  The measurement
&lt;/h3&gt;

&lt;p&gt;I wrote a synthetic 10-message thread: a customer charged twice, a support agent, a refund. The messages are short, between 26 and 65 tokens each, with a two-line signature. Every reply quotes the whole previous message, which already contains its own quote, which contains the one before. That is the default in most mail clients. Lines are wrapped at 72 characters, as in plain-text mail.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Message&lt;/th&gt;
&lt;th&gt;Tokens as it arrived&lt;/th&gt;
&lt;th&gt;Tokens of new text&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1st&lt;/td&gt;
&lt;td&gt;57&lt;/td&gt;
&lt;td&gt;57&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2nd&lt;/td&gt;
&lt;td&gt;148&lt;/td&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5th&lt;/td&gt;
&lt;td&gt;423&lt;/td&gt;
&lt;td&gt;41&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10th&lt;/td&gt;
&lt;td&gt;1,030&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;All 10 together&lt;/td&gt;
&lt;td&gt;5,068&lt;/td&gt;
&lt;td&gt;487&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The whole conversation is 487 tokens of new text. Stored message by message, it's 5,068: 10.4 times as much. Even the last message on its own, 1,030 tokens, is more than twice the whole conversation, because it carries every earlier message plus the clutter around them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why it's worse than "just duplicates"
&lt;/h3&gt;

&lt;p&gt;If every message only copied the earlier text, a thread of N messages would come out at about (N + 1) / 2 times the new text, so 5.5x for ten messages. That alone grows fast: twenty messages would be 10.5x. Two things push the real number higher.&lt;/p&gt;

&lt;p&gt;The first is the &lt;code&gt;&amp;gt;&lt;/code&gt; markers. Each level of quoting adds another &lt;code&gt;&amp;gt;&lt;/code&gt; to the start of every line, and the tokenizer bills it. A line of 10 tokens costs 11 at depth one, 15 at depth five and 19 at depth nine. In the 10th message, markers alone are 36% of the tokens. Clients that nest as &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; without spaces are a bit cheaper (4,240 tokens for the same thread), but not much.&lt;/p&gt;

&lt;p&gt;The second is everything around the text. Every "On ... wrote:" line and every signature gets quoted along with the message and copied down the thread at every level.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it costs
&lt;/h3&gt;

&lt;p&gt;Say your summarizer sends 300 tokens of instructions plus the thread and gets back a 150-token summary, for 1,000 tickets a day. At gpt-5.6's list price of $2 per million input and $12 per million output (from the catalog snapshot of the LLM gateway I work on), a thread costs $0.0125 as stored and $0.0034 with the quotes removed. That's 3.7x, or $376 against $101 a month. On gpt-5.6-mini it's $37.61 against $10.12. On claude-haiku-5.5 and claude-sonnet-5.5 it's 4.0x, because their output is relatively cheaper, so input is a larger share of the bill.&lt;/p&gt;

&lt;p&gt;The fix is to cut the quoted block before the text reaches the model. Each message keeps only what its author wrote, and the thread as a whole still has every word once:&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;re&lt;/span&gt;

&lt;span class="no"&gt;QUOTE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"^On .+ wrote:\n(?:&amp;gt;.*(?:\n|$))*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;M&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;strip_quotes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;QUOTE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Thanks, refund received!\n\nOn Mon, Nov 3, 2026, Support wrote:\n&amp;gt; The refund\n&amp;gt; was issued today.\n&amp;gt;&amp;gt; Any update?"&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;strip_quotes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&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 pattern finds the "wrote:" line and every line under it that starts with &lt;code&gt;&amp;gt;&lt;/code&gt;, and removes them together. In my test thread it gives back each message's own text exactly, and the ten stripped messages add up to the 487 tokens in the table.&lt;/p&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;It only handles plain-text quoting. HTML mail usually wraps the quote in a &lt;code&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; or a &lt;code&gt;div&lt;/code&gt; with a client-specific class, and the "wrote:" line is localized: a German client says "schrieb", a Russian one says "написал". You'll need a pattern per format you actually receive, or a mail-parsing library that knows them.&lt;/p&gt;

&lt;p&gt;Some replies answer inline, writing between quoted lines: "&amp;gt; Which card? / The Visa ending in 4471." Strip the quote there and the answer loses its question. If your users do this, keep the quoted line directly above each inline answer.&lt;/p&gt;

&lt;p&gt;The saving depends on the job. My summarizer reads the whole thread once, so input dominates. A bot that drafts a reply to each incoming message pays for instructions and output every time, and with the same numbers it saves only 27% (1.37x). Measure your own split before expecting 3.7x.&lt;/p&gt;

&lt;p&gt;Finally, the thread is synthetic and counted with one tokenizer. Real threads have longer signatures, legal footers and forwarded chains, so they probably repeat even more, but I haven't measured that. Claude and Gemini tokenize differently, though they still read every copy. To check your own data, compare the token count of one stored thread with and without quotes.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>A 133 KB image pasted into my prompt as text cost 122,584 tokens</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Sat, 21 Nov 2026 12:00:01 +0000</pubDate>
      <link>https://dev.to/altrouter/a-133-kb-image-pasted-into-my-prompt-as-text-cost-122584-tokens-2g2i</link>
      <guid>https://dev.to/altrouter/a-133-kb-image-pasted-into-my-prompt-as-text-cost-122584-tokens-2g2i</guid>
      <description>&lt;p&gt;Here's a mistake that doesn't look like one. You build a support bot that reads incoming emails and drafts replies. The emails are HTML, so you send the HTML. Most of them have the company logo in the signature, embedded right in the markup. Nothing breaks, the drafts are fine, and the input bill is about a hundred times what you estimated.&lt;/p&gt;

&lt;p&gt;The logo is the problem. When a file travels inside text, it's usually written as base64, and the model has to read every character of it.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads; APIs bill per million of them. A &lt;strong&gt;tokenizer&lt;/strong&gt; is the program that cuts text into tokens; I used tiktoken with &lt;code&gt;o200k_base&lt;/code&gt;, the one OpenAI's current models use. &lt;strong&gt;Input&lt;/strong&gt; tokens are everything you send in the request. &lt;strong&gt;Base64&lt;/strong&gt; is a way to write any file, an image, a PDF, a zip, using only 64 safe characters (letters, digits, &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;), so it can sit inside text formats. A &lt;strong&gt;data URI&lt;/strong&gt; is a link that contains the file itself, like &lt;code&gt;src="data:image/png;base64,iVBORw0KGgo..."&lt;/code&gt; in an HTML &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag. A &lt;strong&gt;list price&lt;/strong&gt; is the vendor's official price per million tokens, before any discount.&lt;/p&gt;

&lt;h3&gt;
  
  
  The measurement
&lt;/h3&gt;

&lt;p&gt;I took four PNG files of different sizes, base64-encoded them, and counted the tokens. I added 100 KB of random bytes as a control, and English prose from Python's own docstrings for comparison.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;File size&lt;/th&gt;
&lt;th&gt;Tokens&lt;/th&gt;
&lt;th&gt;Tokens per KB&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Social preview image (PNG)&lt;/td&gt;
&lt;td&gt;133.4 KB&lt;/td&gt;
&lt;td&gt;122,584&lt;/td&gt;
&lt;td&gt;919&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;512-pixel icon (PNG)&lt;/td&gt;
&lt;td&gt;13.1 KB&lt;/td&gt;
&lt;td&gt;12,096&lt;/td&gt;
&lt;td&gt;924&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser screenshot (PNG)&lt;/td&gt;
&lt;td&gt;271.3 KB&lt;/td&gt;
&lt;td&gt;248,134&lt;/td&gt;
&lt;td&gt;914&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Random bytes&lt;/td&gt;
&lt;td&gt;100.0 KB&lt;/td&gt;
&lt;td&gt;93,147&lt;/td&gt;
&lt;td&gt;931&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;English prose, for comparison&lt;/td&gt;
&lt;td&gt;20.4 KB&lt;/td&gt;
&lt;td&gt;4,955&lt;/td&gt;
&lt;td&gt;243&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All four images land between 914 and 931 tokens per kilobyte of the original file, which is the same rate as random noise. That makes sense: PNG and JPEG are already compressed, so their bytes look random, and base64 of random bytes gives the tokenizer nothing to merge. It averages 1.48 characters per token. English prose averages 4.22.&lt;/p&gt;

&lt;p&gt;Two things stack up here. Base64 makes the file a third longer, because it writes every 3 bytes as 4 characters. Then the tokenizer, which was trained on human text, cuts that string into tiny pieces. The result is roughly 0.9 tokens per byte, so you can estimate any file in your head: &lt;strong&gt;kilobytes × 920&lt;/strong&gt;. The older &lt;code&gt;cl100k_base&lt;/code&gt; tokenizer is a few percent worse still.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it costs
&lt;/h3&gt;

&lt;p&gt;The 133 KB preview image is 122,584 tokens. At gpt-5.6's list price of $2 per million input tokens (from the catalog snapshot of the LLM gateway I work on), that's $0.25 per request. On claude-haiku-5.5 at $0.10 per million it's 1.2 cents. Small numbers, until they repeat.&lt;/p&gt;

&lt;p&gt;Back to the support bot. Say an email's actual text is 400 tokens, the signature logo is a modest 40 KB, and you process 1,000 emails a day. The logo adds about 37,300 tokens, so each request is 94 times bigger than the text you meant to send. On gpt-5.6-mini at $0.20 per million, the month goes from $2.40 to $225.95. On gpt-5.6 it goes from $24 to $2,259.53. You're paying for the model to read a picture it can't see, because as text it's just a long string of letters.&lt;/p&gt;

&lt;p&gt;Size also turns into a reliability problem. At 920 tokens per kilobyte, anything over about 430 KB doesn't fit in a 400K-token context window, and anything over about 1 MB doesn't fit in a 1M one. A normal phone photo of 2 MB comes out at roughly 1.9 million tokens, so the request fails with a context-length error, and it fails only for the users who attach big files. That bug is hard to reproduce.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where base64 sneaks in
&lt;/h3&gt;

&lt;p&gt;Data URIs in HTML emails and scraped pages. JSON API responses with an &lt;code&gt;avatar&lt;/code&gt; or &lt;code&gt;attachment&lt;/code&gt; field, passed whole into a prompt or returned whole from a tool call. Log lines that dump request bodies. Jupyter notebooks, whose &lt;code&gt;.ipynb&lt;/code&gt; files store every plot as base64.&lt;/p&gt;

&lt;p&gt;The fix is to remove the blobs before the text reaches the model and leave a short note in their place:&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;re&lt;/span&gt;

&lt;span class="no"&gt;BLOB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"data:[\w/+.-]+;base64,[A-Za-z0-9+/=]+|[A-Za-z0-9+/=]{200,}"&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;strip_blobs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;BLOB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;m&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;"[binary data, {len(m.group())} chars removed]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;p&amp;gt;Thanks!&amp;lt;/p&amp;gt;&amp;lt;img src="data:image/png;base64,'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"iVBORw0KGgo"&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'"&amp;gt;'&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;strip_blobs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&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="s2"&gt;"chars"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first alternative catches data URIs. The second catches any long unbroken run of base64 characters, which is what attachments in JSON usually look like. Run it on everything you didn't write yourself: emails, scraped pages, tool results. If the model really needs to see the image, send it as an image part of the request, which vendors bill by the picture's pixel dimensions rather than by its byte size.&lt;/p&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;The regex is a blunt tool. A 200-character run of letters and digits isn't always base64: long hashes, API tokens, minified code, or a DNA sequence will be cut too. Tune the threshold for your data and log what you remove at least at first.&lt;/p&gt;

&lt;p&gt;Sometimes the base64 is the point. If you're asking the model to decode a string or debug an encoding issue, stripping it defeats the purpose. In that case send a short sample, not the whole file.&lt;/p&gt;

&lt;p&gt;Image parts aren't free either. A picture sent the proper way still costs tokens: a high-resolution photo can cost anywhere from about a thousand to over ten thousand, depending on the vendor. That's a much smaller bill than the base64 version, but it isn't zero.&lt;/p&gt;

&lt;p&gt;Finally, my numbers come from one tokenizer. Claude and Gemini use their own, so the exact rate will differ. But base64 is close to random text for any tokenizer trained on human language, so expect it to be expensive everywhere. Check the rate on your provider by sending one file and reading the token count in the response.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>Line numbers made the code I send to an LLM 42% more expensive</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Fri, 20 Nov 2026 12:00:02 +0000</pubDate>
      <link>https://dev.to/altrouter/line-numbers-made-the-code-i-send-to-an-llm-42-more-expensive-3440</link>
      <guid>https://dev.to/altrouter/line-numbers-made-the-code-i-send-to-an-llm-42-more-expensive-3440</guid>
      <description>&lt;p&gt;If you build a coding helper, you'll soon want the model to point at exact lines: "the bug is on line 212", "replace lines 40 to 52". The usual trick is to number every line before you paste the file into the prompt. It works, and it's cheap to write: one &lt;code&gt;enumerate&lt;/code&gt; call.&lt;/p&gt;

&lt;p&gt;It isn't cheap to send. I measured it, and in the most common format the numbers add 42% to the tokens of the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  A few words first
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;token&lt;/strong&gt; is a chunk of text the model reads; APIs bill per million of them. A &lt;strong&gt;tokenizer&lt;/strong&gt; is the program that cuts text into tokens; I used tiktoken with &lt;code&gt;o200k_base&lt;/code&gt;, the one OpenAI's current models use. &lt;strong&gt;Input&lt;/strong&gt; tokens are everything you send in the request, priced at the input rate. A &lt;strong&gt;list price&lt;/strong&gt; is the vendor's official price per million tokens, before any discount. &lt;strong&gt;&lt;code&gt;cat -n&lt;/code&gt;&lt;/strong&gt; is the Unix command that prints a file with line numbers; many tools copy its layout: the number padded to six characters, then a tab.&lt;/p&gt;

&lt;h3&gt;
  
  
  The measurement
&lt;/h3&gt;

&lt;p&gt;I took every top-level module of the Python 3.13 standard library, excluding tests and private modules: 131 files, 107,041 lines, 893,573 tokens. Then I counted the same files again with five ways of numbering the lines.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format of each line&lt;/th&gt;
&lt;th&gt;Tokens&lt;/th&gt;
&lt;th&gt;Extra&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no numbers&lt;/td&gt;
&lt;td&gt;893,573&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;7&amp;lt;tab&amp;gt;code&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1,058,786&lt;/td&gt;
&lt;td&gt;+18.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;`7\&lt;/td&gt;
&lt;td&gt;code`&lt;/td&gt;
&lt;td&gt;1,142,306&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;7: code&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1,159,092&lt;/td&gt;
&lt;td&gt;+29.7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;7&amp;lt;tab&amp;gt;code&lt;/code&gt; (cat -n)&lt;/td&gt;
&lt;td&gt;1,272,868&lt;/td&gt;
&lt;td&gt;+42.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;cat -n&lt;/code&gt; layout costs 3.54 extra tokens per line, and an average line of this code is only 8.35 tokens long. The per-file overhead stays in a narrow band: the median file gets +41%, and 80% of files land between +35% and +48%. The textwrap module goes from 4,491 tokens to 6,084. A right-aligned &lt;code&gt;42 | code&lt;/code&gt;, another popular layout, is almost as bad at +39%.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the padding costs more than the number
&lt;/h3&gt;

&lt;p&gt;A number below 1,000 is a single token. The cost is in what surrounds it. You can check this in four lines:&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;tiktoken&lt;/span&gt;
&lt;span class="n"&gt;enc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tiktoken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_encoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"o200k_base"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"     7\tx = 1\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"7: x = 1\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"7\tx = 1\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"x = 1\n"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&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="nb"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&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 plain line is 5 tokens. The &lt;code&gt;cat -n&lt;/code&gt; version is 8: the five padding spaces become two tokens, the digit is one more, and the tab happens to merge with the next character. &lt;code&gt;7:&lt;/code&gt; costs two extra tokens, the number and the colon. A bare number followed by a tab costs one, because the tab merges into the code that follows it. That's why the cheapest format in the table is the plainest one.&lt;/p&gt;

&lt;p&gt;Two more details. Blank lines get numbered too. Without numbers a blank line is nearly free, because its newline merges with the previous one into a single token; with &lt;code&gt;cat -n&lt;/code&gt; numbers it costs four or five. And at line 1,000 every format gets one token more expensive, because the tokenizer cuts four digits as &lt;code&gt;123&lt;/code&gt; plus &lt;code&gt;4&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it costs per month
&lt;/h3&gt;

&lt;p&gt;Say your assistant sends three files of median size, 4,250 tokens each, with every request, and handles 1,000 requests a day. On gpt-5.6 or claude-sonnet-5.5 at the $2 per million list price (from the catalog snapshot of the LLM gateway I work on), the code alone is $765 a month. Numbered &lt;code&gt;cat -n&lt;/code&gt; style it's $1,089.72, so the line numbers cost $324.72 a month. With &lt;code&gt;7&amp;lt;tab&amp;gt;code&lt;/code&gt; they cost $141.44. On a small model the absolute amounts shrink: on gpt-5.6-mini the &lt;code&gt;cat -n&lt;/code&gt; numbers cost $32.47 a month, on claude-haiku-5.5 $16.24. The share stays the same, because it's set by tokens, not by the price.&lt;/p&gt;

&lt;p&gt;So if you need numbers, a few habits help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;number&amp;lt;tab&amp;gt;line&lt;/code&gt; with no padding. It gives you the same information for less than half the overhead of &lt;code&gt;cat -n&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Number only the part you're asking about. If the question is about one function, send that function with numbers and the rest of the file without, or not at all.&lt;/li&gt;
&lt;li&gt;If you need the numbers to apply edits, consider asking for search-and-replace blocks instead, which quote the old text and need no numbers at all.&lt;/li&gt;
&lt;li&gt;Tell the model not to repeat the numbers in its answer. Output tokens usually cost several times more than input, and a numbered answer can't be pasted back as code anyway.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What this doesn't solve
&lt;/h3&gt;

&lt;p&gt;Line numbers exist for a reason. They let the model refer to a place without quoting it, and they may make its answers more accurate. I didn't measure answer quality. If numbers save you one wrong edit and a retry, they can pay for themselves.&lt;/p&gt;

&lt;p&gt;The figures come from one tokenizer. Claude and Gemini use their own tokenizers, so the exact percentages will differ, though padding and separators cost something everywhere. They also come from one kind of code: the standard library has longer lines than a typical config file, and short lines suffer more, because the prefix is a fixed cost per line.&lt;/p&gt;

&lt;p&gt;Finally, if you send the same files again and again, prompt caching can cut their input price a lot, numbered or not. Caching makes the overhead cheaper, but the numbered file is still 42% bigger, and it still takes 42% more of your context window.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>beginners</category>
      <category>cost</category>
    </item>
    <item>
      <title>Token price lies: how Gemini 4 Neon cuts your API bill</title>
      <dc:creator>Altrouter</dc:creator>
      <pubDate>Fri, 20 Nov 2026 07:18:55 +0000</pubDate>
      <link>https://dev.to/altrouter/token-price-lies-how-gemini-4-neon-cuts-your-api-bill-3d0d</link>
      <guid>https://dev.to/altrouter/token-price-lies-how-gemini-4-neon-cuts-your-api-bill-3d0d</guid>
      <description>&lt;p&gt;Running autonomous coding agents requires precise session cost calculations. Nominal rates for new models often hide the actual cost structure. The bulk of your budget goes to invisible reasoning tokens and context operations. &lt;/p&gt;

&lt;p&gt;Switching agentic development workflows to Gemini 4 Neon cuts final costs by 32 to 36 percent compared to Gemini 4 Carbon and Claude through free cache writes and fewer revisions, provided you force the default reasoning level down and keep prefixes longer than 4096 tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  The price paradox: why Neon is cheaper than Carbon in tests
&lt;/h2&gt;

&lt;p&gt;Until November 30, 2026, the flagship Gemini 4 Carbon runs on a promo rate of &lt;a href="https://www.datastudios.org/post/google-gemini-4-neon-launch-api-pricing-3-input-15-output" rel="noopener noreferrer"&gt;$2 per million input tokens and $10 per million output tokens&lt;/a&gt;. The base price for the intermediate &lt;a href="https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-gemini-4-neon/" rel="noopener noreferrer"&gt;Gemini 4 Neon&lt;/a&gt; model, released on November 18, 2026, is &lt;a href="https://aistudio.google.com/docs/pricing" rel="noopener noreferrer"&gt;fixed at $3 for input and $15 for output&lt;/a&gt;. At first glance, the flagship model appears 33 percent cheaper. On December 1, 2026, Carbon &lt;a href="https://www.datastudios.org/post/google-gemini-4-neon-launch-api-pricing-3-input-15-output" rel="noopener noreferrer"&gt;will go up to $4 and $20&lt;/a&gt;. Neon's permanent price will then sit 25 percent below the flagship. &lt;/p&gt;

&lt;p&gt;Even now with a higher nominal rate, Neon proves more cost-effective in actual workloads. In Google Antigravity environment tests, the cost of solving end-to-end development tasks with Neon is &lt;a href="https://antigravity.google/blog/gemini-4-neon-in-google-antigravity/" rel="noopener noreferrer"&gt;32 percent lower&lt;/a&gt; than with Carbon. The model generates concise code and requires fewer wasted revision cycles. The Models Engineering Index rates a model's ability to solve real tasks from GitHub repositories. The new release scored &lt;a href="https://blog.google/innovation-and-ai/models-and-research/gemini-models/introducing-gemini-4-neon/" rel="noopener noreferrer"&gt;68.1 points&lt;/a&gt;, beating Claude Fable 5.2 with its 66.3 points, &lt;a href="https://altrouter.ai/en/models/claude-opus-5.5/" rel="noopener noreferrer"&gt;Claude Opus 5.5&lt;/a&gt; with 60.8 points, and Gemini 4 Carbon itself with a score of 60.6. &lt;/p&gt;

&lt;p&gt;In the Terminal-Bench 4.1 agent test adjusted for cheating, the model achieved &lt;a href="https://deepmind.google/models/model-cards/gemini-4-neon/" rel="noopener noreferrer"&gt;65.2 percent&lt;/a&gt; when run through Antigravity-CLI 1.5.9. The Artificial Analysis Coding Agent Index benchmark evaluated the model on its ability to autonomously navigate a file system and fix bugs. The new model took first place with a score of &lt;a href="https://antigravity.google/blog/gemini-4-neon-in-google-antigravity/" rel="noopener noreferrer"&gt;58.6 points&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Developers on Hacker News &lt;a href="https://news.ycombinator.com/item?id=50552424" rel="noopener noreferrer"&gt;joke about Google's naming convention&lt;/a&gt;, comparing the lineup to the periodic table. Users try to map out the release logic. Hydrogen acts as the base and weakest model. Neon follows it. Then comes &lt;a href="https://altrouter.ai/en/models/gemini-4-argon/" rel="noopener noreferrer"&gt;Gemini 4 Argon&lt;/a&gt;. Carbon serves as the flagship. Commenters mock the addition of carbon to a series of noble gases. &lt;/p&gt;

&lt;p&gt;Discussions highlight the unusual architecture of the new release. Neon is based on a compact Hydrogen-class base checkpoint. The model outperforms the heavy Carbon through deep RL optimization for agentic environments. Commenters call Neon the long-awaited successor to Gemini 3.1 Pro. Users see better response times with quality comparable to Claude Opus 5.5. The community praises the shrinking gap with OpenAI and Anthropic models in Terminal-Bench and SWE-bench tests. Commenters consider this gap the primary detector of marketing exaggeration. Comparing costs across different architectures works best through log analysis. General principles of cost formation are described in our article about neural network API prices.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hidden counter: how reasoning tokens drain the budget
&lt;/h2&gt;

&lt;p&gt;In coding agents, hidden reasoning tokens account for up to 70 to 85 percent of the response cost. The model generates a chain of thought before delivering the final answer. These tokens remain invisible to the user. The developer receives only the final code but pays for the entire generation process. Hidden tokens &lt;a href="https://dev.to/hassann/gemini-4-neon-pricing-3-input-15-output-and-what-a-call-really-costs-5g09"&gt;are billed at the full output rate&lt;/a&gt;: $15.00 per million tokens. This makes the nominal $3.00 input price deceptive. The main expenses accumulate during the output phase.&lt;/p&gt;

&lt;p&gt;Google does not publish the exact hardware boundaries for chain-of-thought generation. The volume of hidden tokens lacks strict limits and depends directly on prompt complexity. By default, the API uses a high reasoning level, which multiplies the final bill.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Reasoning level&lt;/th&gt;
&lt;th&gt;Average task cost&lt;/th&gt;
&lt;th&gt;Default status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;low&lt;/td&gt;
&lt;td&gt;$0.75&lt;/td&gt;
&lt;td&gt;Disabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;medium&lt;/td&gt;
&lt;td&gt;$1.90&lt;/td&gt;
&lt;td&gt;Disabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;high&lt;/td&gt;
&lt;td&gt;$3.74&lt;/td&gt;
&lt;td&gt;Enabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;xhigh&lt;/td&gt;
&lt;td&gt;$6.44&lt;/td&gt;
&lt;td&gt;Disabled&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Executing a task at the default high level costs $3.74 on average compared to $0.75 at the low level. Let us calculate a typical cold call with 10,000 input tokens on the standard paid tier. Imagine a task to refactor a large component. The script sends 10,000 input tokens. At the $3.00 per million rate, this costs $0.030. The model starts working at the default high level. It generates 2,000 hidden reasoning tokens while analyzing dependencies and code structure. Then it outputs 1,000 tokens of useful response. The billing system adds these values together. The result is 3,000 output tokens. We multiply them by the $0.000015 per token rate. The output costs $0.045. We add input and output. The final bill for one request comes to $0.075, or 7.5 cents.&lt;/p&gt;

&lt;p&gt;The lack of hard limits on invisible token volume creates budget risks. A complex prompt forces the model to generate thousands of hidden tokens. If an agent operates in an autonomous loop and constantly hits compilation errors, background calls at the high level will quickly drain your daily funds limit. The xhigh mode increases the average task cost to $6.44. Its use is justified only for the most complex algorithmic problems. To avoid overspending, developers implement limits at the application level. We covered this approach in detail in our article on how to reduce token costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Free cache writes: the math behind bill reduction
&lt;/h2&gt;

&lt;p&gt;Neon's caching approach differs from Anthropic models. With competitors, the developer pays a separate price to create the cache. The Cache Write rate ranges from $2.50 to $5.00 per million tokens depending on the Claude version. With Neon, implicit caching &lt;a href="https://www.lindy.ai/blog/gemini-4-neon" rel="noopener noreferrer"&gt;turns on automatically&lt;/a&gt; for prefixes of 4,096 tokens or more. There is absolutely no charge for writing and storing data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo5ayx3swwfw3lohjgbkf.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo5ayx3swwfw3lohjgbkf.webp" alt="A metal coin on a white thread, half lowered into the slot of a white piggy bank." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reading this cache provides a 95 percent discount off the base rate. Processing a million cached tokens &lt;a href="https://ofox.ai/blog/gemini-4-neon-pricing/" rel="noopener noreferrer"&gt;costs just $0.15&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Consider an interactive IDE session with repeated access to the codebase. The script sends the same 10,000 context tokens. They are already in the cache. The input costs $0.0015 instead of $0.030. The program asks for a quick fix in one function. The script programmatically lowers the reasoning level to medium, since complex architectural thought is unnecessary here. The model generates 500 response tokens and 800 reasoning tokens. These 1,300 tokens are multiplied by the $0.000015 rate. The output will cost $0.0195. The repeated call costs $0.021, or 2.1 cents. If the cache had missed, this exact call would have cost significantly more.&lt;/p&gt;

&lt;p&gt;The absence of cache write fees radically changes the economics of long sessions. Independent developers analyzed the logs of the Claude Code plugin. They migrated their workflows from the base model to Neon. The replacement &lt;a href="https://note.com/hacklog_stealth/n/n331f0db2c046?hl=en" rel="noopener noreferrer"&gt;dropped weekly expenses&lt;/a&gt; from $72.67 to $46.54. The net savings reached 36 percent. Billing analysis revealed the reason for this drop. Seventy percent of the saved funds were preserved specifically due to free context storage. When working with Claude, the plugin constantly overwrote the cache as files changed, generating additional costs under the Cache Write rate. Neon simply reads the updated prefix at a discount.&lt;/p&gt;

&lt;p&gt;A developer can load the entire project documentation and source code into a single system prompt. With every new question, the system will read this data array at a discount. The main condition is keeping the initial part of the prompt unchanged. Any modification in the first few thousand tokens will flush the cache, triggering billing at the full $3.00 per million rate. The implicit mechanism works transparently and requires no additional endpoints.&lt;/p&gt;

&lt;h2&gt;
  
  
  Silent breakage of old API configurations
&lt;/h2&gt;

&lt;p&gt;During migration, old API configurations will stop working without throwing errors. The Google Cloud documentation explicitly states that Neon &lt;a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-4-neon" rel="noopener noreferrer"&gt;completely ignores&lt;/a&gt; classic sampling parameters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdk6h46pn0v2jdqpbgi4u.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdk6h46pn0v2jdqpbgi4u.webp" alt="A metal adjustment toggle switch ripped from a panel and lying on a table." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A developer can no longer control generation creativity through familiar parameters. The &lt;code&gt;temperature&lt;/code&gt;, &lt;code&gt;top_p&lt;/code&gt;, and &lt;code&gt;top_k&lt;/code&gt; fields exist in the request schemas, but the API skips them. Attempts to make the code strictly deterministic by setting a zero temperature will yield no results. Developers often use zero temperature to extract structured data. They expect to receive valid JSON without excess reasoning. With Neon, this approach fails. The model ignores creativity settings and relies solely on internal sampling algorithms. Repetition penalties like &lt;code&gt;frequency_penalty&lt;/code&gt; and &lt;code&gt;presence_penalty&lt;/code&gt; are disabled on Google's servers. Explicit cache management has been deprecated. Now only automatic implicit caching is available.&lt;/p&gt;

&lt;p&gt;The only working lever for controlling generation remains the &lt;code&gt;thinking_level&lt;/code&gt; parameter. Four values are available: &lt;code&gt;low&lt;/code&gt;, &lt;code&gt;medium&lt;/code&gt;, &lt;code&gt;high&lt;/code&gt;, and &lt;code&gt;xhigh&lt;/code&gt;. The &lt;code&gt;minimal&lt;/code&gt; mode &lt;a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-4-neon" rel="noopener noreferrer"&gt;is not supported&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This breaks scripts tightly bound to generation determinism. If application logic demands a zero temperature for predictable JSON parsing, Neon will return an unexpected result. On Hacker News, developers &lt;a href="https://news.ycombinator.com/item?id=50552424" rel="noopener noreferrer"&gt;complain&lt;/a&gt; about the inability to run the model under student Google accounts. Users assume a commercial account is required. Neon &lt;a href="https://dev.to/hassann/gemini-4-neon-pricing-3-input-15-output-and-what-a-call-really-costs-5g09"&gt;completely lacks a free tier&lt;/a&gt; in the API and Google AI Studio. The model is available only to users with active paid billing or Google AI Pro and Ultra subscriptions. The vendor does not clarify plans to open free access after the Gemini 4 family promo period ends. The lack of a free tier complicates hypothesis testing for independent researchers. Forum commenters express dissatisfaction with the disappearance of familiar generation control tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation rules: setting parameters and tiers
&lt;/h2&gt;

&lt;p&gt;For standard editing and refactoring tasks, hardcode the reasoning level to &lt;code&gt;medium&lt;/code&gt; or &lt;code&gt;low&lt;/code&gt;. Keep the default &lt;code&gt;high&lt;/code&gt; level only for complex architectural decisions where the model must design logic from scratch.&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;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;genai&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;types&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;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"YOUR_API_KEY"&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;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_content&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;"gemini-4-neon"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;contents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Refactor this database class"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GenerateContentConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;thinking_config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ThinkingConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;thinking_level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"medium"&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="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Group the codebase context into an immutable prefix. To get the 95 percent discount, the size of this prefix must strictly exceed 4,096 tokens. The unified context window holds &lt;a href="https://www.requesty.ai/blog/gemini-neon-pricing-benchmarks" rel="noopener noreferrer"&gt;up to a million tokens&lt;/a&gt; for input. This volume is enough to load several large repositories along with their documentation. A response for a single segment in long decode mode is limited to &lt;a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-4-neon" rel="noopener noreferrer"&gt;65,536 tokens&lt;/a&gt;. This allows generating entire code files without cutting off in the middle of a function. The model's knowledge is limited to &lt;a href="https://www.datastudios.org/post/google-gemini-4-neon-launch-api-pricing-3-input-15-output" rel="noopener noreferrer"&gt;March 2026&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Split tasks by pricing tiers. Move background tests and bulk log analysis to Batch or Flex modes. They provide a 50 percent discount and lower the price to &lt;a href="https://ofox.ai/blog/gemini-4-neon-pricing/" rel="noopener noreferrer"&gt;$1.50 for input and $7.50 for output&lt;/a&gt;. Standard cached input on these tiers costs $0.075 per million tokens. These modes fit well for overnight test runs.&lt;/p&gt;

&lt;p&gt;For critical latency requirements, the vendor mandates using the Priority tier. It includes an 80 percent markup. On this tier, input will cost $5.40, and output will cost $27.00 per million tokens. Cached input costs $0.27. There is no official latency SLA on the Standard tier. Only Priority guarantees minimal response time under peak cluster loads. The specialized secure Neon Cyber version is currently available only to participants of the closed Google Fairwind program, with no exact dates for a public API release. Using aggregators like altrouter.ai allows testing new models alongside the Claude and GPT stack without being tied to Google Cloud billing.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>api</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
