<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged output</title>
<link>https://coderlegion.com/tag/output</link>
<description>Powered by Question2Answer</description>
<item>
<title>AI Email Classifier Cost per 1,000 Messages: Real Math</title>
<link>https://coderlegion.com/25669/ai-email-classifier-cost-per-1-000-messages-real-math</link>
<description>
&lt;p&gt;
        For 1,000 typical text emails, the model API can cost roughly &lt;strong&gt;$0.05 to $1.08&lt;/strong&gt;, or about &lt;strong&gt;PHP 3 to PHP 66&lt;/strong&gt; at a rounded PHP 61.55 per US dollar. That estimate assumes 900 input tokens and 30 output tokens per message, no attachments, no retries, and one classification call per email.
      &lt;/p&gt;

      &lt;div class=&quot;article-callout&quot;&gt;
        &lt;p&gt;&lt;strong&gt;Partner disclosure.&lt;/strong&gt; This guide includes a partner link to &lt;a href=&quot;https://n8n.partnerlinks.io/6mg2xng7s1m6&quot; target=&quot;_blank&quot; rel=&quot;sponsored noopener nofollow&quot;&gt;n8n Cloud&lt;/a&gt;. If you sign up through it, I may earn a commission at no extra cost to you.&lt;/p&gt;
      &lt;/div&gt;
      &lt;p&gt;
        The low token bill is real, but it is not the whole operating cost. Your automation platform, monitoring, human review, and the consequences of a wrong route can cost much more than inference. Prices and exchange rates may change, so keep the formula and replace the rates instead of trusting a static total.
      &lt;/p&gt;

      &lt;div class=&quot;article-callout&quot;&gt;
        &lt;p&gt;&lt;strong&gt;Practical answer:&lt;/strong&gt; budget about &lt;strong&gt;$0.10 to $0.25 per 1,000 ordinary emails&lt;/strong&gt; for a small classification model, then evaluate accuracy on your own inbox. A model that costs five cents but misroutes valuable leads is not the cheaper option.&lt;/p&gt;
      &lt;/div&gt;

      &lt;h2 id=&quot;the-workload-behind-the-estimate&quot;&gt;The workload behind the estimate&lt;/h2&gt;
      &lt;p&gt;
        A useful comparison needs the same input and output size for every model. This article uses a typical business email workload rather than each provider's most flattering example.
      &lt;/p&gt;
      &lt;div class=&quot;article-table-wrap&quot;&gt;
        &lt;table class=&quot;article-table&quot;&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Component per email&lt;/th&gt;
              &lt;th&gt;Assumed tokens&lt;/th&gt;
              &lt;th&gt;What it includes&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Classification instructions&lt;/td&gt;
              &lt;td&gt;250 input&lt;/td&gt;
              &lt;td&gt;Category names, definitions, edge-case rules, and output instructions&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Email content&lt;/td&gt;
              &lt;td&gt;650 input&lt;/td&gt;
              &lt;td&gt;Subject, cleaned body, and a small amount of sender context&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Classification result&lt;/td&gt;
              &lt;td&gt;30 output&lt;/td&gt;
              &lt;td&gt;One label plus compact structured fields such as reason and review flag&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Total for 1,000&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;900,000 input&lt;br&gt;30,000 output&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;No attachment extraction, second model call, retry, or human-written reply&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
      &lt;p&gt;
        Token counts vary by provider and tokenizer. Treat 900 and 30 as planning inputs, then replace them with usage data from the API response or provider dashboard. Long quoted threads, HTML, signatures, disclaimers, and pasted documents can multiply the input without improving the decision.
      &lt;/p&gt;

      &lt;h2 id=&quot;the-cost-formula&quot;&gt;The cost formula&lt;/h2&gt;
      &lt;p&gt;Provider pages normally quote text prices per one million tokens. The calculation is:&lt;/p&gt;
      &lt;pre class=&quot;article-code&quot;&gt;cost = (input_tokens / 1,000,000 &amp;times; input_rate)
     + (output_tokens / 1,000,000 &amp;times; output_rate)

