fix(cost): account for OpenRouter cache write tokens#18445
Closed
LucasSantana-Dev wants to merge 1 commit intoanomalyco:devfrom
Closed
fix(cost): account for OpenRouter cache write tokens#18445LucasSantana-Dev wants to merge 1 commit intoanomalyco:devfrom
LucasSantana-Dev wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Collaborator
|
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? |
Collaborator
|
It even has a readme saying as much: |
Author
I'll have a second look on that and figure out a more structured and fitting solution for the idea i had! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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