BerriAI/litellm · error · ValueError

api_base not set for LiteLLM Proxy route. Set in env via `LI

Error message

api_base not set for LiteLLM Proxy route. Set in env via `LITELLM_PROXY_API_BASE`

What it means

The image_generation transformation for the litellm_proxy provider targets {api_base}/images/generations on a downstream LiteLLM Proxy. It resolves api_base from the call parameter or LITELLM_PROXY_API_BASE and raises ValueError when neither is set, since it cannot construct the generations URL.

Source

Thrown at litellm/llms/litellm_proxy/image_generation/transformation.py:35

        api_key: str | None = None,
        api_base: str | None = None,
    ) -> dict:
        api_key = api_key or get_secret_str("LITELLM_PROXY_API_KEY")
        headers.update({"Authorization": f"Bearer {api_key}"})
        return headers

    def get_complete_url(
        self,
        api_base: str | None,
        api_key: str | None,
        model: str,
        optional_params: dict,
        litellm_params: dict,
        stream: bool | None = None,
    ) -> str:
        api_base = api_base or get_secret_str("LITELLM_PROXY_API_BASE")
        if api_base is None:
            raise ValueError("api_base not set for LiteLLM Proxy route. Set in env via `LITELLM_PROXY_API_BASE`")
        api_base = api_base.rstrip("/")
        return f"{api_base}/images/generations"

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. export LITELLM_PROXY_API_BASE="http://downstream-proxy:4000" and restart the service
  2. Or add api_base to the model_list entry's litellm_params for the litellm_proxy image model
  3. Verify with printenv LITELLM_PROXY_API_BASE inside the running container

Example fix

# before
img = litellm.image_generation(model="litellm_proxy/dall-e-3", prompt="a cat")

# after
img = litellm.image_generation(
    model="litellm_proxy/dall-e-3",
    prompt="a cat",
    api_base="http://downstream-proxy:4000",
)
Defensive patterns

Strategy: validation

Validate before calling

import os

def litellm_proxy_image_url() -> str:
    base = os.getenv("LITELLM_PROXY_API_BASE")
    if not base:
        raise ValueError("Set LITELLM_PROXY_API_BASE before generating images via the proxy")
    return f"{base.rstrip('/')}/images/generations"

Try / catch

try:
    img = litellm.image_generation(model="litellm_proxy/dall-e-3", prompt=p)
except ValueError as e:
    if "api_base not set for LiteLLM Proxy" in str(e):
        raise RuntimeError("Image route misconfigured: upstream proxy base missing") from e

Prevention

When it happens

Trigger: Calling image generation with model="litellm_proxy/..." while neither api_base nor LITELLM_PROXY_API_BASE is available to the process.

Common situations: Using a LiteLLM proxy as an image-generation backend but only configuring the key; env var defined in docker-compose but the service wasn't recreated; typo LITELLM_PROXY_APIBASE.

Related errors


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