@@ -739,12 +739,9 @@ func (s *openAIStreamToAnthropicState) handleChunk(chunk *openai.ChatCompletionR
739739 if len (chunk .Choices ) == 0 && chunk .Usage != nil {
740740 s .inputTokens = chunk .Usage .PromptTokens
741741 s .outputTokens = chunk .Usage .CompletionTokens
742- // We don't forward OpenAI's prompt_tokens_details.cached_tokens/cache_creation_input_tokens
743- // here: they're a breakdown *within* prompt_tokens (like text_tokens/audio_tokens), not
744- // additive extras as in Anthropic's native usage schema, where input_tokens excludes
745- // cache tokens and they're reported as separate additive fields. Forwarding OpenAI's
746- // values as-is would cause Anthropic clients to double-count the cached portion on top
747- // of input_tokens.
742+ // OpenAI's cached_tokens/cache_creation_input_tokens are a breakdown within
743+ // prompt_tokens, not additive like Anthropic's native cache fields, so we don't
744+ // forward them here to avoid double-counting.
748745 s .tokenUsage = metrics .ExtractTokenUsageFromExplicitCaching (
749746 int64 (s .inputTokens ),
750747 int64 (s .outputTokens ),
@@ -1057,8 +1054,7 @@ func (s *openAIStreamToAnthropicState) emitClosingEvents(out *[]byte) error {
10571054 stopReason = string (anthropic .StopReasonEndTurn )
10581055 }
10591056
1060- // message_delta.usage is cumulative per the Anthropic API spec, so we backfill input_tokens
1061- // here rather than in message_start, since OpenAI doesn't report prompt token usage until now.
1057+ // Backfill input_tokens here (not message_start): OpenAI doesn't report it until now.
10621058 msgDeltaPayload := sseMessageDelta {
10631059 Type : "message_delta" ,
10641060 Delta : sseMessageDeltaBody {StopReason : stopReason , StopSequence : nil },
0 commit comments