Skip to content

Commit 6d93f89

Browse files
committed
fix(translator): trim comments in OpenAI->Anthropic cache-token fix
Shorten the comments explaining why we don't forward OpenAI's cache token breakdown, without changing behavior. Signed-off-by: ajac-zero <ajcardoza2000@gmail.com>
1 parent 67d9862 commit 6d93f89

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

internal/translator/openai_helper.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)