BerriAI/litellm · error · ValueError

api_base is required

Error message

api_base is required

What it means

Base Responses-API transformation raises ValueError when get_complete_url receives api_base=None. The Responses API (/v1/responses) needs a concrete host; the default implementation returns api_base unchanged, so a missing value is rejected immediately rather than producing a broken request URL.

Source

Thrown at litellm/llms/base_llm/responses/transformation.py:116

    @abstractmethod
    def validate_environment(self, headers: dict, model: str, litellm_params: GenericLiteLLMParams | None) -> dict:
        return {}

    @abstractmethod
    def get_complete_url(
        self,
        api_base: str | None,
        litellm_params: dict,
    ) -> str:
        """
        OPTIONAL

        Get the complete url for the request

        Some providers need `model` in `api_base`
        """
        if api_base is None:
            raise ValueError("api_base is required")
        return api_base

    @abstractmethod
    def transform_responses_api_request(
        self,
        model: str,
        input: str | ResponseInputParam,
        response_api_optional_request_params: dict,
        litellm_params: GenericLiteLLMParams,
        headers: dict,
    ) -> dict:
        pass

    @abstractmethod
    def transform_response_api_response(
        self,
        model: str,
        raw_response: httpx.Response,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_base in the call: litellm.responses(model=..., input=..., api_base='https://host').
  2. Set the provider base URL env var (OPENAI_API_BASE or <PROVIDER>_API_BASE).
  3. Add api_base to the proxy model's litellm_params in config.yaml.
  4. Provider config authors: override get_complete_url with the provider's responses endpoint default.

Example fix

# before
litellm.responses(model='openai/gpt-4o', input='hi')  # no base URL configured

# after
litellm.responses(model='openai/gpt-4o', input='hi', api_base='https://api.openai.com/v1')
Defensive patterns

Strategy: validation

Validate before calling

def assert_responses_ready(api_base: str | None) -> None:
    if not api_base and not os.environ.get('OPENAI_API_BASE'):
        raise ConfigError('responses API requires api_base')

Try / catch

try:
    litellm.responses(model=m, input=i)
except ValueError as e:
    if 'api_base is required' in str(e):
        return litellm.responses(model=m, input=i, api_base=DEFAULT_BASE_URL)
    raise

Prevention

When it happens

Trigger: Calling litellm.responses(...) for a provider with no resolvable base URL: custom_llm_provider without <PROVIDER>_API_BASE set, proxy model entry missing api_base, or a self-hosted endpoint configured only via env var that is absent in the runtime.

Common situations: Switching from chat completions (which had defaults) to the newer Responses API for a custom provider; env var naming mismatches (OPENAI_API_BASE vs OPENAI_BASE_URL); containerized deploys dropping env configuration.

Related errors


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