Skip to content

fix(core): price OpenAI cached input tokens at the cache read rate - #13141

Open
tonycoder-hub wants to merge 1 commit into
continuedev:mainfrom
tonycoder-hub:cursor/fix-openai-cached-token-cost-4b83
Open

fix(core): price OpenAI cached input tokens at the cache read rate#13141
tonycoder-hub wants to merge 1 commit into
continuedev:mainfrom
tonycoder-hub:cursor/fix-openai-cached-token-cost-4b83

Conversation

@tonycoder-hub

Copy link
Copy Markdown

Fixes #13104.

OpenAI cost used the full input rate for cached tokens. Cached tokens are now billed at the cache-read rate for models that support prompt caching (gpt-4o, gpt-4o-mini).

core/llm/utils/calculateRequestCost.vitest.ts: 27 passed.

OpenAI includes cached input in prompt_tokens and bills it at a discount,
but calculateOpenAICost charged every prompt token at the full input rate,
over-costing cache hits.

Adds a cachedInput rate for the models that support prompt caching, prices
the cached portion separately from the remaining input tokens, and shows a
Cache Read line in the breakdown like the Anthropic branch does.

Co-authored-by: Tony Coder <407243179@qq.com>
@tonycoder-hub
tonycoder-hub requested a review from a team as a code owner August 17, 2026 08:56
@tonycoder-hub
tonycoder-hub requested review from sestinj and removed request for a team August 17, 2026 08:56
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@tonycoder-hub
tonycoder-hub force-pushed the cursor/fix-openai-cached-token-cost-4b83 branch from 36b2348 to fa51e12 Compare August 17, 2026 11:14
@tonycoder-hub

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI cost calculation ignores cached input tokens (over-costs cache hits)

1 participant