OverpayingForAIPricing desk

Lesson 3 of 6 · 12 min read · Beginner

Run it a hundred times without a surprise bill

The moment you loop, you can lose money while you sleep. Build the estimate-first habit, set a hard cap, and run a real batch job with both in place.

In this lesson you will

  • Estimate a job's cost before running it
  • Put a hard spend ceiling in place that does not depend on your attention
  • Run a batch and compare actual against estimate

Everything so far cost fractions of a cent, which is why this is the dangerous lesson. One call is unmissably cheap. Ten thousand calls in a loop with a bug is a story people tell at conferences.

Estimate first, run second

The estimate is one multiplication, and doing it takes fifteen seconds. Skipping it is how the conference stories start.

Estimate, cap, then run 100 classifications

Classifying 100 support tickets by urgency. The pattern generalises to any batch.

recorded session — not a live shell0 / 5
  1. wc -l tickets.txt100 items. Know your denominator before anything else.
  2. head -c 400 tickets.txtShort items — roughly 30 input tokens each, and a one-word answer out. Sample your real data; do not guess.
  3. python3 -c " items, tin, tout = 100, 45, 5 rate_in, rate_out = 0.03, 0.13 # qwen3.7-flash, \$ per 1M cost = items*(tin/1e6*rate_in + tout/1e6*rate_out) print(f'estimate: \${cost:.6f} for {items} items') print(f'at 10,000 items: \${cost*100:.4f}') "Two hundred millionths of a dollar. Now you know the loop is safe to run — and you know it before running it, which is the point.
  4. while read -r ticket; do curl -s https://openrouter.ai/api/v1/chat/completions \ -H "Authorization: Bearer $OPENROUTER_API_KEY" -H "Content-Type: application/json" \ -d "$(jq -n --arg t "$ticket" '{model:"qwen/qwen3.7-flash", max_tokens:5, messages:[{role:"user",content:("Reply with exactly one word - urgent, normal or low: " + $t)}]}')" \ | jq -r '.choices[0].message.content' done < tickets.txt | sort | uniq -cThe whole batch, classified and counted. Note max_tokens:5 — a hard ceiling on the expensive half of the bill.
  5. # actual spend, from the provider dashboardEstimated $0.000200, actual $0.000213 — 6% over, because real tickets ran slightly longer than the sample. An estimate within 10% is a good estimate.

Your own numbers will differ — token counts depend on your text, and rates move. The arithmetic is what transfers.

The four-line safety checklist

  1. 1

    Count your items

    Know the denominator before you run anything. wc -l is usually enough.

  2. 2

    Sample the real data

    Take ten actual rows and measure their token length. Guessing is where estimates go wrong.

  3. 3

    Cap the output

    Set max_tokens to slightly more than the longest answer you actually want.

  4. 4

    Test on five, then run

    A five-item run costs nothing and catches the bug that would have run a thousand times.

Knowledge check

Your estimate says $0.02 for 10,000 items. The actual bill is $2.40. What is the most likely cause?

Lesson FAQ

What is a sensible first spend limit?

Five dollars. It is enough to complete this entire course many times over, and low enough that the worst possible bug is an annoyance rather than an incident.

Should I run requests in parallel?

Not while learning. Parallelism multiplies both your speed and your mistakes, and rate limits will bite. Get it correct in a serial loop first.

Finished reading?

Mark it done to track your progress through the course.

Save progress across devices

Get a private link that restores your lessons on any device. Email is optional and only used to send you the link.

Compare, calculate, decide

If our calculators helped you cut down on hidden AI wallet leaks, thanks for using them. A tiny fraction of your savings is what keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.