Typical 1,000-email workload:
cost = (900,000 / 1,000,000 &amp;times; input_rate)
     + (30,000 / 1,000,000 &amp;times; output_rate)&lt;/pre&gt;
      &lt;p&gt;
        Example for OpenAI GPT-5.4 nano at the rates checked on July 20, 2026:
      &lt;/p&gt;
      &lt;pre class=&quot;article-code&quot;&gt;input  = 0.9 &amp;times; $0.20 = $0.1800
output = 0.03 &amp;times; $1.25 = $0.0375
total  = $0.2175, rounded to $0.22 per 1,000 emails&lt;/pre&gt;

      &lt;h2 id=&quot;current-model-api-comparison&quot;&gt;Current model API comparison&lt;/h2&gt;
      &lt;p&gt;
        These totals use standard synchronous API pricing, without free tiers, batch discounts, cached-input discounts, regional uplifts, or taxes. The selected models are small or cost-focused options that can plausibly handle classification. Model quality is not equivalent, so the last column is a cost comparison, not a ranking.
      &lt;/p&gt;
      &lt;p&gt;
        &lt;strong&gt;Rate check:&lt;/strong&gt; every provider price in this table was checked against the linked official source on July 20, 2026. The PHP estimates use a BSP rate of PHP 61.548 per US dollar checked on the same date. To update any peso estimate, use &lt;code&gt;PHP estimate = USD total &amp;times; current PHP per USD&lt;/code&gt;. For example, &lt;code&gt;$0.2175 &amp;times; 61.548 = PHP 13.39&lt;/code&gt;.
      &lt;/p&gt;
      &lt;div class=&quot;article-table-wrap&quot;&gt;
        &lt;table class=&quot;article-table&quot;&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Model&lt;/th&gt;
              &lt;th&gt;Input / 1M&lt;/th&gt;
              &lt;th&gt;Output / 1M&lt;/th&gt;
              &lt;th&gt;Typical 1,000 emails&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Groq Llama 3.1 8B Instant&lt;/td&gt;
              &lt;td&gt;$0.05&lt;/td&gt;
              &lt;td&gt;$0.08&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;$0.047&lt;/strong&gt; / about PHP 3&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Google Gemini 2.5 Flash-Lite&lt;/td&gt;
              &lt;td&gt;$0.10&lt;/td&gt;
              &lt;td&gt;$0.40&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;$0.102&lt;/strong&gt; / about PHP 6&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;OpenAI GPT-5.4 nano&lt;/td&gt;
              &lt;td&gt;$0.20&lt;/td&gt;
              &lt;td&gt;$1.25&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;$0.218&lt;/strong&gt; / about PHP 13&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Anthropic Claude Haiku 4.5&lt;/td&gt;
              &lt;td&gt;$1.00&lt;/td&gt;
              &lt;td&gt;$5.00&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;$1.05&lt;/strong&gt; / about PHP 65&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;OpenAI GPT-5.6 Luna&lt;/td&gt;
              &lt;td&gt;$1.00&lt;/td&gt;
              &lt;td&gt;$6.00&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;$1.08&lt;/strong&gt; / about PHP 66&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
      &lt;p&gt;
        OpenAI describes GPT-5.4 nano as suitable for classification and other simple high-volume tasks. Its newer GPT-5.6 guidance points cost-sensitive new workloads toward Luna, but Luna costs more in this narrow token calculation. Test both only if the quality gain matters for your categories. Google calls Gemini 2.5 Flash-Lite its smallest and most cost-effective model for at-scale use. Anthropic's current Haiku tier costs more per token, while Groq's Llama 3.1 8B rate is the lowest in this selected set.
      &lt;/p&gt;

      &lt;h2 id=&quot;email-length-changes-the-bill-but-not-equally&quot;&gt;Email length changes the bill, but not equally&lt;/h2&gt;
      &lt;p&gt;
        Output is tiny for a classifier, so input length usually drives the total. This sensitivity table keeps output compact while changing the amount of text sent to the model.
      &lt;/p&gt;
      &lt;div class=&quot;article-table-wrap&quot;&gt;
        &lt;table class=&quot;article-table&quot;&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;1,000-email workload&lt;/th&gt;
              &lt;th&gt;Input / output&lt;/th&gt;
              &lt;th&gt;Gemini 2.5 Flash-Lite&lt;/th&gt;
              &lt;th&gt;GPT-5.4 nano&lt;/th&gt;
              &lt;th&gt;Claude Haiku 4.5&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Short&lt;/td&gt;
              &lt;td&gt;400k / 25k&lt;/td&gt;
              &lt;td&gt;$0.05&lt;/td&gt;
              &lt;td&gt;$0.11&lt;/td&gt;
              &lt;td&gt;$0.53&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Typical&lt;/td&gt;
              &lt;td&gt;900k / 30k&lt;/td&gt;
              &lt;td&gt;$0.10&lt;/td&gt;
              &lt;td&gt;$0.22&lt;/td&gt;
              &lt;td&gt;$1.05&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Long&lt;/td&gt;
              &lt;td&gt;2M / 40k&lt;/td&gt;
              &lt;td&gt;$0.22&lt;/td&gt;
              &lt;td&gt;$0.45&lt;/td&gt;
              &lt;td&gt;$2.20&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
      &lt;p&gt;
        The long scenario is still inexpensive as a token bill. It is also a warning: paying to resend an entire quoted conversation may expose unnecessary customer data and make the classification noisier. Clean the message before the model call.
      &lt;/p&gt;

      &lt;h2 id=&quot;what-the-token-estimate-leaves-out&quot;&gt;What the token estimate leaves out&lt;/h2&gt;
      &lt;h3&gt;Automation platform cost&lt;/h3&gt;
      &lt;p&gt;
        n8n Cloud is priced by workflow executions, not by node or step. If one incoming email starts one production workflow, 1,000 emails normally consume 1,000 executions. The model API remains a separate provider charge when you connect your own credential. If you already have unused execution capacity, the incremental platform cost may be zero. If the classifier forces a plan upgrade, the subscription difference can dwarf a 22-cent model bill.
      &lt;/p&gt;
      &lt;p&gt;
        One n8n execution can contain several items, but the Text Classifier documentation says each item is passed to the model. Grouping emails into one scheduled execution can reduce execution usage, while the token charge still follows the number and size of classified items.
      &lt;/p&gt;

      &lt;h3&gt;Retries and output repair&lt;/h3&gt;
      &lt;p&gt;
        A failed request, provider retry, or second-pass validation adds another call. n8n's Text Classifier has an &lt;strong&gt;Enable Auto-Fixing&lt;/strong&gt; option that sends a schema parsing error back to the model and asks it to repair the output. That is useful, but it means the estimate above is no longer one call per email when repair is triggered. Measure the repair rate before assuming it is free.
      &lt;/p&gt;

      &lt;h3&gt;Human review and mistakes&lt;/h3&gt;
      &lt;p&gt;
        Suppose a reviewer spends 30 seconds on 10% of 1,000 emails. That is 50 minutes of work. Even at a modest internal hourly rate, review costs far more than the API tokens. The review may still be a good investment if it catches invoices routed to sales, urgent complaints marked as routine, or valuable leads sent to the wrong queue.
      &lt;/p&gt;
      &lt;p&gt;
        The correct metric is not only cost per 1,000 messages. Track &lt;strong&gt;cost per correctly classified message&lt;/strong&gt;, manual-review rate, false-negative rate for urgent categories, and the operational cost of each error.
      &lt;/p&gt;

      &lt;h2 id=&quot;a-simple-n8n-cost-measurement-workflow&quot;&gt;A simple n8n cost-measurement workflow&lt;/h2&gt;
      &lt;p&gt;
        n8n already has a Text Classifier root node. It accepts an input prompt, category names and descriptions, optional multiple classes, an Other branch for unclear matches, a custom system prompt, and optional auto-fixing. For cost measurement, keep the workflow smaller than a full email router:
      &lt;/p&gt;
      &lt;pre class=&quot;article-code&quot;&gt;Email trigger or scheduled inbox fetch
  &amp;rarr; Edit Fields: subject + cleaned body + minimal sender context
  &amp;rarr; Text Classifier: named categories and descriptions
     &amp;#8627; connected small chat model
  &amp;rarr; Log: provider, model, input tokens, output tokens, category
  &amp;rarr; Route Other and selected high-risk categories to review&lt;/pre&gt;
      &lt;p&gt;
        The separate &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/n8n-ai-email-routing-philippines&quot;&gt;AI email routing guide&lt;/a&gt; covers the downstream workflow. This article stays focused on cost measurement and model choice.
      &lt;/p&gt;

      &lt;h3&gt;Use categories that are testable&lt;/h3&gt;
      &lt;p&gt;
        Define categories by the action they trigger. For example: &lt;code&gt;sales_lead&lt;/code&gt;, &lt;code&gt;support&lt;/code&gt;, &lt;code&gt;billing&lt;/code&gt;, &lt;code&gt;urgent_complaint&lt;/code&gt;, and &lt;code&gt;other_review&lt;/code&gt;. Give each category a short description and two or three edge rules. Do not ask the model for a paragraph when one label and a compact reason are enough.
      &lt;/p&gt;
      &lt;p&gt;
        Keep &lt;strong&gt;Allow Multiple Classes To Be True&lt;/strong&gt; off when the business requires one owner. Use the documented Other branch instead of discarding an unclear item. Discarding may look efficient, but it can hide the messages most in need of review.
      &lt;/p&gt;

      &lt;h3&gt;Log actual usage&lt;/h3&gt;
      &lt;p&gt;
        Provider response fields differ, so inspect the output from your selected n8n chat-model node or the provider dashboard. Record input tokens, output tokens, model ID, retry count, latency, chosen category, and the reviewer's corrected category. Recalculate weekly:
      &lt;/p&gt;
      &lt;pre class=&quot;article-code&quot;&gt;observed cost per 1,000 =
  total provider cost / classified messages &amp;times; 1,000

