litellm - ✅(Solved) Fix bug: multiple issues in anthropic /v1/messages experimental pass-through to openai [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23841Fetched 2026-04-08 00:48:56
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×2cross-referenced ×1subscribed ×1

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.

Error Message

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. 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.

Root Cause

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.

Fix Action

Fix

All five bugs are fixed in the accompanying PR.

PR fix notes

PR #23844: fix: anthropic experimental pass-through - input_text support and env var checking

Description (problem / solution / changelog)

Summary

This PR fixes 5 related bugs in the Anthropic /v1/messages experimental pass-through implementation when routing requests to OpenAI/Azure models:

  1. Add input_text support in both transformation paths - Claude Code CLI / Claude Agent SDK sends {"type": "input_text"} content blocks which were previously being silently dropped
  2. Consistently respect LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES at all entry points where the Responses API routing decision is made

Fixed Issues

Fixes #23841

Details of fixes

  1. litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py - Added input_text handling for user content blocks and system content
  2. litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py - Added input_text check in three locations (user content, nested tool_result content, system content)
  3. litellm/main.py - Added missing check for use_chat_completions_url_for_anthropic_messages at the beginning of responses_api_bridge_check()
  4. litellm/llms/anthropic/experimental_pass_through/adapters/handler.py - Added missing check before adding responses/ prefix for thinking-enabled requests
  5. litellm/llms/openai/responses/count_tokens/token_counter.py - Added missing check in should_use_token_counting_api() to avoid calling /v1/responses/input_tokens when user opted out

All fixes are minimal and targeted - only the necessary changes are made, following existing code patterns.

Tested

  • Manual testing with LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES=true confirms that requests are correctly routed to Chat Completions endpoint and input_text blocks are properly handled.

Changed files

  • litellm/llms/anthropic/experimental_pass_through/adapters/handler.py (modified, +4/-0)
  • litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py (modified, +14/-2)
  • litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py (modified, +3/-3)
  • litellm/main.py (modified, +2/-3)
  • poetry.lock (modified, +4/-4)
  • pyproject.toml (modified, +3/-3)
  • tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py (modified, +100/-45)
  • tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py (modified, +72/-8)
  • tests/test_litellm/test_count_tokens_public_api.py (modified, +25/-1)
  • tests/test_litellm/test_main.py (modified, +81/-33)
  • tests/test_litellm/test_xai_responses_auto_routing.py (modified, +27/-24)
RAW_BUFFERClick to expand / collapse

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.

extent analysis

Fix Plan

To address the five bugs in the Anthropic /v1/messages experimental pass-through implementation, follow these steps:

  • Bug 1 & 2: Support input_text type
    • In transformation.py and responses_adapters/transformation.py, update the type checks to include "input_text":

if content_block["type"] in ["text", "input_text"]: # Process the content block

* **Bug 3: Respect `LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES` in `responses_api_bridge_check`**
  * In `main.py`, update the `responses_api_bridge_check` function to check the environment variable:
    ```python
import os

def responses_api_bridge_check():
    #...
    if os.environ.get("LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES") == "true":
        # Use Chat Completions API
    #...
  • Bug 4: Respect LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES in thinking auto-routing
    • In handler.py, update the _route_openai_thinking_to_responses_api_if_needed function to check the environment variable:

def _route_openai_thinking_to_responses_api_if_needed(): #... if os.environ.get("LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES") == "true": # Do not add the responses/ prefix #...

* **Bug 5: Respect `LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES` in token counting**
  * In `token_counter.py`, update the `should_use_token_counting_api` function to check the environment variable:
    ```python
def should_use_token_counting_api():
    #...
    if os.environ.get("LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES") == "true":
        return False
    #...

Verification

To verify the fixes, test the following scenarios:

  • Send a request with an input_text content block and verify that it is properly converted and processed.
  • Set LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES=true and verify that the Chat Completions API is used consistently.
  • Test the thinking auto-routing feature with the environment variable set to true and verify that the responses/ prefix is not added.
  • Verify that the token counting API is not called when the environment variable is set to true.

Extra Tips

  • Make sure to update the documentation to reflect the changes and ensure that the environment variable is properly set in the production environment.
  • Consider adding additional logging and monitoring to detect any issues related to

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING