Skip to content

fix: map OpenAI cached_tokens to cache_read_input_tokens on /v1/messages - #37

Open
lukesorvikDO wants to merge 1 commit into
digitalocean:release/v1.83.10-stable.do.5from
lukesorvikDO:lsorvik/openai-messages-cache-read-mapping
Open

fix: map OpenAI cached_tokens to cache_read_input_tokens on /v1/messages#37
lukesorvikDO wants to merge 1 commit into
digitalocean:release/v1.83.10-stable.do.5from
lukesorvikDO:lsorvik/openai-messages-cache-read-mapping

Conversation

@lukesorvikDO

Copy link
Copy Markdown
Collaborator

Summary

translate_response in LiteLLMAnthropicToResponsesAPIAdapter only copied input_tokens and output_tokens from the OpenAI Responses API usage, dropping input_tokens_details.cached_tokens. As a result, inference-proxy always saw cache_read_input_tokens=0 on /v1/messages even when OpenAI returned a cache hit.

Fix

Map input_tokens_details.cached_tokens to cache_read_input_tokens in both the non-streaming translate_response path and the streaming iterator (AnthropicResponsesStreamWrapper), falling back to the OpenAI-style field only when the Anthropic-style cache_read_input_tokens field isn't already present.

Scope

This PR is split out of #35 to keep each fix atomic. It contains only the OpenAI /v1/messages cache-read mapping fix. The Anthropic /v1/responses cache_control and cache_creation fixes from #35 are tracked separately.

Pre-Submission checklist

  • My PR's scope is as isolated as possible; it only solves 1 specific problem

Type

🐛 Bug Fix

Made with Cursor

translate_response in LiteLLMAnthropicToResponsesAPIAdapter only copied
input_tokens and output_tokens from the OpenAI Responses API usage,
dropping input_tokens_details.cached_tokens. The inference-proxy always
saw cache_read_input_tokens=0 even when OpenAI returned a cache hit.

Fix: map input_tokens_details.cached_tokens to cache_read_input_tokens
in both the non-streaming translate_response and the streaming iterator.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant