fix: bound uncached remainder by prompt-max(cached,write) and forward compact prompt_cache_key

This commit is contained in:
CaIon
2026-07-11 22:18:26 +08:00
parent 48068ce923
commit 92d3c9d18f
9 changed files with 34 additions and 18 deletions
+9 -4
View File
@@ -270,12 +270,17 @@ type InputTokenDetails struct {
// which field the upstream reported it in: Claude-derived conversions populate
// CachedCreationTokens while OpenAI reports cache_write_tokens natively. Both
// are billed at the cache-creation price; when both are present the larger
// value wins so the same tokens are never double-counted.
// value wins so the same tokens are never double-counted. Negative upstream
// values are clamped to zero so they can never lower a charge.
func (d InputTokenDetails) CacheCreationTokensTotal() int {
if d.CacheWriteTokens > d.CachedCreationTokens {
return d.CacheWriteTokens
total := d.CachedCreationTokens
if d.CacheWriteTokens > total {
total = d.CacheWriteTokens
}
return d.CachedCreationTokens
if total < 0 {
return 0
}
return total
}
type OutputTokenDetails struct {