BerriAI/litellm · error · ValueError

api_base is required for Infinity embeddings

Error message

api_base is required for Infinity embeddings

What it means

Raised by the Infinity embedding config when building the request URL: Infinity is a self-hosted service, so there is no default host and api_base must be provided (e.g. http://localhost:7111). Without it the URL cannot be constructed and a ValueError aborts the call.

Source

Thrown at litellm/llms/infinity/embedding/transformation.py:33

class InfinityEmbeddingConfig(BaseEmbeddingConfig):
    """
    Reference: https://infinity.modal.michaelfeil.eu/docs
    """

    def __init__(self) -> None:
        pass

    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:
        if api_base is None:
            raise ValueError("api_base is required for Infinity embeddings")
        # Remove trailing slashes and ensure clean base URL
        api_base = api_base.rstrip("/")
        if not api_base.endswith("/embeddings"):
            api_base = f"{api_base}/embeddings"
        return api_base

    def validate_environment(
        self,
        headers: dict,
        model: str,
        messages: list[AllMessageValues],
        optional_params: dict,
        litellm_params: dict,
        api_key: str | None = None,
        api_base: str | None = None,
    ) -> dict:
        if api_key is None:
            api_key = get_secret_str("INFINITY_API_KEY")

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_base: litellm.embedding(model='infinity/BAAI/bge-m3', input=texts, api_base='http://localhost:7111').
  2. In litellm proxy config, set api_base on the infinity model entry.
  3. Ensure the Infinity server is reachable at that base (curl http://host:port/models).

Example fix

# before
litellm.embedding(model='infinity/BAAI/bge-m3', input=texts)

# after
litellm.embedding(model='infinity/BAAI/bge-m3', input=texts, api_base='http://localhost:7111')
Defensive patterns

Strategy: validation

Validate before calling

def get_infinity_base() -> str:
    base = os.environ.get('INFINITY_API_BASE') or 'http://localhost:7111'
    if not base.startswith(('http://', 'https://')):
        raise ValueError(f'invalid Infinity api_base: {base!r}')
    return base

Type guard

def is_valid_api_base(base: object) -> bool:
    return isinstance(base, str) and base.startswith(('http://', 'https://')) and len(base) > len('http://')

Prevention

When it happens

Trigger: litellm.embedding(model='infinity/<model>', input=[...]) without api_base=... and without an api_base in the proxy/model config.

Common situations: Copying example code that omits api_base, forgetting to set api_base in the litellm proxy model entry, or a typo like api_bass/api-base in kwargs.

Related errors


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