{"record":{"id":"02b57a306576afce","repo":"Fosowl/agenticSeek","slug":"litellm-api-error-str-e","errorCode":null,"errorMessage":"LiteLLM API error: {str(e)}","messagePattern":"LiteLLM API error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":542,"sourceCode":"        api_key = os.getenv(\"LITELLM_API_KEY\", None)\n\n        try:\n            call_kwargs = {\n                \"model\": self.model,\n                \"messages\": history,\n                \"drop_params\": True,\n            }\n            if api_key:\n                call_kwargs[\"api_key\"] = api_key\n            response = litellm.completion(**call_kwargs)\n            if response is None:\n                raise Exception(\"LiteLLM response is empty.\")\n            thought = response.choices[0].message.content\n            if verbose:\n                print(thought)\n            return thought\n        except Exception as e:\n            raise Exception(f\"LiteLLM API error: {str(e)}\") from e\n\n    def test_fn(self, history, verbose=True):\n        \"\"\"\n        This function is used to conduct tests.\n        \"\"\"\n        thought = \"\"\"\n\\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```\n        \"\"\"\n        return thought\n\n\nif __name__ == \"__main__\":\n    provider = Provider(\"server\", \"deepseek-r1:32b\", \" x.x.x.x:8080\")\n    res = provider.respond([\"user\", \"Hello, how are you?\"])\n    print(\"Response:\", res)\n","sourceCodeStart":524,"sourceCodeEnd":558,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L524-L558","documentation":"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__).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nthought = provider.litellm_fn(history)\n// after\nimport litellm\nlitellm.suppress_debug_info = True\ntry:\n    thought = provider.litellm_fn(history)\nexcept Exception as e:\n    logger.error('LiteLLM failed: %s', e.__cause__ or e)\n    raise","handlingStrategy":"try-catch","validationCode":"import importlib.util\nassert importlib.util.find_spec('litellm'), 'pip install litellm'\nassert provider.model and not provider.is_local, 'Cloud model with provider prefix required'\nassert os.getenv('LITELLM_API_KEY'), 'LITELLM_API_KEY not set'","typeGuard":"def unwrap_litellm_error(e: BaseException):\n    return e.__cause__ if isinstance(e, Exception) and e.__cause__ else e","tryCatchPattern":"try:\n    thought = provider.litellm_fn(history)\nexcept Exception as e:\n    cause = e.__cause__ or e\n    logger.error('LiteLLM failure: %s: %s', type(cause).__name__, cause)\n    raise","preventionTips":["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"],"tags":["litellm","api-error","error-wrapping","authentication"],"backgroundTag":"api-error-wrapped","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}