Guides / track llm cost python
How to track LLM cost in Python
Culpa's Python SDK reports the raw request and response to a Culpa server on your own machine, which prices them exactly as it prices a call captured on the request path. Your provider key never travels, because the SDK sends a local fingerprint instead. Culpa, a local-first LLM cost, margin, and forecast ledger, meters every reported call without adding a single token to your bill.
Why this happens
Measuring an AI product usually means one of two trades: route your traffic through something, or send your data somewhere. In-process reporting avoids both. Your application still calls the provider directly, so nothing sits in the request path and nothing changes about latency or failure modes. What travels is a report to a server on your own machine, and the credential that authorised the call is reduced to a fingerprint before it leaves the process. Capture itself makes no model calls, so measuring costs nothing.
What this usually looks like
- A measurement plan stalled because nobody would approve traffic leaving the network.
- Your team wants attribution but the request path is considered untouchable.
- Cost tooling was rejected on the basis that it needs a copy of your API key.
- Nobody can say what the measurement layer itself costs per month.
Free, no card, no account
Run the free Cost Leak Scan
It shows your most expensive conversation before you install anything.
Mistakes that cost the most
| Mistake | Why it hurts | Do instead |
|---|---|---|
| Assuming any cost tool needs your provider key. | It rules out measurement on the basis of a requirement that doesn't apply here. | Check what the tool actually sends. A fingerprint identifies a key without being one. |
| Letting the measurement layer make its own model calls. | You then pay tokens to find out what you're paying in tokens, and the cost scales with traffic. | Prefer capture that reads what already happened over anything that asks a model about it. |
| Wiring capture into a path where a failure blocks the call. | A measurement outage becomes a product outage, which is how measurement gets removed. | Use a reporter that returns a value on failure instead of raising, and confirm that in a test. |
Run this check tonight
- Confirm what leaves your process during capture, field by field.
- Check that your provider key is fingerprinted rather than forwarded.
- Count the model calls your measurement layer makes. It should be none.
- Force a capture failure in staging and confirm the host call still succeeds.
- Compare a call captured in-process against the same call captured on the request path.
What measurement costs, and what a key looks like when it doesn't travel
Illustrative example
A service making 1.5 million calls a month on GPT-5.4 at real rates of $0.0025 per 1k input and $0.015 output, each sending 3,000 input tokens and returning 500. Volumes are modelled.
Measurement adds nothing to the bill it measures, which is the property that lets you capture 100% of traffic rather than sampling it. A sampled ledger can't name your most expensive conversation.
Every number, with its confidence and source
| Figure | What it means | Confidence | Source |
|---|---|---|---|
| $0.00 | provider tokens added by capture itself, at any traffic volume | calculated | The SDK reports an already-completed call and makes no model call of its own, so the token count it adds is zero. |
| $22,500 | modelled monthly provider spend the capture layer measures without adding to | calculated | 1,500,000 calls x $0.015, using real GPT-5.4 rates per 1k from the price book, effective 2026-07-02. Call volume and token counts are modelled. |
What a generic answer can’t know
A provider sees a call arrive with a valid key and has no idea which of your services made it or under what user. Those labels exist for a moment inside your process and nowhere else. Culpa captures them there, on your infrastructure, keeps your prompts and responses there, and counts the calls to run your plan.
Questions founders ask next
Does the Python SDK send my provider API key anywhere?
No. It computes a fingerprint locally, a short hash of the key rather than the key itself, and sends that. The fingerprint matches the format the request path uses, so calls captured either way group under the same credential.
Does capture add cost or latency?
It adds no model calls, so it adds nothing to your provider bill. Your application still calls the provider directly, so the request path is unchanged and the report happens alongside it rather than in front of it.
What happens if Culpa is down when a call is reported?
The reporter returns a failure value rather than raising, so your application carries on. That's a contract rather than a best effort, and it's the reason capture can be enabled everywhere instead of on a sample.
On your infrastructure
Culpa runs on your infrastructure. Your prompts and responses never leave it. Culpa counts calls to run your plan, and it fails open, so if it ever breaks your app keeps running.
How Culpa works
Find the culprit. Not just the total.
Your dashboard shows what you spent. It stops short of who spent it. Culpa shows the conversation, the user and the feature behind it.
Your prompts stay local.
Culpa runs on your own infrastructure. What you send to a model reaches us at no point.
Every dollar has a name.
Follow any charge to the conversation, the user, the feature and the customer behind it.
See the bill before it lands.
Cost your next feature before you ship it. You get the likely bill and the worst case, at best, median, p90 and p99.
Three steps to your first answer.
Change one base URL.
Or drop in the Python or TypeScript library.
Find your most expensive conversation.
In the first session, not the first week.
Cost your next feature before you ship it.
Why the bill went up
Example dashboardCalls traced
418,209
across 3 projects
Spend this week
$378.41
+ $182 vs last week
Failed calls
312
74% retried, and you paid for all of them
+ $182 this week traced to one culprit
Spend over 14 days
Most expensive users
Next week forecast
Graded against reality. Accuracy shown as results land.
Free, no card, no account
Run the free Cost Leak Scan
It shows your most expensive conversation before you install anything.
Keep reading
Sources: OpenAI API pricing. Last reviewed 2026-08-02. Plain text version.