Skip to content

fix(cost): preserve OpenAI-compatible cache hit usage - #5774

Open
Tanisha-Katara wants to merge 1 commit into
Helicone:mainfrom
Tanisha-Katara:codex/openai-compatible-cache-hit-usage
Open

fix(cost): preserve OpenAI-compatible cache hit usage#5774
Tanisha-Katara wants to merge 1 commit into
Helicone:mainfrom
Tanisha-Katara:codex/openai-compatible-cache-hit-usage

Conversation

@Tanisha-Katara

Copy link
Copy Markdown

Ticket

No existing ticket.

Component/Service

What part of Helicone does this affect?

  • Web (Frontend)
  • Jawn (Backend)
  • Worker (Proxy)
  • Bifrost (Marketing)
  • AI Gateway
  • Packages
  • Infrastructure/Docker
  • Documentation

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Performance improvement
  • Refactoring

Deployment Notes

  • No special deployment steps required
  • Database migrations need to run
  • Environment variable changes required
  • Coordination with other teams needed

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_tokens still wins when present. The new fallback only applies when providers expose DeepSeek-compatible top-level prompt_cache_hit_tokens and prompt_cache_miss_tokens.

I also ran ../node_modules/.bin/tsc --noEmit --project tsconfig.json in packages; 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 --runInBand from packages
  • ../../node_modules/.bin/jest src/lib/shared/bodyProcessors/__tests__/genericBodyProcessor.test.ts src/lib/shared/bodyProcessors/__tests__/openAIStreamProcessor.test.ts --config jest.config.js --runInBand from valhalla/jawn
  • ../../node_modules/.bin/tsc --noEmit --project tsconfig.json from valhalla/jawn
  • ../node_modules/.bin/tsc --noEmit --project tsconfig.json from worker
  • node_modules/.bin/prettier --check ... on touched files
  • git diff --check

@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

@Tanisha-Katara is attempting to deploy a commit to the Helicone Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant