Skip to content

bug: multiple issues in anthropic /v1/messages experimental pass-through to openai #23841

Description

@garnetlyx

Bug: Multiple bugs in Anthropic /v1/messages experimental pass-through to OpenAI

Description

There are five related bugs in the Anthropic /v1/messages experimental pass-through implementation when routing requests to OpenAI/Azure models. These issues were discovered during integration testing with Claude Code CLI which uses input_text content block format and requires forcing routing through Chat Completions API when the downstream proxy doesn't support Responses API.

Bug 1: input_text type not supported in chat completions transformation

Claude Code CLI / Claude Agent SDK sends content blocks with {"type": "input_text"} (instead of plain {"type": "text"}) for user messages and system content. The current implementation only checks for "text", so input_text blocks are silently dropped → causes empty input → 422 validation error from downstream provider.

Location: litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py

Bug 2: input_text type not supported in Responses API transformation

Same issue exists on the Responses API conversion path. The code only checks for "text" in three locations:

  • Top-level user content blocks
  • Nested content inside tool_result
  • System content array

Location: litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py

Bug 3: LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES not respected in responses_api_bridge_check

When the environment variable LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES=true is set (to force routing through /v1/chat/completions instead of /v1/responses), the responses_api_bridge_check function in main.py doesn't check this setting. It still activates Responses API mode for models with the responses/ prefix → request routed to wrong endpoint.

Location: litellm/main.py function responses_api_bridge_check()

Bug 4: LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES not respected in thinking auto-routing

When thinking parameter is enabled, the code automatically adds the responses/ prefix to route through Responses API (to get reasoning text output). But it didn't check the use_chat_completions_url_for_anthropic_messages setting before adding the prefix, ignoring user opt-out preference.

Location: litellm/llms/anthropic/experimental_pass_through/adapters/handler.py function _route_openai_thinking_to_responses_api_if_needed()

Bug 5: LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES not respected in token counting

When the environment variable is enabled, should_use_token_counting_api() still returns True for OpenAI provider, causing it to call /v1/responses/input_tokens endpoint which doesn't exist when routing through Chat Completions → 405 Method Not Allowed error.

Location: litellm/llms/openai/responses/count_tokens/token_counter.py function should_use_token_counting_api()

Expected behavior

  1. input_text content blocks should be accepted and properly converted just like text blocks
  2. The LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES setting should be respected consistently at all entry points where Responses API routing decision is made

Fix

All five bugs are fixed in the accompanying PR.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions