BerriAI/litellm · error · ValueError

OpenAI client is not initialized. Make sure api_key is passe

Error message

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

What it means

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

Source

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

        create_batch_data: CreateBatchRequest,
        api_key: str | None,
        api_base: 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,
    ) -> LiteLLMBatch | Coroutine[object, object, LiteLLMBatch]:
        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(
                    "OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client."
                )
            return self.acreate_batch(create_batch_data=create_batch_data, azure_client=azure_client)
        response = cast(AzureOpenAI | OpenAI, azure_client).batches.create(**create_batch_data)
        return LiteLLMBatch.model_validate(response.model_dump())

    async def aretrieve_batch(
        self,
        retrieve_batch_data: RetrieveBatchRequest,
        client: AsyncAzureOpenAI | AsyncOpenAI,
    ) -> LiteLLMBatch:
        response: Final = await client.batches.retrieve(**retrieve_batch_data)

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_key or set OPENAI_API_KEY so the OpenAI client can initialize.

When it happens

Trigger: Thrown at litellm/llms/azure/batches/handler.py:63 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/3f96c473b23850d2. Report an issue: GitHub.