fix: stop deducting simulated cache tokens from input_tokens
Some checks failed
Build Docker Image / build (push) Has been cancelled
Some checks failed
Build Docker Image / build (push) Has been cancelled
Kiro backend does not support Anthropic prompt cache protocol. The local cache tracker simulates cache hits/creation for Claude Code compatibility, but subtracting those values from input_tokens caused the reported input_tokens to drop to single digits. input_tokens now reflects the real value; cache_creation_input_tokens and cache_read_input_tokens are still reported for protocol compliance. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -512,13 +512,9 @@ func computePromptCacheTTLBreakdown(profile *promptCacheProfile, matchedTokens i
|
||||
return cache5m, cache1h
|
||||
}
|
||||
|
||||
func billedClaudeInputTokens(inputTokens int, usage promptCacheUsage) int {
|
||||
return maxInt(inputTokens-usage.CacheCreationInputTokens-usage.CacheReadInputTokens, 0)
|
||||
}
|
||||
|
||||
func buildClaudeUsageMap(inputTokens, outputTokens int, usage promptCacheUsage, includeCache bool) map[string]interface{} {
|
||||
result := map[string]interface{}{
|
||||
"input_tokens": billedClaudeInputTokens(inputTokens, usage),
|
||||
"input_tokens": inputTokens,
|
||||
"output_tokens": outputTokens,
|
||||
}
|
||||
if !includeCache {
|
||||
|
||||
@@ -56,8 +56,8 @@ func TestBuildClaudeUsageMapIncludesCacheFields(t *testing.T) {
|
||||
|
||||
m := buildClaudeUsageMap(100, 50, usage, true)
|
||||
|
||||
if got := m["input_tokens"]; got != 50 {
|
||||
t.Fatalf("expected billed input tokens 50, got %#v", got)
|
||||
if got := m["input_tokens"]; got != 100 {
|
||||
t.Fatalf("expected input tokens 100 (no deduction), got %#v", got)
|
||||
}
|
||||
if got := m["cache_creation_input_tokens"]; got != 30 {
|
||||
t.Fatalf("expected cache creation tokens 30, got %#v", got)
|
||||
|
||||
@@ -1286,7 +1286,7 @@ func (h *Handler) handleClaudeNonStream(w http.ResponseWriter, account *config.A
|
||||
}
|
||||
|
||||
resp := KiroToClaudeResponse(finalContent, responseThinkingContent, includeEmptyThinkingBlock, toolUses, inputTokens, outputTokens, model)
|
||||
resp.Usage.InputTokens = billedClaudeInputTokens(inputTokens, cacheUsage)
|
||||
resp.Usage.InputTokens = inputTokens
|
||||
resp.Usage.CacheCreationInputTokens = cacheUsage.CacheCreationInputTokens
|
||||
resp.Usage.CacheReadInputTokens = cacheUsage.CacheReadInputTokens
|
||||
if cacheProfile != nil {
|
||||
|
||||
Reference in New Issue
Block a user