Repository navigation
fix(kiro): estimate prompt cache and report Anthropic input tokens - #571
Merged
Merged
Conversation
- gateway: Anthropic input_tokens excludes cache read/creation; stream message_delta now carries input_tokens. - kiro: local per-account prompt-cache estimator (prompt_cache.go), Kiro-Go style token estimator (token_estimate.go), broader upstream usage parsing (upstream_tokens.go). - collectOutcome passes cache read/write through.
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
input_tokensin the finalmessage_delta(it was missing, so clients saw 0). Anthropicinput_tokensnow excludes cache read/creation, matching Anthropic semantics; OpenAIprompt_tokensis unchanged. Logic lives ininternal/gateway/anthropic_usage.go.cache_tracker.go(internal/providers/kiro/prompt_cache.go): per-account SHA-256 prefix fingerprints, 5m TTL, 1024/4096 (opus) minimum, 85% read cap, first request writes only, stored only after a clean stream. The estimate is scaled to Kiro's context-share input count and emitted ascache_read_tokens/cache_write_tokens;collectOutcomepasses them through for non-stream.token_estimate.go); upstream token parsing accepts more usage shapes, including nested usage maps, cache sums, and total minus output (upstream_tokens.go).Tests
go test ./...andgo vet ./...pass.anthropic_usage_test.go,prompt_cache_test.go,token_estimate_test.go,upstream_tokens_test.go.