
Part 1 was the system: the pipeline, the stages, and why Claude only steps in once, for one real judgment call. This part is the money side of that call: what it costs every month, what surprised me in the bill, what I changed, and what I learned along the way, some good and some not.
Same rule as before: every number comes from a table I built to track this, as of August 2026.
How $30 of credit disappeared
This started while I was still building the pipeline. I was curious what running Claude through this would cost, so I added some credits and started testing.
First mix-up: I thought the API and my Claude subscription were the same thing. They’re not. The subscription is a flat monthly plan for using Claude the assistant. The API is billed separately, pay as you go, and that’s what this pipeline runs on.
So I added $20 of API credit to test with. It was gone after a handful of test runs. I added another $10, thinking that would give me more room. It lasted two or three calls. That’s when it stopped being curiosity. Before I let this run unattended every month, I needed to know exactly where the money was going.
The first bill
Stage B (Step 7 in Part 1) is the one step where Claude looks at a stock and forms an opinion, and the only step that spends money. The early version ran on Opus, the strongest and most expensive model, with reasoning effort at “medium” and no limit on how much it could search the web per stock. That came to about $5 for one monthly run, with 4 to 6 stocks getting a review.
On paper, $5 isn’t much. But watching $20 and then $10 vanish in a few calls told a different story. This task shouldn’t be burning money that fast.
Logging every call
So I built a claude_usage table in BigQuery. The idea is simple:
- Every call (Stage B, the notes call, the gold-silver price lookup, all of them) goes through one function before its result is used.
- That function reads
input_tokensandoutput_tokensstraight from the API’s own response. - It prices them with a small hardcoded rate table, checked against Anthropic’s published prices: Opus 5 at $5/$25 per million input/output tokens, Sonnet 5 at $2/$10, Haiku 4.5 at $1/$5. This is just arithmetic on numbers the API already returned. It never calls the API.
- It writes one row per call to
zerodha_pipeline.claude_usage:run_id,call_type, stock symbol, model, input tokens, output tokens, cost and a timestamp. - The cost badge in the email is the sum of that run’s rows.
Everything below is a row I queried from that table, which is also why I could write this from data instead of memory.
Here’s one full run, run_id=2026-08-20, straight from the table:
| Call | Model | Input tokens | Output tokens | Cost |
|---|---|---|---|---|
| IRCTC | Sonnet 5 | 78,981 | 1,998 | $0.178 |
| ITC | Sonnet 5 | 79,968 | 2,861 | $0.189 |
| JYOTIRES | Sonnet 5 | 75,273 | 2,466 | $0.175 |
| KSOLVES | Sonnet 5 | 51,484 | 1,509 | $0.118 |
| PIIND | Sonnet 5 | 44,177 | 1,161 | $0.100 |
| gsr_lookup | Haiku 4.5 | 9,867 | 138 | $0.011 |
| notes | Haiku 4.5 | 410 | 108 | $0.001 |
| Full run, 7 calls | $0.77 |
The 104K-token spike
The prices, from the Claude API pricing page:
| Model | Input ($/M tokens) | Output ($/M tokens) |
|---|---|---|
| Opus 5 | $5 | $25 |
| Sonnet 5 | $2 | $10 |
| Haiku 4.5 | $1 | $5 |
The first surprise: Opus costs only 2.5x Sonnet, not the ~5x I’d assumed before checking. That wrong guess would have made me overvalue “switch to a smaller model” and miss what was really driving the cost.
The real driver was input tokens, and specifically what web search pulled into the context.
The table caught it directly. One Stage B call on PIIND logged 104,529 input tokens. The cause was one website returning the full transcript of an earnings call into the search result. I added that domain (investywise.com) to a blocklist on the search tool. Same stock, about an hour later: 37,217 input tokens, a 64% drop with the same quality of analysis.
It felt like the fix, but it was only one blocklist entry. More on that below.
What I changed
| What | Before | After | Why |
|---|---|---|---|
| Model | claude-opus-5 everywhere |
claude-sonnet-5 for the judgment, claude-haiku-4-5 for one-line notes |
Opus’s depth isn’t needed to write an 8-word note |
| Reasoning effort | "medium" |
"low" |
Stage B’s prompt is already tightly scoped (four fixed questions); lower effort didn’t hurt the verdicts |
| Web searches | no limit | 4 per stock (down from 5), floor of 2 | search volume, not reasoning, was the biggest cost |
| Search results | full content echoed back | response_inclusion: "excluded" |
the pipeline is single-turn and never needs the raw content again |
| Domain blocklist | none | grown from real outliers in claude_usage |
the PIIND 104K → 37K fix above |
What it costs now
Every clean run in the log after the changes cost between $0.55 and $1.24, so roughly 4x to 9x cheaper than about $5 on Opus. The cheapest was the run right after the blocklist fix on 19 August: five Stage B calls for $0.074, $0.104, $0.088, $0.113 and $0.176, which adds up to $0.55. The amount moves from month to month with how much that month’s web searches happen to pull back.
The email’s own footer for the 20 August run (5 stocks evaluated):
This run cost ~$0.76 (~₹66) in Claude API usage
That’s a cent under the $0.77 I get when I add up all 7 rows myself. The email’s running total doesn’t include the separate gold-silver lookup, only Stage B and the notes call. A small gap, but worth being exact about instead of rounding it away.

