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/openai/fine_tuning/handler.py:126

        api_base: str | None,
        api_version: str | None,
        timeout: float | httpx.Timeout,
        max_retries: int | None,
        organization: str | None,
        client: OpenAI | AsyncOpenAI | AzureOpenAI | AsyncAzureOpenAI | None = None,
    ) -> LiteLLMFineTuningJob | Coroutine[Any, Any, LiteLLMFineTuningJob]:
        openai_client: Final[OpenAI | AsyncOpenAI | AzureOpenAI | AsyncAzureOpenAI | None] = self.get_openai_client(
            api_key=api_key,
            api_base=api_base,
            timeout=timeout,
            max_retries=max_retries,
            organization=organization,
            client=client,
            _is_async=_is_async,
            api_version=api_version,
        )
        if openai_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(openai_client, (AsyncOpenAI, AsyncAzureOpenAI)):
                raise ValueError(
                    "OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client."
                )
            return self.acreate_fine_tuning_job(
                create_fine_tuning_job_data=create_fine_tuning_job_data,
                openai_client=openai_client,
            )
        verbose_logger.debug("creating fine tuning job, args= %s", create_fine_tuning_job_data)
        response: Final = cast(OpenAI, openai_client).fine_tuning.jobs.create(**create_fine_tuning_job_data)
        return _litellm_fine_tuning_job_from_response(response)

    async def acancel_fine_tuning_job(
        self,

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/openai/fine_tuning/handler.py:126 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/a57de6cddaa6cc39. Report an issue: GitHub.