BerriAI/litellm · error · ValueError
api_base is required for Pydantic AI agents
Error message
api_base is required for Pydantic AI agents
What it means
PydanticAIProviderConfig.handle_streaming raises ValueError when api_base is falsy. Streaming for Pydantic AI is simulated (fake streaming) from a non-streaming HTTP call, which still requires the agent's base URL.
Source
Thrown at litellm/a2a_protocol/providers/pydantic_ai_agents/config.py:47
raise ValueError("api_base is required for PydanticAIProviderConfig")
return await PydanticAIHandler.handle_non_streaming(
request_id=request_id,
params=params,
api_base=api_base,
timeout=kwargs.get("timeout", 60.0),
agent_extra_headers=kwargs.get("agent_extra_headers"),
)
async def handle_streaming(
self,
request_id: str,
params: dict[str, Any],
api_base: str | None = None,
**kwargs,
) -> AsyncIterator[dict[str, Any]]:
"""Handle streaming request with fake streaming."""
if not api_base:
raise ValueError("api_base is required for Pydantic AI agents")
async for chunk in PydanticAIHandler.handle_streaming(
request_id=request_id,
params=params,
api_base=api_base,
timeout=kwargs.get("timeout", 60.0),
chunk_size=kwargs.get("chunk_size", 50),
delay_ms=kwargs.get("delay_ms", 10),
agent_extra_headers=kwargs.get("agent_extra_headers"),
):
yield chunk
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Provide a non-empty api_base in the call/deployment config
- Verify the api_base env/config variable resolves at request time (not an unset env default of '')
Example fix
# before
async for c in config.handle_streaming(request_id=rid, params=params, api_base=os.getenv("AGENT_URL")): ...
# after
base = os.environ["AGENT_URL"] # fail fast if unset
async for c in config.handle_streaming(request_id=rid, params=params, api_base=base): ... Defensive patterns
Strategy: validation
Validate before calling
if not api_base:
raise ValueError("pydantic-ai streaming requires api_base") Prevention
- Never default api_base to '' from env vars; use required lookup
- Assert api_base before entering streaming code paths
When it happens
Trigger: Calling handle_streaming on the pydantic_ai_agents config with api_base=None or empty string.
Common situations: Streaming requests through a gateway where the deployment lacks api_base; passing "" from an env var that was never set.
Related errors
- api_base is required for PydanticAIProviderConfig
- api_base is required for Pydantic AI agents
- Either a2a_client or api_base is required for standard A2A f
- Task {task_id} ended with state: {state}
- Task {task_id} did not complete within {max_attempts * poll_
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/87d64d942d36f27c.
Report an issue: GitHub.