BerriAI/litellm · error · HerokuError
No api base was set. Please provide an api_base, or set the…
Error message
No api base was set. Please provide an api_base, or set the HEROKU_API_BASE environment variable.
What it means
Heroku's chat completion integration in LiteLLM is OpenAI-compatible but has no default base URL. In get_complete_url(), _get_openai_compatible_provider_info() resolves the api_base argument against the HEROKU_API_BASE environment variable; if both are empty, HerokuError is raised before any HTTP request is made. LiteLLM would otherwise append /v1/chat/completions to the base.
Solutions
- Pass the endpoint explicitly: litellm.completion(model='heroku/<model>', api_base='https://<your-app>.herokuapp.com', api_key=...)
- Or export HEROKU_API_BASE=https://<your-app>.herokuapp.com and verify the running process sees it (printenv HEROKU_API_BASE)
- Do not append /v1/chat/completions yourself — LiteLLM adds it if the base does not already end with it
- Smoke-test the base URL with curl <api_base>/v1/models to confirm it is live
Example fix
# before
litellm.completion(model="heroku/meta-llama/Llama-4-Scout-17B-16E-Instruct", messages=msgs)
# after
litellm.completion(
model="heroku/meta-llama/Llama-4-Scout-17B-16E-Instruct",
api_base="https://your-inference-app.herokuapp.com",
api_key=os.environ["HEROKU_API_KEY"],
messages=msgs,
) Defensive patterns
Strategy: validation
Validate before calling
import os
def heroku_ready(api_base: str | None = None) -> bool:
return bool(api_base or os.getenv("HEROKU_API_BASE"))
if not heroku_ready(api_base):
raise SystemExit("Set HEROKU_API_BASE or pass api_base before calling heroku models") Prevention
- Centralize provider config: resolve api_base + api_key once at startup and fail fast if missing
- Add a startup check for HEROKU_API_BASE in deployed environments (container, CI) where .env files are easy to miss
- Use a thin wrapper around litellm.completion that injects api_base for heroku/* models so callers cannot forget it
When it happens
Trigger: litellm.completion(model='heroku/<model>', ...) invoked without api_base=... and without HEROKU_API_BASE set in the process environment. Also triggered when the env var is set in a .env file that the running process never loaded.
Common situations: First-time Heroku Inference AI setup where the deployed endpoint URL was never configured; a typo'd env var name (e.g. HEROKU_API_URL); passing api_key but forgetting api_base; deploying to a container/platform where the env var did not propagate.
Related errors
- api_base is required
- api_base is required for hosted_vllm embeddings
- api_base must be provided for Hosted VLLM rerank
- api base needs to be a string. api_base=
- api_base not set for Hosted VLLM responses API. Set via…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/1cb7276460b791a4.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/heroku/chat/transformation.py:70
) -> tuple[str | None, str | None]:
api_base = api_base or os.getenv("HEROKU_API_BASE")
api_key = api_key or os.getenv("HEROKU_API_KEY")
return api_base, api_key
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, _ = self._get_openai_compatible_provider_info(api_base, api_key)
if not api_base:
raise HerokuError(
"No api base was set. Please provide an api_base, or set the HEROKU_API_BASE environment variable."
)
if not api_base.endswith("/v1/chat/completions"):
api_base = f"{api_base}/v1/chat/completions"
return api_base
View on GitHub (pinned to 77b7c6c40c)