BerriAI/litellm · error · BadRequestError

{exception_provider} BadRequestError : This can happen due t

Error message

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

What it means

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.

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 6c2dcb801b)

Solutions

  1. Set the Azure API version explicitly: os.environ['AZURE_API_VERSION']='2024-06-01' or pass api_version in the call.
  2. Prefer the full deployment format 'azure/<deployment-name>' with api_base, api_key, api_version all provided.
  3. Pin/upgrade openai-python to a version compatible with your litellm release.

Example fix

# before
litellm.completion(model='azure/my-deploy', messages=msgs, api_key=k, api_base=b)

# after
litellm.completion(model='azure/my-deploy', messages=msgs, api_key=k, api_base=b, api_version='2024-06-01')
Defensive patterns

Strategy: validation

Validate before calling

import os

def azure_config_valid() -> bool:
    return bool(os.getenv('AZURE_API_KEY') and os.getenv('AZURE_API_BASE') and os.getenv('AZURE_API_VERSION'))

Try / catch

try {
  await litellm.completion({ model: 'azure/deploy', ... });
} catch (e) {
  if (e instanceof litellm.BadRequestError && /AZURE_API_VERSION/.test(e.message)) { /* set api_version and retry */ }
}

Prevention

When it happens

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

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

Related errors


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