fix: normalize prompt_tokens to include cache tokens across all Anthropic providers
Summary
Fixes #1564
prompt_tokens normalization is inconsistent across Anthropic access paths:
| Provider | prompt_tokens includes cache? |
|---|---|
| Anthropic direct | ❌ No (input_tokens only) |
| Vertex AI | ❌ No (input_tokens only) |
| Bedrock | ✅ Yes (inputTokens + cache*) |
Per OpenAI convention, prompt_tokens should include cached tokens, with breakdown in prompt_tokens_details.cached_tokens.
Changes
Updated 4 code paths (non-streaming + streaming × 2 providers):
Anthropic direct (src/providers/anthropic/chatComplete.ts):
// Before
prompt_tokens: input_tokens
// After
prompt_tokens: input_tokens + (cache_creation_input_tokens ?? 0) + (cache_read_input_tokens ?? 0)
Vertex AI (src/providers/google-vertex-ai/chatComplete.ts): same change.
Both non-streaming and streaming paths updated. total_tokens was already correct.
We’ve encountered this issue on our end and would greatly appreciate it if someone could share the expected ETA for when this PR will be merged. This information will help us avoid adding unnecessary complexity on our end.
Thank you so much for your assistance!