BerriAI/litellm · error · ValueError

Azure client is not an instance of AsyncAzureOpenAI or Async

Error message

Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI. Make sure you passed an async client.

What it means

Error "Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI. Make sure you passed an async client." thrown in BerriAI/litellm.

Source

Thrown at litellm/llms/azure/batches/handler.py:153

        client: AzureOpenAI | AsyncAzureOpenAI | OpenAI | AsyncOpenAI | None = None,
        litellm_params: dict | None = None,
    ):
        azure_client: AzureOpenAI | AsyncAzureOpenAI | OpenAI | AsyncOpenAI | None = self.get_azure_openai_client(
            api_key=api_key,
            api_base=api_base,
            api_version=api_version,
            client=client,
            _is_async=_is_async,
            litellm_params=litellm_params or {},
        )
        if azure_client is None:
            raise ValueError(
                "OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment."
            )

        if _is_async is True:
            if not isinstance(azure_client, (AsyncAzureOpenAI, AsyncOpenAI)):
                raise ValueError(
                    "Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI. Make sure you passed an async client."
                )
            return self.acancel_batch(cancel_batch_data=cancel_batch_data, client=azure_client)

        # At this point, azure_client is guaranteed to be a sync client
        if not isinstance(azure_client, (AzureOpenAI, OpenAI)):
            raise ValueError(
                "Azure client is not an instance of AzureOpenAI or OpenAI. Make sure you passed a sync client."
            )
        response: Final = azure_client.batches.cancel(**cancel_batch_data)
        return LiteLLMBatch.model_validate(response.model_dump())

    async def alist_batches(
        self,
        client: AsyncAzureOpenAI | AsyncOpenAI,
        after: str | None = None,
        limit: int | None = None,
    ):

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass an AsyncAzureOpenAI or AsyncOpenAI client.

When it happens

Trigger: Thrown at litellm/llms/azure/batches/handler.py:153 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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