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.
Classifying 100 support tickets by urgency. The pattern generalises to any batch.
wc -l tickets.txt100 items. Know your denominator before anything else.head -c 400 tickets.txtShort items — roughly 30 input tokens each, and a one-word answer out. Sample your real data; do not guess.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.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.# 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
Count your items
Know the denominator before you run anything.
wc -lis usually enough. - 2
Sample the real data
Take ten actual rows and measure their token length. Guessing is where estimates go wrong.
- 3
Cap the output
Set max_tokens to slightly more than the longest answer you actually want.
- 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?