Fosowl/agenticSeek · error · Exception
LiteLLM API error: {str(e)}
Error message
LiteLLM API error: {str(e)} What it means
litellm_fn wraps the entire completion flow in a broad except Exception and re-raises a single Exception 'LiteLLM API error: <original>'. Any failure from litellm.completion — auth, bad model name, quota, timeouts, provider errors — surfaces under this uniform message with the real cause appended and chained (__cause__).
Source
Thrown at sources/llm_provider.py:542
api_key = os.getenv("LITELLM_API_KEY", None)
try:
call_kwargs = {
"model": self.model,
"messages": history,
"drop_params": True,
}
if api_key:
call_kwargs["api_key"] = api_key
response = litellm.completion(**call_kwargs)
if response is None:
raise Exception("LiteLLM response is empty.")
thought = response.choices[0].message.content
if verbose:
print(thought)
return thought
except Exception as e:
raise Exception(f"LiteLLM API error: {str(e)}") from e
def test_fn(self, history, verbose=True):
"""
This function is used to conduct tests.
"""
thought = """
\n\n```json\n{\n \"plan\": [\n {\n \"agent\": \"Web\",\n \"id\": \"1\",\n \"need\": null,\n \"task\": \"Conduct a comprehensive web search to identify at least five AI startups located in Osaka. Use reliable sources and websites such as Crunchbase, TechCrunch, or local Japanese business directories. Capture the company names, their websites, areas of expertise, and any other relevant details.\"\n },\n {\n \"agent\": \"Web\",\n \"id\": \"2\",\n \"need\": null,\n \"task\": \"Perform a similar search to find at least five AI startups in Tokyo. Again, use trusted sources like Crunchbase, TechCrunch, or Japanese business news websites. Gather the same details as for Osaka: company names, websites, areas of focus, and additional information.\"\n },\n {\n \"agent\": \"File\",\n \"id\": \"3\",\n \"need\": [\"1\", \"2\"],\n \"task\": \"Create a new text file named research_japan.txt in the user's home directory. Organize the data collected from both searches into this file, ensuring it is well-structured and formatted for readability. Include headers for Osaka and Tokyo sections, followed by the details of each startup found.\"\n }\n ]\n}\n```
"""
return thought
if __name__ == "__main__":
provider = Provider("server", "deepseek-r1:32b", " x.x.x.x:8080")
res = provider.respond(["user", "Hello, how are you?"])
print("Response:", res)
View on GitHub (pinned to ae57a23577)
Solutions
- Read the chained suffix (str(e)) — it contains the underlying provider error
- Validate the model string format '<provider>/<model>' per LiteLLM docs
- Ensure LITELLM_API_KEY is set and valid for the target provider (or pass api_key explicitly)
- Catch specific litellm exceptions (AuthenticationError, RateLimitError) around the call for better handling
- Update litellm if a provider changed its API surface
Example fix
// before
thought = provider.litellm_fn(history)
// after
import litellm
litellm.suppress_debug_info = True
try:
thought = provider.litellm_fn(history)
except Exception as e:
logger.error('LiteLLM failed: %s', e.__cause__ or e)
raise Defensive patterns
Strategy: try-catch
Validate before calling
import importlib.util
assert importlib.util.find_spec('litellm'), 'pip install litellm'
assert provider.model and not provider.is_local, 'Cloud model with provider prefix required'
assert os.getenv('LITELLM_API_KEY'), 'LITELLM_API_KEY not set' Type guard
def unwrap_litellm_error(e: BaseException):
return e.__cause__ if isinstance(e, Exception) and e.__cause__ else e Try / catch
try:
thought = provider.litellm_fn(history)
except Exception as e:
cause = e.__cause__ or e
logger.error('LiteLLM failure: %s: %s', type(cause).__name__, cause)
raise Prevention
- Always inspect e.__cause__ — the wrapper hides the real provider error
- Validate model strings against LiteLLM's provider/model catalog
- Rotate and test API keys before long-running jobs
- Pin the litellm version and upgrade deliberately, checking provider changelogs
- Catch litellm-specific exceptions upstream for finer-grained handling
When it happens
Trigger: Calling litellm_fn(history) when litellm.completion raises anything: invalid model prefix, missing/invalid LITELLM_API_KEY, provider quota exceeded, rate limits, network failures, or malformed call_kwargs.
Common situations: Wrong model string (missing provider prefix like 'openai/'); expired or absent API key; free-tier quota exhausted; LiteLLM SDK version incompatibility with a provider's API changes.
Related errors
- Provider {self.provider_name} failed: {str(e)}
- OpenAI API error: {str(e)}
- Anthropic API error: {str(e)}
- LiteLLM response is empty.
- GOOGLE API error: {str(e)}
AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30).
Data as JSON: /api/errors/02b57a306576afce.
Report an issue: GitHub.