Fosowl/agenticSeek · error · Exception

LiteLLM response is empty.

Error message

LiteLLM response is empty.

What it means

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.

Source

Thrown at sources/llm_provider.py:536

        except ImportError as e:
            raise ImportError("litellm is not installed. Install with: pip install litellm") from e

        if self.is_local:
            raise Exception("LiteLLM is not available for local use. Change config.ini")

        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__":

View on GitHub (pinned to ae57a23577)

Solutions

  1. Check the configured model name/prefix is a valid LiteLLM route (e.g. 'openai/gpt-4o-mini')
  2. Verify the LITELLM_API_KEY env var and provider account status
  3. Retry — upstream outages often resolve; the wrapper's catch-all will wrap the real cause as 'LiteLLM API error' on subsequent failures
  4. Inspect litellm verbose logging (litellm.set_verbose = True) to see what the gateway returned
Defensive patterns

Strategy: type-guard

Validate before calling

assert provider.model and '/' in provider.model, 'Use a LiteLLM model prefix like openai/gpt-4o-mini'
assert os.getenv('LITELLM_API_KEY'), 'LITELLM_API_KEY not set'

Type guard

def has_content(response) -> bool:
    return bool(response and response.choices and response.choices[0].message.content)

Try / catch

try:
    thought = provider.litellm_fn(history)
except Exception as e:
    if 'response is empty' in str(e):
        logger.warning('Empty LiteLLM response — check model name and provider status')
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30). Data as JSON: /api/errors/8f07a294e96a8531. Report an issue: GitHub.