cost per correct classification =
  (provider + platform allocation + review labor) / correct decisions&lt;/pre&gt;

      &lt;h2 id=&quot;reduce-cost-without-weakening-the-classifier&quot;&gt;Reduce cost without weakening the classifier&lt;/h2&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;strong&gt;Use deterministic rules first.&lt;/strong&gt; Known senders, exact aliases, and clear invoice mailbox rules do not need an LLM.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Remove quoted history.&lt;/strong&gt; Classify the newest message plus only the minimum thread context required for meaning.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Strip HTML and signatures.&lt;/strong&gt; Boilerplate consumes input and can introduce misleading terms.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Return a compact schema.&lt;/strong&gt; A label, short reason, and review flag are enough for routing.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Do not add search or tools.&lt;/strong&gt; An inbox classifier should not browse the web or call unrelated tools.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Measure auto-fixes and retries.&lt;/strong&gt; A low base price can double if malformed output repeatedly triggers a second call.&lt;/li&gt;
        &lt;li&gt;&lt;strong&gt;Test a small model first.&lt;/strong&gt; Upgrade only when a measured accuracy gap is worth the higher rate.&lt;/li&gt;
      &lt;/ul&gt;

      &lt;h2 id=&quot;choose-the-model-by-evaluation-not-the-price-table&quot;&gt;Choose the model by evaluation, not the price table&lt;/h2&gt;
      &lt;p&gt;
        Start with at least 100 to 200 representative emails that a person has already labeled. Include short replies, forwarded threads, vague subjects, multilingual messages, promotions, complaints, and categories that are easy to confuse. This is an operational starting point, not a universal statistical guarantee.
      &lt;/p&gt;
      &lt;div class=&quot;article-table-wrap&quot;&gt;
        &lt;table class=&quot;article-table&quot;&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Test&lt;/th&gt;
              &lt;th&gt;What to measure&lt;/th&gt;
              &lt;th&gt;Decision&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;Overall accuracy&lt;/td&gt;
              &lt;td&gt;Correct labels divided by all tested messages&lt;/td&gt;
              &lt;td&gt;Useful for orientation, not enough for rare urgent classes&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Per-category recall&lt;/td&gt;
              &lt;td&gt;How many real messages in a category the model found&lt;/td&gt;
              &lt;td&gt;Prioritize billing, complaints, security, and other costly misses&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Other or review rate&lt;/td&gt;
              &lt;td&gt;Share of messages that need a person&lt;/td&gt;
              &lt;td&gt;Convert the review share into minutes and labor cost&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;Correction stability&lt;/td&gt;
              &lt;td&gt;Whether prompt or model changes improve the same held-out set&lt;/td&gt;
              &lt;td&gt;Use a versioned test set before changing production&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
      &lt;p&gt;
        If two models are close, choose the simpler operational fit: supported credential, stable model ID, acceptable latency, data-processing requirements, and clear usage reporting. A few extra cents per 1,000 emails can be a sensible trade for fewer manual reviews.
      &lt;/p&gt;

      &lt;h2 id=&quot;questions-small-teams-usually-ask&quot;&gt;Questions small teams usually ask&lt;/h2&gt;
      &lt;h3&gt;Can the classifier really cost less than one dollar?&lt;/h3&gt;
      &lt;p&gt;
        Yes. A classification output is short, and small models have low token rates. The estimate stops being valid when you send long histories, extract attachments, ask for generated replies, use a larger model, or trigger repair and retry calls.
      &lt;/p&gt;
      &lt;h3&gt;Does n8n include the model tokens?&lt;/h3&gt;
      &lt;p&gt;
        Do not confuse n8n's AI Assistant credits with the third-party model used inside your production workflow. With your own OpenAI, Gemini, Anthropic, or Groq credential, the model provider meters the API usage. n8n Cloud separately counts workflow executions according to its current plan rules.
      &lt;/p&gt;
      &lt;h3&gt;Should I use the cheapest model?&lt;/h3&gt;
      &lt;p&gt;
        Use the cheapest model that passes your labeled evaluation and operational requirements. Price alone cannot tell you whether a model understands your category boundary, language mix, or unusual messages.
      &lt;/p&gt;
      &lt;h3&gt;Should low-cost classifications send automatic replies?&lt;/h3&gt;
      &lt;p&gt;
        Classification and outbound sending are separate risk decisions. Route first. If AI also drafts a customer-facing response, use a &lt;a rel=&quot;nofollow&quot; href=&quot;https://floxolab.com/blog/human-approval-ai-email-workflow&quot;&gt;duplicate-safe human approval gate&lt;/a&gt; until measured evidence supports narrower exceptions.
      &lt;/p&gt;

      &lt;h2 id=&quot;sources-checked&quot;&gt;Sources checked&lt;/h2&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;https://developers.openai.com/api/docs/models/gpt-5.4-nano&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;OpenAI GPT-5.4 nano model purpose, features, and token pricing&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://developers.openai.com/api/docs/models/gpt-5.6-luna&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;OpenAI GPT-5.6 Luna model purpose and token pricing&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://ai.google.dev/gemini-api/docs/pricing&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Google Gemini API pricing for Gemini 2.5 Flash-Lite&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://platform.claude.com/docs/en/about-claude/pricing&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Anthropic Claude Platform pricing for Claude Haiku 4.5&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://groq.com/pricing&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Groq on-demand token pricing for Llama 3.1 8B Instant&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-classifier/&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;n8n Text Classifier parameters, Other branch, and auto-fixing behavior&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://n8n.io/pricing/&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;n8n Cloud execution-based pricing and current plan rules&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;https://www.bsp.gov.ph/statistics/external/day99_data.aspx&quot; target=&quot;_blank&quot; rel=&quot;noopener nofollow&quot;&gt;Bangko Sentral ng Pilipinas daily peso per US dollar data&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;

      &lt;div class=&quot;article-referral-card&quot;&gt;
        &lt;div&gt;
          &lt;p class=&quot;article-referral-kicker mono&quot;&gt;n8n Cloud for small teams&lt;/p&gt;
          &lt;p class=&quot;cta-h&quot;&gt;Measure the classifier before you scale it&lt;/p&gt;
          &lt;p&gt;n8n Cloud is the simplest starting point if you want to connect an inbox, test categories, and log real usage without maintaining a server. Affiliate disclosure: I may earn a commission if you sign up through this link, at no extra cost to you.&lt;/p&gt;
        &lt;/div&gt;
        &amp;lt;a href=&quot;&lt;a href=&quot;https://n8n.partnerlinks.io/6mg2xng7s1m6&quot; rel=&quot;nofollow&quot;&gt;https://n8n.partnerlinks.io/6mg2xng7s1m6&lt;/a&gt;&quot; target=&quot;_blank&quot; rel=&quot;sponsored noopener&quot; class=&quot;btn b&lt;/div&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/25669/ai-email-classifier-cost-per-1-000-messages-real-math</guid>
