fix(cost): tier Anthropic cached-input reads by the long-context threshold - #5765
Open
eeshsaxena wants to merge 2 commits into
Open
fix(cost): tier Anthropic cached-input reads by the long-context threshold#5765eeshsaxena wants to merge 2 commits into
eeshsaxena wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
@eeshsaxena is attempting to deploy a commit to the Helicone Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
getThresholdValueFunctionreturns, per provider, the token count used to pick which pricing tier applies to a given cost field. Theanthropicbranch handlesinputCostandoutputCostbut has nocachedInputCostcase, so that field falls through todefault: return 0. Every other provider that tiers (vertex,xai,google-ai-studio) has acachedInputCostcase.Because the threshold value is always 0 for Anthropic cached reads,
getPricingTieralways returns the base tier for them, even on a request past the long-context threshold.Concretely,
claude-4.5-sonnet:anthropicprices:A cached read is priced as
cachedInput * tier.input * cacheMultipliers.cachedInput. Above 200k prompt tokens the input rate doubles, so the cached-read price should double too (0.1 * 0.000006). Instead it stays at the base tier (0.1 * 0.000003), so cached reads on long-context Anthropic requests are billed at half the intended rate. Input and output already tier correctly, so within one request the cached-read rate is inconsistent with the input rate it is derived from.Fix
Add the
cachedInputCostcase to theanthropicthreshold function, returning the same total-prompt value asinputCost/outputCost. Cached reads now select the same tier as input and output.Tests
packages/__tests__/cost/anthropic-cache-tier.test.tschecks that a >200k request prices cached reads at the tier-1 rate (0.06 for 100k cached tokens, where the base tier would give 0.03), and that a sub-threshold request still uses the base tier.