Build1 publisher3 min readPublished
Counting only successful agent calls hid 48% of the bill in spendgraph's worked example
Spendgraph's worked example has a dashboard showing $0.034 for an agent job the provider billed at $0.066, because two failed attempts were never recorded. The figures are illustrative, but any retry below the cost-recording layer makes agent spend look lower than it is.
The Engineer · Build desk

What happened
- In spendgraph's worked example, an agent job's extract and review steps each failed once before succeeding, and the provider billed all four calls for $0.066.
- A tracker that keeps only the answers it used records $0.034, leaving $0.032, or about 48% of the spend, off the dashboard.
- Spendgraph's stage library places the retry around the whole recorded call, so every attempt is written down as its own priced record.
- The library retries a reply that came back in the wrong shape but stops after one failure when the prompt never rendered the question.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
- cost Unit economics built from success-only logs understate spend every time; in the example, the provider's bill was 1.94 times what the dashboard showed.
- decision Teams whose retry loop sits inside the recorded call, the cheaper design to build, have to move it outward or meter below it before trusting per-job cost.
- constraint Because the 48% comes from a constructed job, a team has to measure its own per-step failure rate and failed-attempt cost before quoting any hidden share.
The gap comes from where the retry loop sits. The example is from a post on dev.to introducing spendgraph's cost-metering packages, so the figures and design claims are the vendor's own [18]. Put the retry inside the recorded call and the model can fail, then succeed, within a single record. For the extract step, that leaves one row at $0.006 [5]. Put the retry around the recorded call and each attempt gets its own row: two rows, $0.011 [5]. The post concedes the inner version is smaller and cheaper to build, and says it gets the accounting wrong [6].
Most tracking, according to the post, keeps only the call whose answer ended up being used [2]. It states the general rule this way: any retry that happens below the cost-recording layer is "a retry you pay for twice and see once" [7]. The resulting error has a fixed sign. Tracked spend comes out lower than the bill [15].
The 48% needs a narrower reading. The post calls its numbers illustrative [8]. Two of the four billed calls failed, one on each step [17]. Each failed attempt cost $0.001 less than the retry that worked [14]. With half the attempts failing at nearly full price, a hidden share near half follows from the setup [17][3]. Steps that usually pass on the first try would hide much less, and a reviewer that rejects twice in a row would hide more. For the figure to transfer, a team's steps would need to fail about as often as the example's. A failed attempt would also need to cost about what a good one does.
The storage choice is sound. Every cost is kept as an integer count of micro-dollars, where one unit is $0.000001 [10]. The post's case is that floats drift after a few thousand additions of a tenth of a cent, while integers give the same monthly total however they were summed [10].
The pricing path is the part I would copy. The price arrives as a promise, and the answer does not wait for it, because in the post's words a billing lookup "has no business on the path of a user waiting for a reply" [11]. The promise can resolve to undefined when no price is found, since an unknown price is not a zero one [11]. A zero in a cost table gets summed without complaint. An undefined forces whoever builds the report to decide what a missing price means.
Teams that want metering without adopting stages get a one-line wrapper around an existing OpenAI client. It reads usage off each reply and reports it in the background. The post says the meter never throws into application code [12]. A retry issued by application code calls the wrapped client again, so each such attempt passes through the meter.
The post's closing advice is to count every attempt and check which steps fail most. "The prompt that fails half the time is usually a cheaper fix than a cheaper model," it says [13].
What to watch
- Measured per-step failure rates from production pipelines, published by spendgraph or its users, would replace the illustrative 48% with a real hidden-spend share.
- Whether spendgraph's one-line OpenAI wrapper records retries made inside the client library, the layer its own rule says a tracker cannot see.