{"record":{"id":"c62a4c7282c9eb0c","repo":"BerriAI/litellm","slug":"azure-client-is-not-an-instance-of-azureopenai-or","errorCode":null,"errorMessage":"azure_client is not an instance of AzureOpenAI or OpenAI","messagePattern":"azure_client is not an instance of AzureOpenAI or OpenAI","errorType":"exception","errorClass":"AzureOpenAIError","httpStatus":500,"severity":"error","filePath":"litellm/llms/azure/azure.py","lineNumber":341,"sourceCode":"                        \"api_version\": api_version,\n                        \"api_base\": api_base,\n                        \"complete_input_dict\": data,\n                    },\n                )\n                if not isinstance(max_retries, int):\n                    raise AzureOpenAIError(status_code=422, message=\"max retries must be an int\")\n                # init AzureOpenAI 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=False,\n                    litellm_params=litellm_params,\n                )\n                if not isinstance(azure_client, (AzureOpenAI, OpenAI)):\n                    raise AzureOpenAIError(\n                        status_code=500,\n                        message=\"azure_client is not an instance of AzureOpenAI or OpenAI\",\n                    )\n\n                headers, response = self.make_sync_azure_openai_chat_completion_request(\n                    azure_client=azure_client, data=data, timeout=timeout\n                )\n                if isinstance(response, str):\n                    raise AzureOpenAIError(\n                        status_code=500,\n                        message=f\"Unexpected string response from Azure: {response[:500]}\",\n                    )\n                stringified_response: Final = response.model_dump()\n                ## LOGGING\n                logging_obj.post_call(\n                    input=messages,\n                    api_key=api_key,\n                    original_response=stringified_response,","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/azure.py#L323-L359","documentation":"An internal invariant check in the sync Azure OpenAI chat completion path: after `get_azure_openai_client` builds or accepts a passed-in client, it must be an instance of AzureOpenAI or OpenAI. A 500 is raised otherwise. Almost always means a caller injected a custom `client` object of the wrong type.","triggerScenarios":"Passing client=<httpx.AsyncClient or custom wrapper> to a sync completion call; passing an AsyncAzureOpenAI client to the sync path; mocking the client in tests with an object that is not an SDK instance.","commonSituations":"Users constructing their own OpenAI SDK client for connection tuning and passing the async variant; test doubles replacing the client.","solutions":["If you pass a custom client, construct it with openai.AzureOpenAI(...) for sync calls.","Otherwise omit the client argument and let LiteLLM build it from api_base/api_key.","For async calls use litellm.acompletion so the async client path is used."],"exampleFix":"# before\nclient = openai.AsyncAzureOpenAI(api_key=k, azure_endpoint=base)\nlitellm.completion(model='azure/gpt-4o', messages=msgs, client=client)\n\n# after\nclient = openai.AzureOpenAI(api_key=k, azure_endpoint=base, api_version='2024-06-01')\nlitellm.completion(model='azure/gpt-4o', messages=msgs, client=client)","handlingStrategy":"type-guard","validationCode":"if client is not None and not isinstance(client, (openai.AzureOpenAI, openai.OpenAI)):\n    raise TypeError('client must be an openai.AzureOpenAI/OpenAI instance for sync calls')","typeGuard":"from openai import AzureOpenAI, OpenAI\n\ndef is_sync_azure_client(c) -> bool:\n    return isinstance(c, (AzureOpenAI, OpenAI))","tryCatchPattern":null,"preventionTips":["Keep one factory for sync clients and another for async; never share a client across paths.","If you don't need custom TLS/proxy settings, omit `client` and let LiteLLM construct it."],"tags":["azure","openai","internal-invariant","client","type-guard"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}