fix(cost): account for OpenRouter cache write tokens#18445
fix(cost): account for OpenRouter cache write tokens#18445LucasSantana-Dev wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
I'm having a hard time trusting these PRs because if u look at the file paths u edited, it specifically says it is specifically and ONLY for copilot, so what does that have to do with openrouter? That codepath should basically never be hit unless u have a custom provider configured to use the github copilot sdk which I kinda doubt? |
|
It even has a readme saying as much: |
I'll have a second look on that and figure out a more structured and fitting solution for the idea i had! |
Issue for this PR
Closes #18440
Type of change
What does this PR do?
This fixes OpenRouter cost underestimation when cache write tokens are present. OpenAI-compatible responses can report
prompt_tokens_details.cache_write_tokens, but we were not carrying that through for usage accounting.Changes in this PR:
cache_write_tokensin OpenAI-compatible provider paths (stream + non-stream)openrouter.usage.cacheWriteInputTokens)Session.getUsageso cache write tokens are counted in token/cost totalsSession.getUsagetestsHow did you verify your code works?
cd packages/opencode && bun test test/session/compaction.test.tscd packages/opencode && bun run typecheckScreenshots / recordings
Not a UI change.
Checklist