fix(usage): read DeepSeek's native prompt_cache_hit_tokens cache field - #65678
Merged
Conversation
DeepSeek's own API (api.deepseek.com) reports context-cache hits as top-level usage.prompt_cache_hit_tokens / prompt_cache_miss_tokens (prompt_tokens = hit + miss), not the OpenAI nested prompt_tokens_details.cached_tokens shape. Neither normalize_usage() nor the chat_completions transport's extract_cache_stats() read those fields, so direct DeepSeek sessions always showed 0 cache-hit tokens: invisible in accounting, mis-billed at the full input rate, and 0% cache display. Both layers now fall back to prompt_cache_hit_tokens when the nested shape is absent; the nested value wins when both are present (proxies). Fixes #61871.
tonydwb
reviewed
Jul 16, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
Overview
- Usage fix: read DeepSeek's native
prompt_cache_hit_tokenscache field - 82 additions, 5 deletions
Assessment
- Targeted fix to read a specific DeepSeek cache field
- No obvious security concerns
- Clean diff
Reviewed by Hermes Agent
Closed
23 tasks
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
NousResearch#65678) DeepSeek's own API (api.deepseek.com) reports context-cache hits as top-level usage.prompt_cache_hit_tokens / prompt_cache_miss_tokens (prompt_tokens = hit + miss), not the OpenAI nested prompt_tokens_details.cached_tokens shape. Neither normalize_usage() nor the chat_completions transport's extract_cache_stats() read those fields, so direct DeepSeek sessions always showed 0 cache-hit tokens: invisible in accounting, mis-billed at the full input rate, and 0% cache display. Both layers now fall back to prompt_cache_hit_tokens when the nested shape is absent; the nested value wins when both are present (proxies). Fixes NousResearch#61871.
mehmetkr-31
added a commit
to mehmetkr-31/hermes-agent
that referenced
this pull request
Jul 31, 2026
…sage (NousResearch#65722) Kimi/Moonshot's native API (api.moonshot.cn / .ai) reports context-cache hits as a top-level ``usage.cached_tokens``. The chat-completions branch of normalize_usage() walks a fallback chain of prompt_tokens_details.cached_tokens -> cache_read_input_tokens -> prompt_cache_hit_tokens; none of those names match, so direct Kimi sessions normalized to cache_read_tokens=0. The hits were invisible in accounting and the cached prefix was billed at the full input rate. Appended as the last link in that chain, so it only fills a genuine zero and cannot override a provider that reports the nested OpenAI shape or DeepSeek's prompt_cache_hit_tokens. Rebuilt on current main rather than rebased — the branch was ~3400 commits behind. The DeepSeek half of the original branch is dropped: 03c0b00 (NousResearch#65678) landed prompt_cache_hit_tokens on main, so this is Kimi-only as the review asked. The scripts/release.py addition to the frozen LEGACY_AUTHOR_MAP is dropped too; contributors/emails/mehmet.kar@std.yildiz.edu.tr already exists on main. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
NousResearch#65678) DeepSeek's own API (api.deepseek.com) reports context-cache hits as top-level usage.prompt_cache_hit_tokens / prompt_cache_miss_tokens (prompt_tokens = hit + miss), not the OpenAI nested prompt_tokens_details.cached_tokens shape. Neither normalize_usage() nor the chat_completions transport's extract_cache_stats() read those fields, so direct DeepSeek sessions always showed 0 cache-hit tokens: invisible in accounting, mis-billed at the full input rate, and 0% cache display. Both layers now fall back to prompt_cache_hit_tokens when the nested shape is absent; the nested value wins when both are present (proxies). Fixes NousResearch#61871.
teknium1
pushed a commit
that referenced
this pull request
Aug 14, 2026
…sage (#65722) Kimi/Moonshot's native API (api.moonshot.cn / .ai) reports context-cache hits as a top-level ``usage.cached_tokens``. The chat-completions branch of normalize_usage() walks a fallback chain of prompt_tokens_details.cached_tokens -> cache_read_input_tokens -> prompt_cache_hit_tokens; none of those names match, so direct Kimi sessions normalized to cache_read_tokens=0. The hits were invisible in accounting and the cached prefix was billed at the full input rate. Appended as the last link in that chain, so it only fills a genuine zero and cannot override a provider that reports the nested OpenAI shape or DeepSeek's prompt_cache_hit_tokens. Rebuilt on current main rather than rebased — the branch was ~3400 commits behind. The DeepSeek half of the original branch is dropped: 03c0b00 (#65678) landed prompt_cache_hit_tokens on main, so this is Kimi-only as the review asked. The scripts/release.py addition to the frozen LEGACY_AUTHOR_MAP is dropped too; contributors/emails/mehmet.kar@std.yildiz.edu.tr already exists on main. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Summary
Direct DeepSeek API sessions now recognize cache hits:
normalize_usage()and the chat-completions transport both read DeepSeek's native top-levelusage.prompt_cache_hit_tokensfield. Fixes #61871.Root cause: DeepSeek's own API (
api.deepseek.com) reports context-cache hits as top-levelprompt_cache_hit_tokens/prompt_cache_miss_tokens(prompt_tokens = hit + miss), not OpenAI's nestedprompt_tokens_details.cached_tokens. No code path read those fields (repo-wide grep: zero matches), so direct DeepSeek sessions always showed 0 cache-hit tokens — invisible in accounting, 0% in the cache display, and billed at the full input rate instead of the 50x-cheaper cache-read rate.Changes
agent/usage_pricing.pynormalize_usage(): chat-completions branch falls back toprompt_cache_hit_tokenswhen the nested shape is absent; input tokens correctly derive as the cache-miss bucket.agent/transports/chat_completions.pyextract_cache_stats(): same fallback for the live 💾 cache display.Validation
estimatedat 2026-07 ratesInfographic