BerriAI/litellm · error · AzureOpenAIError
Unexpected string response from Azure: {response[:500]}
Error message
Unexpected string response from Azure: {response[:500]} What it means
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.
Source
Thrown at litellm/llms/azure/azure.py:350
api_version=api_version,
api_base=api_base,
api_key=api_key,
model=model,
client=client,
_is_async=False,
litellm_params=litellm_params,
)
if not isinstance(azure_client, (AzureOpenAI, OpenAI)):
raise AzureOpenAIError(
status_code=500,
message="azure_client is not an instance of AzureOpenAI or OpenAI",
)
headers, response = self.make_sync_azure_openai_chat_completion_request(
azure_client=azure_client, data=data, timeout=timeout
)
if isinstance(response, str):
raise AzureOpenAIError(
status_code=500,
message=f"Unexpected string response from Azure: {response[:500]}",
)
stringified_response: Final = response.model_dump()
## LOGGING
logging_obj.post_call(
input=messages,
api_key=api_key,
original_response=stringified_response,
additional_args={
"headers": headers,
"api_version": api_version,
"api_base": api_base,
},
)
return convert_to_model_response_object(
response_object=stringified_response,
model_response_object=model_response,View on GitHub (pinned to 6c2dcb801b)
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.
Example fix
# before pip install litellm==1.x openai==0.28 # after pip install -U litellm openai # let litellm pin a compatible openai
Defensive patterns
Strategy: retry
Validate before calling
import litellm, openai
print('litellm', litellm.__version__, '| openai', openai.__version__) # verify compatible pair before deploying Try / catch
from litellm.exceptions import APIError
for attempt in range(2):
try:
resp = litellm.completion(model='azure/gpt-4o', messages=msgs)
break
except APIError as e:
if 'Unexpected string response' not in str(e) or attempt == 1:
raise
time.sleep(1) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Upgrading litellm without upgrading (or with a downgraded) openai SDK; pip resolving an old openai version after another dependency pinned it.
Related errors
- azure_client is not an instance of AzureOpenAI or OpenAI
- Azure client is not an instance of AsyncAzureOpenAI or Async
- embedding_response is not an instance of EmbeddingResponse
- Unsupported provider config: {transcription_provider_config}
- Missing model or messages
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/79b58168abe92e68.
Report an issue: GitHub.