Repository navigation
fix(ai): Match dotted and dashed model versions so cache tokens get priced - #6808
sentry-junior[bot] wants to merge 2 commits into
Conversation
Model ids spell the same version as 5.5 or 5-5, so a dotted id missed a dashed cost key and the reverse. Look up the other spelling after an exact miss, for exact and glob keys, without adding keys to the metadata map. Refs CW-1897
|
Would it simplify the code to lookup the version as part of |
|
@jjbayer Only if we also normalize the keys. Price feeds spell keys both ways (some With both sides canonicalized, it would look like this:
What we give up: two keys that differ only by separator would collapse into one, and the last one wins. So the "exact spelling wins" test ( via @BYK. |
I'll let @vgrozdanic weigh in as well. |
|
There is also a discussion here: https://sentry.slack.com/archives/C019637C760/p1796336674610849 With the same thoughts that the model name normalization ideally can be improved as that can fix the lookup and it will help in the product/ui. |
|
@Dav1dde Thanks, that matches Joris's suggestion: fix the normalization instead of adding fallbacks to the lookup. Concretely, @vgrozdanic mentioned in Slack that a larger cost-calculation project is planned, so I'll hold off on reworking this PR until he's had a look and says whether this should land now or fold into that project. via @BYK. |
|
@BYK, who asked for this PR, is OK with dropping the "exact spelling wins" rule and normalizing both the model names and the price keys to one spelling, as long as dotted and dashed ids still get priced. @vgrozdanic, should I switch this PR to normalization (keeping the tests for both spellings and for globs), or leave it for your cost-calculation rework? via @BYK. |
Why
LLM apps pay a cache-write premium every time the provider's prompt cache misses. A miss has one of two causes: the cache expired because calls were further apart than the TTL (fixed by cache warming or a longer TTL), or the prompt prefix changed (tools, system prompt, or history), which needs a code fix. Sentry can't show either today. The cost of a miss is only real if cache reads and writes are priced, but some models get no price because providers and price feeds spell the same version two ways (
claude-opus-5.5andclaude-opus-5-5) andModelMetadata::getonly tries the id's own spelling.What
When the exact key misses,
getalso tries the other spelling of the normalized id, swapping each.or-between two single-digit numbers (5.5↔5-5,3-5↔3.5). An exact key in either spelling wins over a glob, and the id's own spelling wins over the other one. The metadata map gets no new keys, and multi-digit numbers such asgpt4-21-04or5-55are left alone. Exact hits cost nothing extra; the alias is aSmallVec<[u8; 64]>, so ids up to 64 bytes don't allocate.Refs CW-1897, getsentry/sentry#133197.
Open decision: should the fix live in normalization instead of the lookup?
normalize_ai_model_namewould turn5-5into5.5, and metadata keys would get the same treatment when loaded. The lookup stays one exact match plus one glob pass and the normalized name can feed the UI, but two keys that differ only by separator collapse into one.Part of
Together these let Sentry show the cache hit rate, alert on drops, price cache tokens correctly, name the cause of each miss, attribute it to a call site, and rank where warming would save money across an org.
via @BYK.
--
View Session [Sentry]