{"record":{"id":"a57de6cddaa6cc39","repo":"BerriAI/litellm","slug":"openai-client-is-not-initialized-make-sure-api-ke-a57de6","errorCode":null,"errorMessage":"OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment.","messagePattern":"OpenAI client is not initialized\\. Make sure api_key is passed or OPENAI_API_KEY is set in the environment\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/fine_tuning/handler.py","lineNumber":126,"sourceCode":"        api_base: str | None,\n        api_version: str | None,\n        timeout: float | httpx.Timeout,\n        max_retries: int | None,\n        organization: str | None,\n        client: OpenAI | AsyncOpenAI | AzureOpenAI | AsyncAzureOpenAI | None = None,\n    ) -> LiteLLMFineTuningJob | Coroutine[Any, Any, LiteLLMFineTuningJob]:\n        openai_client: Final[OpenAI | AsyncOpenAI | AzureOpenAI | AsyncAzureOpenAI | None] = self.get_openai_client(\n            api_key=api_key,\n            api_base=api_base,\n            timeout=timeout,\n            max_retries=max_retries,\n            organization=organization,\n            client=client,\n            _is_async=_is_async,\n            api_version=api_version,\n        )\n        if openai_client is None:\n            raise ValueError(\n                \"OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment.\"\n            )\n\n        if _is_async is True:\n            if not isinstance(openai_client, (AsyncOpenAI, AsyncAzureOpenAI)):\n                raise ValueError(\n                    \"OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client.\"\n                )\n            return self.acreate_fine_tuning_job(\n                create_fine_tuning_job_data=create_fine_tuning_job_data,\n                openai_client=openai_client,\n            )\n        verbose_logger.debug(\"creating fine tuning job, args= %s\", create_fine_tuning_job_data)\n        response: Final = cast(OpenAI, openai_client).fine_tuning.jobs.create(**create_fine_tuning_job_data)\n        return _litellm_fine_tuning_job_from_response(response)\n\n    async def acancel_fine_tuning_job(\n        self,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/openai/fine_tuning/handler.py#L108-L144","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/openai/fine_tuning/handler.py:126 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass api_key or set OPENAI_API_KEY so the OpenAI client can initialize."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}