BerriAI/litellm · error · ValueError
api_base is required
Error message
api_base is required
What it means
This is the default get_complete_url in the base chat transformation config: if a provider config does not override URL building, the api_base string is used verbatim as the request URL, so None is rejected. Seeing it means your provider's request reached URL construction with no resolvable base URL.
Source
Thrown at litellm/llms/base_llm/chat/transformation.py:294
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:
"""
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_request(
self,
model: str,
messages: list[AllMessageValues],
optional_params: dict,
litellm_params: dict,
headers: dict,
) -> dict:
pass
async def async_transform_request(
self,
model: str,
messages: list[AllMessageValues],
optional_params: dict,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass the endpoint: litellm.completion(model='openai/my-model', ..., api_base='http://localhost:8000/v1') (or base_url)
- Set the matching env var for the provider (e.g. OPENAI_API_BASE for openai/ prefixed models)
- In proxy config.yaml, add api_base to the model's litellm_params
- Verify the provider prefix in the model string matches the config you intended (model='openai/...' vs 'ollama/...')
Example fix
# before litellm.completion(model='openai/my-finetune', messages=msgs, api_key=k) # after litellm.completion(model='openai/my-finetune', messages=msgs, api_key=k, api_base='https://my-endpoint.example.com/v1')
Defensive patterns
Strategy: validation
Validate before calling
api_base = os.environ.get('OPENAI_API_BASE') or kwargs.get('api_base')
assert api_base, 'This provider requires api_base/base_url' Try / catch
try:
litellm.completion(model=model, messages=msgs)
except ValueError as e:
if str(e) == 'api_base is required':
raise ConfigurationError(f'{model} needs an explicit endpoint') from e
raise Prevention
- Always set base_url for openai-compatible and custom providers
- Keep provider env var names in one checked constants module
When it happens
Trigger: Using a provider/config combo whose get_complete_url is not overridden, with api_base=None and no provider-specific env var resolving it (OPENAI_API_BASE-style fallbacks belong to overridden configs). Common with custom/openai-compatible providers where you forgot base_url.
Common situations: Calling a custom/openai-compatible provider (model like 'openai/...' or a custom handler) without base_url/api_base; env var typos (OPENAI_BASE_URL vs OPENAI_API_BASE); proxy model entries missing api_base for openai-compatible endpoints.
Related errors
- api_base is required
- Missing Azure AI API Base - Set AZURE_AI_API_BASE environmen
- Azure AI API Base is required. api_base=None. Set in call or
- Azure AI API Base must be an absolute URL including scheme (
- NVIDIA Riva requires `api_base` (host:port for the gRPC endp
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/25cea10af337ed31.
Report an issue: GitHub.