fix(cost): preserve OpenAI-compatible cache hit usage - #5774
Open
Tanisha-Katara wants to merge 1 commit into
Open
fix(cost): preserve OpenAI-compatible cache hit usage#5774Tanisha-Katara wants to merge 1 commit into
Tanisha-Katara wants to merge 1 commit into
Conversation
|
@Tanisha-Katara is attempting to deploy a commit to the Helicone Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
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.
Ticket
No existing ticket.
Component/Service
What part of Helicone does this affect?
Type of Change
Deployment Notes
Screenshots / Demos
No UI change.
Extra Notes
This keeps the existing precedence rule: nested OpenAI-style
prompt_tokens_details.cached_tokens/input_tokens_details.cached_tokensstill wins when present. The new fallback only applies when providers expose DeepSeek-compatible top-levelprompt_cache_hit_tokensandprompt_cache_miss_tokens.I also ran
../node_modules/.bin/tsc --noEmit --project tsconfig.jsoninpackages; it still fails on existing unrelated test typing issues in__tests__/cost/providers/helicone.test.ts,__tests__/cost/registrySnapshots.test.ts, and__tests__/llm-mapper/getMapperType.test.ts.Context
Some OpenAI-compatible providers and gateways can return DeepSeek-style cache usage as top-level fields. Helicone already has native DeepSeek handling, but the generic OpenAI-compatible usage paths only looked at nested OpenAI cache details. That can record cache hits as ordinary prompt input, or lose cache-read accounting in worker/Jawn fallback paths.
This PR centralizes prompt-cache extraction and reuses it in cost processors, generic body processing, streaming usage, and worker response extraction.
Tests
../node_modules/.bin/jest __tests__/cost/usageProcessor.test.ts --config jest.config.ts --runInBandfrompackages../../node_modules/.bin/jest src/lib/shared/bodyProcessors/__tests__/genericBodyProcessor.test.ts src/lib/shared/bodyProcessors/__tests__/openAIStreamProcessor.test.ts --config jest.config.js --runInBandfromvalhalla/jawn../../node_modules/.bin/tsc --noEmit --project tsconfig.jsonfromvalhalla/jawn../node_modules/.bin/tsc --noEmit --project tsconfig.jsonfromworkernode_modules/.bin/prettier --check ...on touched filesgit diff --check