{"record":{"id":"2c8dd484d341494b","repo":"BerriAI/litellm","slug":"exception-provider-badrequesterror-this-can-ha","errorCode":null,"errorMessage":"{exception_provider} BadRequestError : This can happen due to missing AZURE_API_VERSION: {original_exception}","messagePattern":"(.+?) BadRequestError : This can happen due to missing AZURE_API_VERSION: (.+?)","errorType":"exception","errorClass":"BadRequestError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":2466,"sourceCode":"                    exception_type=exception_type,\n                    exception_provider=exception_provider,\n                    extra_information=extra_information,\n                )\n            if custom_llm_provider == \"openrouter\":\n                _map_openrouter_exception(\n                    model=model,\n                    original_exception=mappable_exception,\n                    custom_llm_provider=custom_llm_provider,\n                    error_str=error_str,\n                    exception_type=exception_type,\n                    exception_provider=exception_provider,\n                    extra_information=extra_information,\n                )\n        if \"BadRequestError.__init__() missing 1 required positional argument: 'param'\" in str(\n            original_exception\n        ):  # deal with edge-case invalid request error bug in openai-python sdk\n            exception_mapping_worked = True\n            raise BadRequestError(\n                message=f\"{exception_provider} BadRequestError : This can happen due to missing AZURE_API_VERSION: {original_exception}\",\n                model=model,\n                llm_provider=custom_llm_provider,\n                response=getattr(original_exception, \"response\", None),\n            )\n        else:  # ensure generic errors always return APIConnectionError=\n            \"\"\"\n            For unmapped exceptions - raise the exception with traceback - https://github.com/BerriAI/litellm/issues/4201\n            \"\"\"\n            exception_mapping_worked = True\n            if hasattr(original_exception, \"request\"):\n                raise APIConnectionError(\n                    message=f\"{exception_provider} - {error_str}\",\n                    llm_provider=custom_llm_provider,\n                    model=model,\n                    request=getattr(original_exception, \"request\", None),\n                )\n            else:","sourceCodeStart":2448,"sourceCodeEnd":2484,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L2448-L2484","documentation":"A compatibility shim for an openai-python SDK bug where BadRequestError.__init__() is missing the required 'param' argument. LiteLLM intercepts this broken exception and re-raises it as a well-formed BadRequestError, hinting that the usual root cause is a missing AZURE_API_VERSION when calling Azure OpenAI.","triggerScenarios":"Calling azure/ deployments without the api-version query parameter or without the AZURE_API_VERSION env var, in combination with an openai-python version that raises the malformed BadRequestError.","commonSituations":"Azure deployments configured with only api_base+api_key, env var name typos (AZURE_API_VERSION vs AZURE_API_VERSION), or openai-python version drift after upgrading litellm.","solutions":["Set the Azure API version explicitly: os.environ['AZURE_API_VERSION']='2024-06-01' or pass api_version in the call.","Prefer the full deployment format 'azure/<deployment-name>' with api_base, api_key, api_version all provided.","Pin/upgrade openai-python to a version compatible with your litellm release."],"exampleFix":"# before\nlitellm.completion(model='azure/my-deploy', messages=msgs, api_key=k, api_base=b)\n\n# after\nlitellm.completion(model='azure/my-deploy', messages=msgs, api_key=k, api_base=b, api_version='2024-06-01')","handlingStrategy":"validation","validationCode":"import os\n\ndef azure_config_valid() -> bool:\n    return bool(os.getenv('AZURE_API_KEY') and os.getenv('AZURE_API_BASE') and os.getenv('AZURE_API_VERSION'))","typeGuard":null,"tryCatchPattern":"try {\n  await litellm.completion({ model: 'azure/deploy', ... });\n} catch (e) {\n  if (e instanceof litellm.BadRequestError && /AZURE_API_VERSION/.test(e.message)) { /* set api_version and retry */ }\n}","preventionTips":["Always pass api_version explicitly for azure/ models.","Validate AZURE_* env vars at app startup.","Keep litellm and openai-python versions aligned."],"tags":["azure","bad-request","api-version","sdk-compat"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}