{"record":{"id":"0b45d7850956eacd","repo":"BerriAI/litellm","slug":"openai-client-is-not-an-instance-of-asyncopenai-m-0b45d7","errorCode":null,"errorMessage":"OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client.","messagePattern":"OpenAI client is not an instance of AsyncOpenAI\\. Make sure you passed an AsyncOpenAI client\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure/fine_tuning/handler.py","lineNumber":89,"sourceCode":"\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(\n        self,\n        _is_async: bool,\n        fine_tuning_job_id: str,\n        api_key: str | None,\n        api_base: str | None,\n        api_version: str | None,","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/fine_tuning/handler.py#L71-L107","documentation":"When _is_async=True, AzureFineTuningAPI.create_fine_tuning_job verifies the resolved client is AsyncOpenAI/AsyncAzureOpenAI before delegating to acreate_fine_tuning_job. This error signals that a synchronous OpenAI/AzureOpenAI client reached the async dispatch. It is raised locally, before fine_tuning.jobs.create is invoked.","triggerScenarios":"Awaiting create_fine_tuning_job(data, client=OpenAI(...) or AzureOpenAI(...), _is_async=True); async training pipelines whose shared client was constructed with the sync class.","commonSituations":"Moving fine-tune submission scripts into async schedulers (Airflow async, Celery with asyncio) while reusing sync client objects; test fixtures that only build the sync class.","solutions":["Construct the client with AsyncOpenAI/AsyncAzureOpenAI for async submission.","Keep the sync path (omit _is_async=True) if a sync client is all you need.","Introduce a client factory keyed by is_async so mismatches cannot occur."],"exampleFix":"# before\nclient = AzureOpenAI(api_key=k, azure_endpoint=b)\njob = await azure_finetune.create_fine_tuning_job(data, client=client, _is_async=True)\n\n# after\nclient = AsyncAzureOpenAI(api_key=k, azure_endpoint=b)\njob = await azure_finetune.create_fine_tuning_job(data, client=client, _is_async=True)","handlingStrategy":"type-guard","validationCode":"from openai import AsyncOpenAI, AsyncAzureOpenAI\n\nassert isinstance(client, (AsyncOpenAI, AsyncAzureOpenAI)), 'async fine-tuning needs an async client'","typeGuard":"def is_async_ft_client(c: object) -> bool:\n    from openai import AsyncOpenAI, AsyncAzureOpenAI\n    return isinstance(c, (AsyncOpenAI, AsyncAzureOpenAI))","tryCatchPattern":"try:\n    job = await ft.create_fine_tuning_job(data, client=client, _is_async=True)\nexcept ValueError as e:\n    if 'AsyncOpenAI' in str(e):\n        raise TypeError('sync client in async fine-tuning create') from e\n    raise","preventionTips":["Construct the fine-tuning client inside the async pipeline that uses it.","Share one async client across create/cancel/retrieve for a job's lifetime."],"tags":["azure","openai","fine-tuning","async","client-type","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}