BerriAI/litellm · error · ValueError

AzureOpenAI client is not initialized. Make sure api_key is…

Error message

AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment.

What it means

Error "AzureOpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment." thrown in BerriAI/litellm.

Solutions

  1. Set OPENAI_API_KEY/AZURE_API_KEY or pass api_key so the AzureOpenAI client initializes.

When it happens

Trigger: Thrown at litellm/llms/azure/files/handler.py:74 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/9ec953ac50464242. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/azure/files/handler.py:74

        create_file_data: CreateFileRequest,
        api_base: str | None,
        api_key: str | None,
        api_version: str | None,
        timeout: float | httpx.Timeout,
        max_retries: int | None,
        client: AzureOpenAI | AsyncAzureOpenAI | OpenAI | AsyncOpenAI | None = None,
        litellm_params: dict | None = None,
    ) -> OpenAIFileObject | Coroutine[Any, Any, OpenAIFileObject]:
        openai_client: AzureOpenAI | AsyncAzureOpenAI | OpenAI | AsyncOpenAI | None = self.get_azure_openai_client(
            litellm_params=litellm_params or {},
            api_key=api_key,
            api_base=api_base,
            api_version=api_version,
            client=client,
            _is_async=_is_async,
        )
        if openai_client is None:
            raise ValueError(
                "AzureOpenAI 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(openai_client, (AsyncAzureOpenAI, AsyncOpenAI)):
                raise ValueError(
                    "AzureOpenAI client is not an instance of AsyncAzureOpenAI. Make sure you passed an AsyncAzureOpenAI client."
                )
            return self.acreate_file(create_file_data=create_file_data, openai_client=openai_client)
        response: Final = cast(AzureOpenAI | OpenAI, openai_client).files.create(
            **self._prepare_create_file_data(create_file_data)
        )
        return OpenAIFileObject(**response.model_dump())

    async def afile_content(
        self,
        file_content_request: FileContentRequest,
        openai_client: AsyncAzureOpenAI | AsyncOpenAI,

View on GitHub (pinned to 77b7c6c40c)