{"record":{"id":"9bb5383b54c5e13b","repo":"BerriAI/litellm","slug":"azure-client-is-not-an-instance-of-asyncazureopena","errorCode":null,"errorMessage":"Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI","messagePattern":"Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/azure/azure.py","lineNumber":419,"sourceCode":"        azure_ad_token_provider: Callable | None = None,\n        convert_tool_call_to_json_mode: bool | None = None,\n        client=None,  # this is the AsyncAzureOpenAI\n        litellm_params: dict | None = {},\n    ):\n        response = None\n        try:\n            # setting Azure client\n            azure_client: Final = self.get_azure_openai_client(\n                api_version=api_version,\n                api_base=api_base,\n                api_key=api_key,\n                model=model,\n                client=client,\n                _is_async=True,\n                litellm_params=litellm_params,\n            )\n            if not isinstance(azure_client, (AsyncAzureOpenAI, AsyncOpenAI)):\n                raise ValueError(\"Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI\")\n            ## LOGGING\n            logging_obj.pre_call(\n                input=data[\"messages\"],\n                api_key=azure_client.api_key,\n                additional_args={\n                    \"headers\": {\n                        \"api_key\": api_key,\n                        \"azure_ad_token\": azure_ad_token,\n                    },\n                    \"api_base\": api_base,\n                    \"acompletion\": True,\n                    \"complete_input_dict\": data,\n                },\n            )\n\n            headers, response = await self.make_azure_openai_chat_completion_request(\n                azure_client=azure_client,\n                data=data,","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/azure.py#L401-L437","documentation":"Async counterpart of the sync client check: in acompletion, the client obtained from `get_azure_openai_client` must be an AsyncAzureOpenAI or AsyncOpenAI instance, else this ValueError is raised. Typically caused by injecting a sync client or a custom object via the `client` parameter.","triggerScenarios":"Passing client=openai.AzureOpenAI(...) (sync) to a litellm.acompletion call; passing an httpx client or a mock object instead of an SDK client.","commonSituations":"Reusing one client factory for both sync and async code paths; test harnesses injecting fakes that don't subclass the SDK classes.","solutions":["Use openai.AsyncAzureOpenAI(...) when supplying a client to acompletion.","Or drop the client argument and let LiteLLM construct the async client itself.","For sync flows use litellm.completion."],"exampleFix":"# before\nclient = openai.AzureOpenAI(api_key=k, azure_endpoint=base)\nawait litellm.acompletion(model='azure/gpt-4o', messages=msgs, client=client)\n\n# after\nclient = openai.AsyncAzureOpenAI(api_key=k, azure_endpoint=base, api_version='2024-06-01')\nawait litellm.acompletion(model='azure/gpt-4o', messages=msgs, client=client)","handlingStrategy":"type-guard","validationCode":"if client is not None and not isinstance(client, (openai.AsyncAzureOpenAI, openai.AsyncOpenAI)):\n    raise TypeError('client must be AsyncAzureOpenAI/AsyncOpenAI for acompletion')","typeGuard":"from openai import AsyncAzureOpenAI, AsyncOpenAI\n\ndef is_async_azure_client(c) -> bool:\n    return isinstance(c, (AsyncAzureOpenAI, AsyncOpenAI))","tryCatchPattern":null,"preventionTips":["Name sync and async client variables distinctly (azure_sync_client / azure_async_client).","In FastAPI-style apps, create the async client once at startup and validate its type."],"tags":["azure","openai","async","client","internal-invariant"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}