{"record":{"id":"79b58168abe92e68","repo":"BerriAI/litellm","slug":"unexpected-string-response-from-azure-response","errorCode":null,"errorMessage":"Unexpected string response from Azure: {response[:500]}","messagePattern":"Unexpected string response from Azure: (.+?)","errorType":"exception","errorClass":"AzureOpenAIError","httpStatus":500,"severity":"error","filePath":"litellm/llms/azure/azure.py","lineNumber":350,"sourceCode":"                    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,\n                    additional_args={\n                        \"headers\": headers,\n                        \"api_version\": api_version,\n                        \"api_base\": api_base,\n                    },\n                )\n                return convert_to_model_response_object(\n                    response_object=stringified_response,\n                    model_response_object=model_response,","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure/azure.py#L332-L368","documentation":"After the sync Azure OpenAI chat completion request succeeds at the HTTP level, the SDK response must be a parsed model object, not a str. If it is a string, LiteLLM raises this 500 including the first 500 characters. Indicates an SDK/version mismatch or an exotic response shape from the gateway in front of Azure.","triggerScenarios":"An incompatible openai package version returning raw strings from client.chat.completions.create; routing through a Cloudflare AI Gateway or proxy that returns non-standard payloads; monkeypatched SDK in tests.","commonSituations":"Upgrading litellm without upgrading (or with a downgraded) openai SDK; pip resolving an old openai version after another dependency pinned it.","solutions":["Align versions: pip install -U litellm openai so the openai package matches the version litellm declares.","Check the embedded response snippet in the message to see what the endpoint actually returned.","If a gateway (Cloudflare AI Gateway etc.) is in the path, verify it forwards Azure OpenAI responses unmodified.","Report with the snippet if it persists on matched versions."],"exampleFix":"# before\npip install litellm==1.x openai==0.28\n\n# after\npip install -U litellm openai  # let litellm pin a compatible openai","handlingStrategy":"retry","validationCode":"import litellm, openai\nprint('litellm', litellm.__version__, '| openai', openai.__version__)  # verify compatible pair before deploying","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import APIError\n\nfor attempt in range(2):\n    try:\n        resp = litellm.completion(model='azure/gpt-4o', messages=msgs)\n        break\n    except APIError as e:\n        if 'Unexpected string response' not in str(e) or attempt == 1:\n            raise\n        time.sleep(1)","preventionTips":["Pin litellm and openai versions together in requirements and upgrade them in one commit.","Smoke-test one completion after any dependency change before rolling out."],"tags":["azure","openai","version-mismatch","sdk","internal-invariant"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}