Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ describe("toOpenAI (non-streaming) - Cache Token Handling", () => {

const result = toOpenAI(anthropicResponse);

// prompt_tokens should be input_tokens + cache_read_input_tokens
expect(result.usage.prompt_tokens).toBe(4);
// prompt_tokens should be input_tokens + cache_read_input_tokens (same as streaming)
expect(result.usage.prompt_tokens).toBe(4 + 51713);
expect(result.usage.total_tokens).toBe(4 + 51713 + 100);
expect(result.usage.prompt_tokens_details?.cached_tokens).toBe(51713);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export function toOpenAI(response: AnthropicResponseBody): OpenAIResponseBody {
model: response.model,
choices: [choice],
usage: {
prompt_tokens: anthropicUsage.input_tokens,
// OpenAI's prompt_tokens includes cached tokens; match the streaming converter
prompt_tokens: anthropicUsage.input_tokens + cachedTokens,
completion_tokens: anthropicUsage.output_tokens,
total_tokens: anthropicUsage.input_tokens + anthropicUsage.output_tokens + cachedTokens + cacheWriteTokens,
...((cachedTokens > 0 || cacheWriteTokens > 0) && {
Expand Down