BerriAI/litellm · error · AzureOpenAIError

embedding_response is not an instance of EmbeddingResponse

Error message

embedding_response is not an instance of EmbeddingResponse

What it means

After converting the Azure embedding response with `convert_to_model_response_object`, the result must be an instance of EmbeddingResponse; otherwise this 500 is raised. It is an internal consistency check — conversion normally either succeeds or throws its own error, so seeing this means the converter returned an unexpected type (custom response object injection, version skew).

Source

Thrown at litellm/llms/azure/azure.py:724

                )
            stringified_response: Final = response.model_dump()

            ## LOGGING
            logging_obj.post_call(
                input=input,
                api_key=api_key,
                additional_args={"complete_input_dict": data},
                original_response=stringified_response,
            )
            embedding_response: Final = convert_to_model_response_object(
                response_object=stringified_response,
                model_response_object=model_response,
                hidden_params={"headers": headers},
                _response_headers=process_azure_headers(headers),
                response_type="embedding",
            )
            if not isinstance(embedding_response, EmbeddingResponse):
                raise AzureOpenAIError(
                    status_code=500,
                    message="embedding_response is not an instance of EmbeddingResponse",
                )
            return embedding_response
        except Exception as e:
            ## LOGGING
            logging_obj.post_call(
                input=input,
                api_key=api_key,
                additional_args={"complete_input_dict": data},
                original_response=str(e),
            )
            raise e

    def embedding(
        self,
        model: str,
        input: list,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Do not pass a custom model_response argument; let LiteLLM create it.
  2. Reinstall cleanly: pip install --force-reinstall litellm to eliminate mixed-version internals.
  3. Verify you are not monkeypatching convert_to_model_response_object in tests.

Example fix

# before
resp = litellm.embedding(model='azure/text-embedding-3-large', input=['hi'], model_response=my_custom_obj)

# after
resp = litellm.embedding(model='azure/text-embedding-3-large', input=['hi'])
Defensive patterns

Strategy: validation

Validate before calling

# Don't pass a custom model_response; if you must, ensure it's the right type:
from litellm.types.utils import EmbeddingResponse
assert my_response_obj is None or isinstance(my_response_obj, EmbeddingResponse)

Type guard

from litellm.types.utils import EmbeddingResponse

def is_embedding_response(r) -> bool:
    return isinstance(r, EmbeddingResponse)

Prevention

When it happens

Trigger: Passing a custom `model_response` object of the wrong class into the embedding call; a litellm version where internal response types changed under a partially-upgraded install.

Common situations: Mixed-version installs after upgrading litellm in place; code that reuses or subclasses response objects incorrectly.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/48eb34152b26272e. Report an issue: GitHub.