{"record":{"id":"8f07a294e96a8531","repo":"Fosowl/agenticSeek","slug":"litellm-response-is-empty","errorCode":null,"errorMessage":"LiteLLM response is empty.","messagePattern":"LiteLLM response is empty\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":536,"sourceCode":"        except ImportError as e:\n            raise ImportError(\"litellm is not installed. Install with: pip install litellm\") from e\n\n        if self.is_local:\n            raise Exception(\"LiteLLM is not available for local use. Change config.ini\")\n\n        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__\":","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L518-L554","documentation":"litellm_fn treats a None return from litellm.completion() as a failure and raises 'LiteLLM response is empty.' This guards against the gateway returning no object at all, which would otherwise cause an opaque AttributeError on response.choices.","triggerScenarios":"Calling litellm_fn(history) when litellm.completion(**call_kwargs) returns None despite not raising — rare, typically after an upstream provider silently fails or a mocked/stubbed completion returns None in tests.","commonSituations":"Upstream provider outage returning an empty/None-mapped response; misconfigured model prefix causing degenerate behavior; unit tests where litellm.completion is mocked to return None.","solutions":["Check the configured model name/prefix is a valid LiteLLM route (e.g. 'openai/gpt-4o-mini')","Verify the LITELLM_API_KEY env var and provider account status","Retry — upstream outages often resolve; the wrapper's catch-all will wrap the real cause as 'LiteLLM API error' on subsequent failures","Inspect litellm verbose logging (litellm.set_verbose = True) to see what the gateway returned"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"assert provider.model and '/' in provider.model, 'Use a LiteLLM model prefix like openai/gpt-4o-mini'\nassert os.getenv('LITELLM_API_KEY'), 'LITELLM_API_KEY not set'","typeGuard":"def has_content(response) -> bool:\n    return bool(response and response.choices and response.choices[0].message.content)","tryCatchPattern":"try:\n    thought = provider.litellm_fn(history)\nexcept Exception as e:\n    if 'response is empty' in str(e):\n        logger.warning('Empty LiteLLM response — check model name and provider status')\n    raise","preventionTips":["Use fully-qualified model names with provider prefixes","Verify API key and provider account/quota status before batches","Check upstream provider status pages during outages","Avoid mocking litellm.completion to return None in tests without expecting this error"],"tags":["empty-response","litellm","api-error","null-check"],"backgroundTag":"empty-api-response","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}