fix: bound uncached remainder by prompt-max(cached,write) and forward compact prompt_cache_key
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user