Skip to content

fix(anthropic): normalize prompt_tokens to include cache tokens across all providers#1567

Open
BillionClaw wants to merge 1 commit intoPortkey-AI:mainfrom
BillionClaw:clawoss/fix/1564-prompt-tokens-normalization
Open

fix(anthropic): normalize prompt_tokens to include cache tokens across all providers#1567
BillionClaw wants to merge 1 commit intoPortkey-AI:mainfrom
BillionClaw:clawoss/fix/1564-prompt-tokens-normalization

Conversation

@BillionClaw
Copy link

@BillionClaw BillionClaw commented Mar 17, 2026

prompt_tokens normalization was inconsistent across Anthropic providers. For the same model with caching enabled, Anthropic direct and Vertex AI set prompt_tokens = input_tokens (excluding cache tokens), while Bedrock included them. OpenAI convention is that prompt_tokens includes cached tokens with breakdown in prompt_tokens_details.cached_tokens.

Updated prompt_tokens in both non-streaming and streaming response transforms for Anthropic direct and Vertex AI to include cache_creation_input_tokens and cache_read_input_tokens, matching Bedrock. Also fixed the streaming totalTokens calculation to avoid double-counting now that prompt_tokens includes cache tokens.

Files changed:

  • src/providers/anthropic/chatComplete.ts (non-streaming + streaming)
  • src/providers/google-vertex-ai/chatComplete.ts (non-streaming + streaming)

Fixes #1564

@BillionClaw BillionClaw force-pushed the clawoss/fix/1564-prompt-tokens-normalization branch 2 times, most recently from abc415a to 48eb4d6 Compare March 17, 2026 07:21
…nthropic and Vertex AI

Anthropic direct and Vertex AI set prompt_tokens = input_tokens (excluding
cache), while Bedrock included cache tokens. OpenAI convention is that
prompt_tokens includes cached tokens. Updated both non-streaming and streaming
response transforms to include cache_creation_input_tokens and
cache_read_input_tokens in prompt_tokens, and adjusted totalTokens in streaming
to avoid double-counting.

Fixes Portkey-AI#1564
@BillionClaw BillionClaw force-pushed the clawoss/fix/1564-prompt-tokens-normalization branch from 48eb4d6 to 2c9b69d Compare March 17, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Inconsistent prompt_tokens normalization across Anthropic providers (direct API vs Vertex AI vs Bedrock)

1 participant