{"record":{"id":"2c0400d3215dccd8","repo":"BerriAI/litellm","slug":"azure-openai-client-is-not-initialized-make-sure","errorCode":null,"errorMessage":"Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_API_KEY is set in the environment.","messagePattern":"Azure OpenAI client is not initialized\\. Make sure api_key is passed or AZURE_API_KEY is set in the environment\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure/fine_tuning/handler.py","lineNumber":83,"sourceCode":"        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        self._ensure_training_type(create_fine_tuning_job_data)\n\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                \"Azure OpenAI client is not initialized. Make sure api_key is passed or AZURE_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\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, is_azure=True)\n\n    def cancel_fine_tuning_job(","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/fine_tuning/handler.py#L65-L101","documentation":"AzureFineTuningAPI.create_fine_tuning_job builds an OpenAI-family client via get_openai_client(api_key, api_base, ...); if that resolver returns None (no client= argument, no api_key, and AZURE_API_KEY absent from the environment) this ValueError is raised. It is a pre-flight credential check — no fine-tuning API request is made.","triggerScenarios":"create_fine_tuning_job(create_fine_tuning_job_data) with no api_key, no client, and AZURE_API_KEY unset; pipelines running in containers where the Azure key secret was not injected.","commonSituations":"Automation that sets OPENAI_API_KEY for OpenAI jobs but forgets AZURE_API_KEY for the Azure variant; rotated/expired Azure keys removed from the environment; multi-region deployments where one region lacks the env var.","solutions":["Pass api_key=os.environ['AZURE_API_KEY'] to create_fine_tuning_job.","Or export AZURE_API_KEY in the runtime environment.","Or pass a pre-built AzureOpenAI/AsyncAzureOpenAI client via client=.","Add a startup validation step that fails fast when no Azure credential is discoverable."],"exampleFix":"# before\njob = azure_finetune.create_fine_tuning_job(data)\n\n# after\njob = azure_finetune.create_fine_tuning_job(\n    data,\n    api_key=os.environ['AZURE_API_KEY'],\n    api_base='https://<resource>.openai.azure.com',\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef validate_fts_credentials(api_key: str | None, client: object | None) -> None:\n    if client is None and not api_key and not os.environ.get('AZURE_API_KEY'):\n        raise RuntimeError('fine-tuning needs api_key, a client, or AZURE_API_KEY in env')","typeGuard":null,"tryCatchPattern":"try:\n    job = ft.create_fine_tuning_job(data, api_key=api_key)\nexcept ValueError as e:\n    if 'not initialized' in str(e):\n        raise RuntimeError('Azure fine-tuning credential missing (AZURE_API_KEY)') from e\n    raise","preventionTips":["Set AZURE_API_KEY via your secret manager, not ad-hoc exports.","Validate credentials in a preflight check before submitting training data.","Note this handler checks AZURE_API_KEY, not OPENAI_API_KEY."],"tags":["azure","openai","fine-tuning","credentials","api-key","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}