<pubDate>Thu, 08 Oct 2026 15:50:00 +0000</pubDate>
</item>
<item>
<title>Understanding Backpropagation: Calculating Gradients for Hidden Layer Weights and Biases</title>
<link>https://coderlegion.com/21631/understanding-backpropagation-calculating-gradients-for-hidden-layer-weights-biases</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star git-lrc on GitHub&lt;/a&gt; to help more developers discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In the previous article, we derived formulas for updating the output layer weights w3, w4, and bias b3. Now, we will understand how to calculate the gradients for the hidden layer parameters: w1, b1, w2, and b2.&lt;/p&gt;

&lt;h2&gt;
  
  
  How are w1, b1, w2, and b2 connected to the prediction?
&lt;/h2&gt;

&lt;p&gt;To find the gradients of the parameters in the hidden layer, we need to trace how changing these values affects the final prediction and the error (SSR).&lt;/p&gt;

&lt;p&gt;Let's recall the structure of our neural network:&lt;/p&gt;

&lt;p&gt;For the top neuron:&lt;/p&gt;

&lt;p&gt;x1 = input * w1 + b1&lt;/p&gt;

&lt;p&gt;y1 = f(x1) = log(1 + e^x1) &lt;em&gt;(using the softplus function)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For the bottom neuron:&lt;/p&gt;

