BerriAI/litellm · error · ValueError

Failed to transform response to Anthropic format

Error message

Failed to transform response to Anthropic format

What it means

Error "Failed to transform response to Anthropic format" thrown in BerriAI/litellm.

Solutions

  1. Inspect the provider response for fields the adapter cannot convert to Anthropic format.
  2. Enable debug logging to capture the raw response.

When it happens

Trigger: Thrown at litellm/llms/anthropic/experimental_pass_through/adapters/handler.py:627 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/d3bd0f4705dcdba5. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/anthropic/experimental_pass_through/adapters/handler.py:627

            transformed_stream: Final = ANTHROPIC_ADAPTER.translate_completion_output_params_streaming(
                completion_response,
                model=model,
                tool_name_mapping=tool_name_mapping,
                polyfill_result=polyfill_result,
                is_async=True,
            )
            if transformed_stream is not None:
                return transformed_stream
            raise ValueError("Failed to transform streaming response")
        else:
            anthropic_response: Final = ANTHROPIC_ADAPTER.translate_completion_output_params(
                cast(ModelResponse, completion_response),
                tool_name_mapping=tool_name_mapping,
                polyfill_result=polyfill_result,
            )
            if anthropic_response is not None:
                return anthropic_response
            raise ValueError("Failed to transform response to Anthropic format")

    @staticmethod
    def anthropic_messages_handler(
        max_tokens: int,
        messages: _AnthropicMessages,
        model: str,
        metadata: dict[str, object] | None = None,
        stop_sequences: list[str] | None = None,
        stream: bool | None = False,
        system: str | None = None,
        temperature: float | None = None,
        thinking: dict[str, object] | None = None,
        tool_choice: dict[str, object] | None = None,
        tools: list[dict[str, object]] | None = None,
        top_k: int | None = None,
        top_p: float | None = None,
        output_format: dict[str, object] | None = None,
        _is_async: bool = False,

View on GitHub (pinned to 77b7c6c40c)