# How to track LLM cost in LangChain > Culpa's LangChain adapter is a callback handler that reports the framework's own token counts. An honest floor, and how to measure what it misses. URL: https://getculpa.com/track-llm-cost-langchain Last reviewed: 2026-08-02 ## Answer Culpa's LangChain adapter is a callback handler you attach to your calls, and it reports the token counts LangChain itself surfaces. That's an honest floor rather than a ceiling, because the adapter sees what the framework reports and not the raw provider response. Culpa, a local-first LLM cost, margin, and forecast ledger, prices what arrives and reconciles it against the invoice so the floor is measurable. ## Why this happens A framework sits between your code and the provider, and it decides what to pass on. Anything it summarises or drops is invisible to anything downstream of it, including a cost adapter. The fields most at risk are the ones that change the price rather than the count, and cached input is the clearest example: if a framework reports prompt tokens as one number, a ledger has no way to know which of them were cached reads at a tenth of the rate. The result is a ledger that's internally consistent and reads above the invoice. ## What this usually looks like - Your captured spend runs above the provider invoice rather than below it. - Your prompts use a large cached prefix and nothing in your ledger shows cached tokens. - The gap is proportional to your cached share rather than a fixed amount. - Per-call token counts look right while per-call cost looks high. ## Common mistakes - Assuming a framework passes through every usage field the provider returned. Why it hurts: The fields that decide price, cached reads especially, are the ones most often collapsed. Do instead: Reconcile against the invoice in the first week and treat any gap as a fidelity measurement. - Reading a ledger that sits above the invoice as an accounting error. Why it hurts: It's usually a capture-fidelity gap, and looking in the accounting will find nothing. Do instead: Compare the shape of the gap against your cached share. A proportional gap names its own cause. - Running only one capture path and trusting it because it's consistent. Why it hurts: Consistency is what a floor looks like from the inside. Do instead: Run the request path or the in-process SDK alongside it for a week and compare the two. ## Self-check - Total your captured spend for a full month and put it beside the provider invoice. - Work out what share of your input is a repeated cached prefix. - Check whether any cached-token figure reaches your ledger at all. - Divide the gap by your cached volume. If it lands near the cached discount, you've found the cause. - Run a second capture path for a week and compare the two ledgers on the same traffic. ## What a collapsed cached-token field does to a ledger (illustrative) A feature on Claude Opus 4.8 at real rates of $5.00 per million input, $25.00 output and $0.50 cached read. It sends 40 million input tokens a month of which 30 million is a cached prefix, plus 6 million output. The cached share is modelled. True cost: (30 x $0.50) + (10 x $5.00) + (6 x $25.00) = $15 + $50 + $150 = $215 If all 40M input is reported as one uncached number: (40 x $5.00) + (6 x $25.00) = $200 + $150 = $350 The ledger reads $350 against a $215 invoice, a 63% over-statement The gap is 30M x ($5.00 - $0.50) = $135, exactly the cached discount not applied Divide the gap by the cached volume and you recover the missing rate: $135 / 30 = $4.50 The count was right and the price was wrong, and the arithmetic points straight at the missing field. A gap that divides cleanly into a rate difference is a fidelity problem, not an accounting one. ## Cost figures Every figure carries its confidence and its source. No figure on this site is provider-reported. - $215 to $350 — modelled monthly cost of one workload, priced with the cached split and priced without it [estimated] Source: Both endpoints from the teardown arithmetic at real Claude Opus 4.8 rates from the price book, effective 2026-07-02. A range because the cached share is modelled. - 63% — modelled over-statement when a cached-token field never reaches the ledger [calculated] Source: $350 divided by $215, from the teardown arithmetic. ## FAQ Q: How accurate is LangChain cost tracking? A: As accurate as what LangChain reports, which is a floor rather than a ceiling. The adapter builds an openai-shaped body from the framework's own token counts, so any usage field the framework collapses is a field no downstream ledger can recover. Q: Will the adapter break my chain if Culpa is unavailable? A: No. Every hook swallows its own failures by design, so a Culpa problem can't propagate into your chain. That's the same fail-open contract the rest of the capture surface follows. Q: How do I get full-fidelity capture instead? A: Capture on the request path by pointing your base URL at Culpa, or use the in-process SDK, which reports the raw provider response. Both see the usage fields the provider actually returned rather than the framework's summary of them. ## Sources - Anthropic pricing: https://platform.claude.com/docs/en/docs/about-claude/pricing Run the free Cost Leak Scan: https://app.getculpa.com/scan?source=pseo&slug=track-llm-cost-langchain&cluster=integration Machine-readable index of every guide: https://getculpa.com/api/pages Human-readable index of every guide: https://getculpa.com/guides Site overview: https://app.getculpa.com/llms.txt Privacy: 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.