&lt;p&gt;x2 = input * w2 + b2&lt;/p&gt;

&lt;p&gt;y2 = f(x2) = log(1 + e^x2) &lt;em&gt;(using the softplus function)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Finally, the prediction:&lt;/p&gt;

&lt;p&gt;Predicted = y1 * w3 + y2 * w4 + b3&lt;/p&gt;

&lt;p&gt;And the prediction error:&lt;/p&gt;

&lt;p&gt;SSR = &amp;Sigma; (observed &amp;minus; predicted)&amp;sup2;&lt;/p&gt;

&lt;p&gt;Since w1, b1, w2, and b2 are not directly connected to the output prediction, we must use the chain rule to backpropagate the error from the output layer back to the hidden layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying the Chain Rule to the Hidden Layer
&lt;/h2&gt;

&lt;p&gt;Let's calculate the gradient for the top neuron's weight w1 first.&lt;/p&gt;

&lt;p&gt;A change in w1 affects x1, which affects the output y1, which affects the predicted value, which finally affects the SSR.&lt;/p&gt;

&lt;p&gt;So, by the chain rule:&lt;/p&gt;

&lt;p&gt;dSSR/dw1 = dSSR/d(predicted) * d(predicted)/dy1 * dy1/dx1 * dx1/dw1&lt;/p&gt;

