BerriAI/litellm · error · BadRequestError

BadRequestError : This can happen due to missing…

Error message

{exception_provider} BadRequestError : This can happen due to missing AZURE_API_VERSION: {original_exception}

What it means

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.

Solutions

  1. Set the api_version explicitly: os.environ['AZURE_API_VERSION'] = '2024-10-21' (or pass api_version=) for your deployment.
  2. Align versions: upgrade litellm to the latest release (pip install -U litellm) so its SDK adapter matches your openai-python.
  3. Verify the deployment's supported API versions in Azure Portal and pick a current GA version.
  4. If it persists, pin openai-python to the version litellm declares as tested.

Example fix

# before
litellm.completion(model="azure/dep", messages=msgs)  # AZURE_API_VERSION unset

# after
litellm.completion(
    model="azure/dep",
    messages=msgs,
    api_base=os.environ["AZURE_API_BASE"],
    api_key=os.environ["AZURE_API_KEY"],
    api_version="2024-10-21",
)
Defensive patterns

Strategy: validation

Validate before calling

import os
assert os.getenv("AZURE_API_VERSION"), "AZURE_API_VERSION must be set for azure deployments"
# or hard-set a known-good GA version
os.environ.setdefault("AZURE_API_VERSION", "2024-10-21")

Try / catch

try:
    resp = litellm.completion(model="azure/dep", **kwargs)
except litellm.BadRequestError as e:
    if "AZURE_API_VERSION" in str(e):
        kwargs["api_version"] = "2024-10-21"
        resp = litellm.completion(model="azure/dep", **kwargs)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/2c8dd484d341494b. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:2466

                    exception_type=exception_type,
                    exception_provider=exception_provider,
                    extra_information=extra_information,
                )
            if custom_llm_provider == "openrouter":
                _map_openrouter_exception(
                    model=model,
                    original_exception=mappable_exception,
                    custom_llm_provider=custom_llm_provider,
                    error_str=error_str,
                    exception_type=exception_type,
                    exception_provider=exception_provider,
                    extra_information=extra_information,
                )
        if "BadRequestError.__init__() missing 1 required positional argument: 'param'" in str(
            original_exception
        ):  # deal with edge-case invalid request error bug in openai-python sdk
            exception_mapping_worked = True
            raise BadRequestError(
                message=f"{exception_provider} BadRequestError : This can happen due to missing AZURE_API_VERSION: {original_exception}",
                model=model,
                llm_provider=custom_llm_provider,
                response=getattr(original_exception, "response", None),
            )
        else:  # ensure generic errors always return APIConnectionError=
            """
            For unmapped exceptions - raise the exception with traceback - https://github.com/BerriAI/litellm/issues/4201
            """
            exception_mapping_worked = True
            if hasattr(original_exception, "request"):
                raise APIConnectionError(
                    message=f"{exception_provider} - {error_str}",
                    llm_provider=custom_llm_provider,
                    model=model,
                    request=getattr(original_exception, "request", None),
                )
            else:

View on GitHub (pinned to 77b7c6c40c)