Repository navigation
fix(gateway): DeepSeek cache-hit tokens billing + disjoint input (rant 2026-08-23T08:20:38) - #128
Merged
Merged
Conversation
…t 2026-08-23T08:20:38) P0 cache-billing fix: - StreamUsage: add top-level prompt_cache_hit_tokens (DeepSeek native spelling) - extract_cache_read_tokens priority: DeepSeek -> OpenAI -> Anthropic - record_usage input = prompt_tokens - cached (saturating) at all 6 sites - forward disjoint input_tokens downstream (build_anthropic_usage_json now effective) - tests: 3 spelling tests (deepseek/openai/anthropic) assert (input, cached, output)
4 tasks done
argszero
added a commit
that referenced
this pull request
Aug 23, 2026
…0 / 2026-08-23T08:20:38) (#129) - Cargo.toml/Cargo.lock 0.7.9 -> 0.7.10 - ui/index.html cache-bust 20260822-9 -> 20260823-1 (5 refs) - CHANGELOG: v0.7.10 entry (70MB body limit #127 + P0 cache-billing fix #128) Gates: 145/145 cargo test + fmt + clippy + node --check all green. Co-authored-by: argszero <argszero@argszerodeMac-mini.local>
3 tasks done
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
Fixes the P0 cache-billing bug (rant
2026-08-23T08:20:38): DeepSeek's native top-levelprompt_cache_hit_tokensspelling was silently dropped by serde, so cache hits were billed at the full cache-miss price (~30x overcharge), and input tokens were not disjointed (double-billing risk).Changes
StreamUsage(src/sse.rs): added#[serde(default)] prompt_cache_hit_tokens: u32— DeepSeek's native top-level spelling (prompt_tokens = prompt_cache_hit_tokens + prompt_cache_miss_tokens).extract_cache_read_tokens: now supports all three spellings with priority DeepSeek → OpenAI → Anthropic (prompt_cache_hit_tokens→prompt_tokens_details.cached_tokens→cache_read_input_tokens).record_usagecall sites: input is now disjoint —prompt_tokens.saturating_sub(cached)(or.max(0.0)for the f64 paths) — so cached tokens are never billed twice (miss price + hit price).build_anthropic_usage_json): already disjoints (input_tokens = prompt_tokens - cached - cache_creation) and is now effective sincecachedis actually extracted for DeepSeek.Tests
Added 3 spelling tests, each asserting the
(input, cached, output)triple:deepseek_cache_hit_tokens_spelling—{prompt_tokens:100, prompt_cache_hit_tokens:90, completion_tokens:50}→(10, 90, 50); also verifies downstreaminput_tokens:10+cache_read_input_tokens:90openai_cached_tokens_spelling_disjoint— OpenAIprompt_tokens_details.cached_tokens→(10, 90, 50)anthropic_cache_read_spelling_disjoint— Anthropiccache_read_input_tokens→(10, 90, 50)Related
Rant
2026-08-23T08:20:38— 缓存计费 bug(P0,多收 ~30 倍)Verification
cargo test— 145/145 pass (142 baseline + 3 new)cargo fmt --checkcleancargo clippy --all-targets -- -D warningscleanExplicitly NOT changed (per rant)
cached_tokenscolumn)