Run usage totalTokens double-counts cache read and cache write tokens

Where does the bug appear (feature/product)?

Cursor SDK

Describe the Bug

The usage object on a settled run reports inputTokens that already include cacheReadTokens and cacheWriteTokens, but totalTokens adds those two fields again: totalTokens = inputTokens + outputTokens + cacheReadTokens + cacheWriteTokens. For cache-heavy agent runs this roughly doubles the reported total, so any UI or budget built on totalTokens overstates usage by about 2x.

Steps to Reproduce

I checked 7,002 settled runs recorded from run.wait() usage in my app. In all 7,002, totalTokens equals the sum of all four fields, and inputTokens is at least cacheReadTokens + cacheWriteTokens. On claude-opus-5-5 runs inputTokens equals cacheReadTokens + cacheWriteTokens exactly. Example: inputTokens 1,021,720, cacheReadTokens 850,500, cacheWriteTokens 171,186, outputTokens 13,676, totalTokens 2,057,082 — the real total is 1,035,396.

Expected Behavior

totalTokens should equal inputTokens + outputTokens when inputTokens already includes cached tokens. Alternatively, inputTokens should exclude cached tokens and the docs should state which convention applies.

Version Information

@cursor/sdk 1.0.31, Node v22.22.1, Linux; seen on claude-opus-5-5, grok-4.7, composer-2.5

Hey, @James_M, thanks for the detailed report and for the numbers. That helped a lot.

Yep, that’s correct. In run.wait(), run.usage, and the per-turn usage stream events, inputTokens already includes cacheReadTokens and cacheWriteTokens, and then totalTokens adds them again a second time. On cache-heavy runs, that can make it look almost 2x. I reproduced it and passed it on to the team.

For now, the correct total for those objects is:

  • actual total: inputTokens + outputTokens
  • uncached input: inputTokens - cacheReadTokens - cacheWriteTokens

agent.getUsage() uses a different convention. There, inputTokens excludes cache, so its totalTokens is already correct. It may lag a bit right after the run finishes while billing catches up.

One important note: this only affects how the SDK adds up the numbers in the report. What actually gets charged is calculated separately, and cache is not counted twice there.

I’ll post here when there’s an update.

Same pattern as mine. totalTokens adds cache read and cache write a second time on top of inputTokens, which already includes them. On cache-heavy runs the displayed total is nearly 2x the real one. If the usage meter or the ‘2x’ comparison leans on that field, the headline number is inflated by construction.

Hey, @Vault, yes, this is the same issue. In run.wait(), run.usage, and the stream usage events, the inputTokens field already includes cache tokens, and totalTokens adds them again. We’re tracking this, and the team already has the details.

For now, the real total for these objects is:

  • total: inputTokens + outputTokens
  • uncached input: inputTokens - cacheReadTokens - cacheWriteTokens

agent.getUsage() is not affected by this. There, inputTokens does not include cache, so totalTokens is correct. Billing is also calculated separately, so cache is not counted twice there.

Could you clarify what you mean by “usage meter” and the “‘2x’ comparison”? Is that something in your app built on totalTokens, or a specific screen in Cursor itself? If it’s the latter, let me know which one and I’ll check.

I’ll reply here when there’s an update.

Hey — I get why the column split changed, but bouncing between one-sixty and twenty thousand tokens per request is making my head spin. What I actually need is a dollar figure — it’s just not showing up for me. Can you point me to where that lives, or send it over? Without it, the token math feels pretty academic.

Hey @Vault, that’s fair. If what you need is cost, token counts alone don’t help much.

Dollar amounts for a specific account are handled by our team at [email protected]. They can check your usage details and look into your specific situation directly.

My earlier reply about totalTokens still stands: for run.wait() and run.usage, the real total is inputTokens + outputTokens. I’ll post here when there’s an update on that.

Hey, @James_M, there’s an update. The double counting of cache tokens in totalTokens was fixed in @cursor/sdk 1.1.0, and the same fix is in Python cursor-sdk 1.1.0. The current npm version is 1.2.0.

What changed:

  • In run.wait(), run.usage, and stream usage events, totalTokens is now calculated as inputTokens + outputTokens
  • inputTokens still includes cacheReadTokens and cacheWriteTokens
  • Runs that were saved locally by older SDK versions are recalculated when read through getRun, listRuns, or replayed stream(), so those should also be correct

If you added your own adjustment on top of totalTokens, you should remove it after updating. Otherwise, cache tokens will be subtracted twice and the total will be too low. agent.getUsage() has not changed.

Please update the SDK to the latest version and let us know if totalTokens still looks doubled.

cc @Vault