&lt;p&gt;Let's calculate each of these values:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. dSSR/d(predicted)
&lt;/h3&gt;

&lt;p&gt;As we saw in the previous articles, this is the derivative of SSR with respect to the predicted value:&lt;/p&gt;

&lt;p&gt;dSSR/d(predicted) = -2 * (Observed - Predicted)&lt;/p&gt;

&lt;h3&gt;
  
  
  2. d(predicted)/dy1
&lt;/h3&gt;

&lt;p&gt;Since Predicted = y1 * w3 + y2 * w4 + b3, and all other terms are treated as constants w.r.t y1:&lt;/p&gt;

&lt;p&gt;d(predicted)/dy1 = w3&lt;/p&gt;

&lt;h3&gt;
  
  
  3. dy1/dx1
&lt;/h3&gt;

&lt;p&gt;Since y1 = log(1 + e^x1), the derivative of the softplus function is the logistic sigmoid function:&lt;/p&gt;

&lt;p&gt;dy1/dx1 = e^x1 / (1 + e^x1)&lt;/p&gt;

&lt;h3&gt;
  
  
  4. dx1/dw1
&lt;/h3&gt;

&lt;p&gt;Since x1 = input * w1 + b1, differentiating w.r.t w1 gives:&lt;/p&gt;

&lt;p&gt;dx1/dw1 = input&lt;/p&gt;

&lt;h3&gt;
  
  
  Final formula for dSSR/dw1:
