Repository navigation
fix(usage): preserve DeepSeek prompt cache hits - #5817
ramapitecusment wants to merge 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Thanks for the PR! Just a quick note from live verification: the official DeepSeek API ( That said, adding The fallback precedence and explicit-zero semantics look clean and well-tested. LGTM! |
|
Closing as not planned. After further architectural consideration, we have decided to keep the generic OpenAI-compatible usage parser strictly aligned with the canonical OpenAI specification ( Introducing vendor-specific non-standard fields ( Thank you again for the effort and the well-crafted test suite! |
DeepSeek reports cached prompt tokens in
usage.prompt_cache_hit_tokens. The OpenAI-compatible usage parser currently ignores this field, so a response with 100 input tokens, 80 cache hits and 10 output tokens is recorded as 100 uncached input tokens and zero cache reads. This loses the cache discount information used by downstream cost accounting.Read the DeepSeek field as a fallback after the existing Chat Completions and Responses cache fields. The existing token breakdown then records 20 uncached input + 80 cached input + 10 output = 110 total. Explicit zero in a standard cache field remains authoritative.
The production change is three lines in the shared parser used by normal responses and SSE. It uses existing usage fields and requires no SDK, queue, journal or desktop changes. This covers documented responses with input/output counters; handling incomplete cache-only payloads remains outside this patch.
Validation:
devfor mixed/full cache in both response and streaming modes, then passed with the fallback.[DONE]stream chunks.go test ./internal/runtime/executor/helps ./sdk/cliproxy/usage -count=1passed.go build -o test-output ./cmd/serverpassed (Go 1.26.5, macOS arm64).TestOpenAICompatExecutorToolResultContentByInputModalities; the same failure reproduces on clean upstreambb20fa2d, without this patch.References: DeepSeek usage schema and cache semantics.
Extracted from #5765 so this correction can be reviewed independently of persistent delivery and broader accounting changes. Related to the earlier #3802 proposal; this patch only maps the documented counter into the existing schema and does not add new cache-hit/cache-miss SDK fields.