BerriAI/litellm · error · ValueError
api_base is required for LangGraph. Set it via LANGGRAPH_API
Error message
api_base is required for LangGraph. Set it via LANGGRAPH_API_BASE env var or api_base parameter.
What it means
The LangGraph provider builds its endpoint as {api_base}/runs/stream (streaming) or {api_base}/runs/wait (non-streaming) and has no default host. get_complete_url raises ValueError when api_base is None — it must be supplied via the api_base parameter or the LANGGRAPH_API_BASE environment variable (typically the LangGraph Platform/Agent Server URL).
Source
Thrown at litellm/llms/langgraph/chat/transformation.py:106
return optional_params
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:
"""
Get the complete URL for the LangGraph request.
Streaming: /runs/stream
Non-streaming: /runs/wait
"""
if api_base is None:
raise ValueError(
"api_base is required for LangGraph. Set it via LANGGRAPH_API_BASE env var or api_base parameter."
)
# Remove trailing slash if present
api_base = api_base.rstrip("/")
# Choose endpoint based on streaming mode
if stream:
return f"{api_base}/runs/stream"
else:
return f"{api_base}/runs/wait"
def _get_assistant_id(self, model: str, optional_params: dict) -> str:
"""
Get the assistant ID from model or optional_params.
model format: "langgraph/assistant_id" or just "assistant_id"
"""View on GitHub (pinned to 6c2dcb801b)
Solutions
- Set LANGGRAPH_API_BASE to your LangGraph server URL (e.g. https://my-agent.langgraph.com)
- Or pass api_base=... explicitly on the call / model_list entry
- For LiteLLM proxy, add api_base to the deployment's litellm_params for the langgraph model
- Confirm the env var is actually present in the process: printenv LANGGRAPH_API_BASE
Example fix
# before
litellm.completion(model="langgraph/my-agent", messages=msgs, api_key=lg_key)
# after
litellm.completion(
model="langgraph/my-agent",
messages=msgs,
api_key=lg_key,
api_base="https://my-agent.langgraph.com",
) Defensive patterns
Strategy: validation
Validate before calling
import os
def ensure_langgraph_config(api_base: str | None = None) -> str:
base = api_base or os.getenv("LANGGRAPH_API_BASE")
if not base:
raise ValueError("LANGGRAPH_API_BASE is not set; refusing to call LangGraph")
return base.rstrip("/") Try / catch
try:
litellm.completion(model="langgraph/agent", messages=msgs, api_base=ensure_langgraph_config())
except ValueError as e:
if "api_base is required for LangGraph" in str(e):
raise RuntimeError("Bootstrap error: LANGGRAPH_API_BASE missing in this environment") from e Prevention
- Pin LANGGRAPH_API_BASE (and LANGGRAPH_API_KEY) in the same env manifest for every environment
- Add a startup connectivity check against {base}/info or /runs before serving traffic
- Watch for the common typo LANGGRAPH_API_URL — assert the exact variable name in tests
When it happens
Trigger: Calling completion(model="langgraph/...", stream=True) with neither api_base nor LANGGRAPH_API_BASE set; env var defined only in the local shell but not in the deployed container/CI.
Common situations: Missing LANGGRAPH_API_BASE when integrating a LangGraph Deployment (e.g. https://my-deployment.langgraph.com); typo'd variable name (LANGGRAPH_API_URL); .env not loaded; proxy config lacking api_base on the langgraph model entry.
Related errors
- Missing `LLM_GUARD_API_BASE` from environment
- ANTHROPIC_API_BASE/ANTHROPIC_BASE_URL or ANTHROPIC_API_KEY/A
- Missing Azure Document Intelligence API Key - Set AZURE_DOCU
- Missing Azure Document Intelligence Endpoint - Set AZURE_DOC
- Missing Azure AI API Key - A call is being made to Azure AI
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/8c777f19824c8e13.
Report an issue: GitHub.