What the tuning didn’t fix
1. New outliers keep showing up. A blocklist only stops a website after it has already cost money once, so new ones keep slipping through:
- ITC: 155,106 input tokens, $0.35 in one call. The worst call in the whole log, worse than the PIIND spike that started the blocklist.
- PIIND, the same stock as the fix: back up to 90,763 tokens on a later run, then 103,342 on another, from a different source that isn’t blocked yet.
- IRCTC: 127,837 input tokens on the most recent run.
- JYOTIRES: 125,672 input tokens on the most recent run.
So the blocklist is really a queue of sources I haven’t caught yet.
2. A retry doubles the bill. The $0.77 for 20 August is real, but it isn’t the whole day. The same run_id also has a retry logged against it: all 5 stocks reviewed a second time after an earlier partial failure. That pushed the real total for the run to $1.75. The pipeline handles failures by retrying, and that has a price nobody sees unless they look at the log. The email footer only shows one pass.
Two “obvious” savings that made it worse
Not every change moves the number the way you’d expect. These two looked right on paper.
Moving Stage B fully to Haiku. Half of Sonnet’s price, so it should be cheaper. I tested it:
- Haiku doesn’t support the
effortparameter at all. The call fails with a straight400. - Haiku can’t filter search results on the fly the way Sonnet can. It reads a result in full or not at all.
- To make up for that, the search budget had to grow, so it searched more.
- Total tokens went up enough that the run cost noticeably more than on Sonnet, even at the lower rate.
Limiting search to a list of trusted sites. For two thinly covered small-cap stocks, I tried allowing only a few trusted finance sites instead of blocking a few bad ones.
- The thinking: fewer, better sources should mean less searching.
- What happened: cost got clearly worse for at least one of them. The model kept searching inside the short list, didn’t find enough, and tried again.
- The lesson: an open search that finds a good source on the first try beats a narrow one that has to hunt.
Gotcha: if you use the
web_searchtool,moneycontrol.comandeconomictimes.indiatimes.comblock Anthropic’s search crawler, and the API rejects them outright if you put them in eitherallowed_domainsorblocked_domains. I found that one the hard way.
The bug that got through anyway
None of the above stopped a real production bug:
- The small notes call on Haiku still had
output_config={"effort": "low"}left over from an earlier version of the code. Haiku doesn’t support that parameter. - It failed silently, on every run. The pipeline caught the error and carried on, so Stage B and C still worked and an email still went out.
- But every email was missing its portfolio value summary. Nobody noticed, because nothing looked broken. It was just quieter than it should have been.
- I found it by triggering a real production run against that day’s real holdings Sheet and reading the response myself. No unit test caught it.
Lesson: catching errors and carrying on is good practice, but it also lets a real bug hide behind a run that technically succeeded. Trigger the real thing every so often and read what comes back. Don’t just check the HTTP status code.
Knowing when not to call the model
The newest addition at the time was an equity balance check:
- a concentration score (the Herfindahl-Hirschman Index), weight bands, and the 5 most under- and overweight stocks in my equity book,
- all plain Python, zero Claude calls,
- worked out from the same holdings data Stage A already reads, because it’s plain arithmetic.
That taught me more than any single trick above. Using AI well as a data engineer means building the system so the model only sits where real judgment is needed, measuring that one spot properly, and undoing an “obvious” change as soon as the numbers say it made things worse.
Claude didn’t make this pipeline disciplined. The stages, the cost table, and being willing to reverse a decision that looked right on paper all had to exist first. Claude got to be the one piece of judgment none of that could replace.
Where retrieval might go next
The blocklist is a reactive fix. It only stops a source after it has cost money once, because web search’s token cost depends on whatever a website happens to return that day, and that has no upper limit. On top of that, Stage B starts from zero every month. It searches the open web for a stock it may well have reviewed before, with no memory of what it decided last time, or why.
Retrieval-augmented generation (RAG) could fix both at once. It gives Stage B memory, and just as important here, a fixed amount of context:
- Every Stage B verdict already lands in BigQuery with its full reasoning, sources and confidence. That’s a knowledge base sitting there unused.
- Split it into chunks, embed them, put them behind a vector store, and a future Stage B could pull back a fixed number of its own past reasoning chunks: a chosen chunk size and a chosen top-k.
- That replaces an open web search that might return a two-line summary or a full transcript, depending on what some website serves that day.
- The input tokens for that context become a number I decide in advance, not one I find out after the bill arrives.
- The same idea could work for the gold-silver and equity balance checks, pulling in past months’ trend instead of only comparing against the last run.
None of this is built yet, but the pieces are close: BigQuery vector search and Vertex AI Vector Search are both within reach of this stack, and Stage B’s own past output is exactly the kind of grounded, first-party data a RAG system should be built on. When it’s built, it gets its own write-up.
What’s changed since August 2026
This article is a record of the costs as they were in August 2026, when the review ran as the Cloud Function from Part 1. The monthly review now runs locally in Claude Code with a newer set of rules, so these per-run numbers describe that version. The new setup will get its own write-up.
Part 1 covers the system all this sits inside: the goal, the architecture, and why it’s split into stages. Part 3, putting the results on a physical screen, is on hold until there’s real hardware to show.