BerriAI/litellm · error · ValueError

api_base is required

Error message

api_base is required

What it means

Thrown by the base evals transformation config when building the request URL for the Evals API (GET/POST /v1/evals). The get_complete_url helper refuses to construct '{api_base}/v1/{endpoint}' when api_base is None, because the resulting URL would be invalid. Every LiteLLM Evals provider config relies on this method, so a missing base URL fails fast before any HTTP call is made.

Source

Thrown at litellm/llms/base_llm/evals/transformation.py:81

    def get_complete_url(
        self,
        api_base: str | None,
        endpoint: str,
        eval_id: str | None = None,
    ) -> str:
        """
        Get the complete URL for the API request

        Args:
            api_base: Base API URL
            endpoint: API endpoint (e.g., 'evals', 'evals/{id}')
            eval_id: Optional eval ID for specific eval operations

        Returns:
            Complete URL
        """
        if api_base is None:
            raise ValueError("api_base is required")
        return f"{api_base}/v1/{endpoint}"

    @abstractmethod
    def transform_create_eval_request(
        self,
        create_request: CreateEvalRequest,
        litellm_params: GenericLiteLLMParams,
        headers: dict,
    ) -> dict:
        """
        Transform create eval request to provider-specific format

        Args:
            create_request: Eval creation parameters
            litellm_params: LiteLLM parameters
            headers: Request headers

        Returns:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_base explicitly in litellm_params (e.g. litellm_params={'api_base': 'https://your-host'}) when invoking evals APIs.
  2. Set the provider base URL env var (e.g. OPENAI_API_BASE or the matching <PROVIDER>_API_BASE) before the call.
  3. If using the proxy, add api_base to the model config entry (model_info/litellm_params) used for evals.
  4. Subclassing a BaseEvalConfig: override get_complete_url instead of relying on the default when your provider builds URLs differently.

Example fix

// before
await litellm.acreate_eval(create_request=req, litellm_params=GenericLiteLLMParams())  # api_base None -> ValueError

// after
params = GenericLiteLLMParams(api_base='https://api.openai.com')
await litellm.acreate_eval(create_request=req, litellm_params=params)
Defensive patterns

Strategy: validation

Validate before calling

from litellm import GenericLiteLLMParams

def can_build_eval_url(litellm_params: GenericLiteLLMParams) -> bool:
    return bool(getattr(litellm_params, 'api_base', None))

assert can_build_eval_url(params), 'Set api_base (or OPENAI_API_BASE) before calling evals APIs'

Try / catch

try:
    await litellm.acreate_eval(...)
except ValueError as e:
    if 'api_base is required' in str(e):
        raise ConfigError('Evals provider missing api_base') from e
    raise

Prevention

When it happens

Trigger: Calling litellm.eval creation/listing APIs for a provider whose config was instantiated without an api_base (e.g. custom/self-hosted evals endpoint), or passing litellm_params without api_base/api_key env vars set, so the resolved api_base arrives as None at get_complete_url(api_base=None, endpoint='evals').

Common situations: Running litellm.evals against a custom OpenAI-compatible endpoint while forgetting OPENAI_API_BASE / api_base param; proxy deployments where the evals router model entry lacks api_base; env var typos (OPENAI_BASE_URL vs OPENAI_API_BASE) in CI.

Related errors


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