&lt;/h3&gt;

&lt;p&gt;Multiplying these parts together, we get:&lt;/p&gt;

&lt;p&gt;dSSR/dw1 = -2 * (Observed - Predicted) * w3 * (e^x1 / (1 + e^x1)) * input&lt;/p&gt;

&lt;h2&gt;
  
  
  Deriving the Gradient for Bias b1
&lt;/h2&gt;

&lt;p&gt;Similarly, for the top neuron's bias b1:&lt;/p&gt;

&lt;p&gt;dSSR/db1 = dSSR/d(predicted) * d(predicted)/dy1 * dy1/dx1 * dx1/db1&lt;/p&gt;

&lt;p&gt;The only term that changes here is the last one:&lt;/p&gt;

&lt;p&gt;dx1/db1 = 1 (since x1 = input * w1 + b1, derivative w.r.t b1 is 1)&lt;/p&gt;

&lt;p&gt;So:&lt;/p&gt;

&lt;p&gt;dSSR/db1 = -2 * (Observed - Predicted) * w3 * (e^x1 / (1 + e^x1)) * 1&lt;/p&gt;

&lt;h2&gt;
  
  
  Deriving the Gradients for the Bottom Neuron (w2 and b2)
&lt;/h2&gt;

&lt;p&gt;Following the same logic, we can find the gradients for the bottom neuron's parameters:&lt;/p&gt;

&lt;h3&gt;
  
  
  For weight w2:
&lt;/h3&gt;

&lt;p&gt;dSSR/dw2 = dSSR/d(predicted) * d(predicted)/dy2 * dy2/dx2 * dx2/dw2&lt;/p&gt;

&lt;p&gt;dSSR/dw2 = -2 * (Observed - Predicted) * w4 * (e^x2 / (1 + e^x2)) * input&lt;/p&gt;

&lt;h3&gt;
  
  
  For bias b2:
&lt;/h3&gt;

&lt;p&gt;dSSR/db2 = dSSR/d(predicted) * d(predicted)/dy2 * dy2/dx2 * dx2/db2&lt;/p&gt;

&lt;p&gt;dSSR/db2 = -2 * (Observed - Predicted) * w4 * (e^x2 / (1 + e^x2)) * 1&lt;/p&gt;

&lt;h2&gt;
  
  
  Improving Prediction with self Learning
&lt;/h2&gt;

&lt;p&gt;Once we calculate all these derivatives (dSSR/dw1, dSSR/db1, dSSR/dw2, dSSR/db2), we can update the hidden layer weights and biases using gradient descent:&lt;/p&gt;

&lt;p&gt;Step size w1 = derivation w1 * Learning rate&lt;br&gt;
New w1 = old w1 - Step size w1&lt;/p&gt;

&lt;p&gt;Step size b1 = derivation b1 * Learning rate&lt;br&gt;
New b1 = old b1 - Step size b1&lt;/p&gt;

&lt;p&gt;Step size w2 = derivation w2 * Learning rate&lt;br&gt;
New w2 = old w2 - Step size w2&lt;/p&gt;

&lt;p&gt;Step size b2 = derivation b2 * Learning rate&lt;br&gt;
New b2 = old b2 - Step size b2&lt;/p&gt;

&lt;p&gt;By doing this repeatedly, the model minimizes the error and converges to the optimal values for all weights and biases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We have successfully derived the formulas to calculate the gradients for w1, b1, w2, and b2. Combined with the output layer derivations, we now have the math for the entire neural network's backpropagation!&lt;/p&gt;

&lt;p&gt;In the next article, we will see how to implement this in code.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnuphqwcp6bha9ol6pdo3.png&quot; alt=&quot;git-lrc&quot; width=&quot;360&quot; height=&quot;540&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use.&lt;/p&gt;

&lt;p&gt;&amp;#11088; &lt;a href=&quot;https://github.com/HexmosTech/git-lrc?utm_source=chatgpt.com&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star git-lrc on GitHub&lt;/a&gt;&lt;/p&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/21631/understanding-backpropagation-calculating-gradients-for-hidden-layer-weights-biases</guid>
<pubDate>Tue, 30 Jun 2026 20:23:01 +0000</pubDate>
</item>
</channel>
</rss>