{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L2448-L2484","documentation":"exception_type() special-cases the openai-python SDK internal crash 'BadRequestError.__init__() missing 1 required positional argument: \\\"param\\\"'. When Azure rejects a request and the SDK itself fails constructing its BadRequestError, litellm recovers by raising litellm.BadRequestError, hinting that this often happens when AZURE_API_VERSION is not set, so the request hits an endpoint/preview combination Azure answers with an error the SDK can't parse.","triggerScenarios":"Azure calls where api_version is missing or invalid (e.g. using old azure deployment names or envs without AZURE_API_VERSION) combined with an openai-python version whose AzureError/BadRequestError signatures mismatch litellm's expectations — commonly after upgrading one of the two packages.","commonSituations":"Deployments missing AZURE_API_VERSION env; pinned incompatible openai-python after a litellm upgrade (or vice versa); Azure discontinuing a preview api_version so requests 400 unexpectedly; CI installing latest openai against older litellm.","solutions":["Set the api_version explicitly: os.environ['AZURE_API_VERSION'] = '2024-10-21' (or pass api_version=) for your deployment.","Align versions: upgrade litellm to the latest release (pip install -U litellm) so its SDK adapter matches your openai-python.","Verify the deployment's supported API versions in Azure Portal and pick a current GA version.","If it persists, pin openai-python to the version litellm declares as tested."],"exampleFix":"# before\nlitellm.completion(model=\"azure/dep\", messages=msgs)  # AZURE_API_VERSION unset\n\n# after\nlitellm.completion(\n    model=\"azure/dep\",\n    messages=msgs,\n    api_base=os.environ[\"AZURE_API_BASE\"],\n    api_key=os.environ[\"AZURE_API_KEY\"],\n    api_version=\"2024-10-21\",\n)","handlingStrategy":"validation","validationCode":"import os\nassert os.getenv(\"AZURE_API_VERSION\"), \"AZURE_API_VERSION must be set for azure deployments\"\n# or hard-set a known-good GA version\nos.environ.setdefault(\"AZURE_API_VERSION\", \"2024-10-21\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.completion(model=\"azure/dep\", **kwargs)\nexcept litellm.BadRequestError as e:\n    if \"AZURE_API_VERSION\" in str(e):\n        kwargs[\"api_version\"] = \"2024-10-21\"\n        resp = litellm.completion(model=\"azure/dep\", **kwargs)\n    else:\n        raise","preventionTips":["Always set AZURE_API_VERSION (env or api_version=) for Azure deployments.","Pin litellm and openai-python to a tested-compatible pair in requirements.","After upgrading either package, run a smoke completion against Azure in CI."],"tags":["azure","api-version","sdk-incompatibility","bad-request","litellm","openai-python"],"backgroundTag":"missing-configuration","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}