BerriAI/litellm · error · ValueError

api_base is required

Error message

api_base is required

What it means

Thrown by the base image-edit transformation when get_complete_url is called with api_base=None. The default implementation simply returns api_base for OpenAI-style providers, so a None base URL (nothing to POST the multipart edit to) is rejected up front with a clear ValueError.

Source

Thrown at litellm/llms/base_llm/image_edit/transformation.py:90

    ) -> dict:
        return {}

    @abstractmethod
    def get_complete_url(
        self,
        model: str,
        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_image_edit_request(
        self,
        model: str,
        prompt: str | None,
        image: FileTypes | None,
        image_edit_optional_request_params: dict,
        litellm_params: GenericLiteLLMParams,
        headers: dict,
    ) -> tuple[dict, RequestFiles]:
        pass

    def finalize_image_edit_request_data(self, data: dict, resolved_request_url: str) -> dict:
        """
        Last pass on the request dict after ``transform_image_edit_request``, using the
        exact URL string used for the HTTP POST (same as ``get_complete_url`` output).

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_base in the call: litellm.image_edit(..., api_base='https://your-host/v1').
  2. Set the provider's base URL env var (e.g. OPENAI_API_BASE) before calling.
  3. In proxy deployments, add api_base to the model's litellm_params in config.yaml.
  4. Custom provider: override get_complete_url in your config class to construct the URL from your own defaults.

Example fix

# before
resp = litellm.image_edit(model='my-provider/gpt-image-1', prompt='add a hat', image=f)

# after
resp = litellm.image_edit(model='my-provider/gpt-image-1', prompt='add a hat', image=f,
                           api_base='https://my-provider.example.com/v1/images/edits')
Defensive patterns

Strategy: validation

Validate before calling

def assert_image_edit_ready(api_base: str | None) -> None:
    if not api_base:
        raise ConfigError('image_edit requires api_base or OPENAI_API_BASE')

Try / catch

try:
    litellm.image_edit(...)
except ValueError as e:
    if 'api_base is required' in str(e):
        api_base = os.environ.get('OPENAI_API_BASE')
        if not api_base:
            raise
        return litellm.image_edit(..., api_base=api_base)
    raise

Prevention

When it happens

Trigger: Calling litellm.image_edit for a provider whose config/params leave api_base unset — e.g. custom OpenAI-compatible host without OPENAI_API_BASE, a proxy model entry missing api_base, or a provider subclass that forgot to override get_complete_url and also lacks a base URL.

Common situations: Running image edits against Azure/OpenAI-compatible deployments without setting the base URL env var; new custom provider configs that define transform_image_edit_request but rely on the default get_complete_url; dockerized deployments losing env vars.

Related errors


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