Fosowl/agenticSeek · error · Exception

OpenRouter response is empty.

Error message

OpenRouter response is empty.

What it means

openrouter_fn checks the chat completion response for None and raises 'OpenRouter response is empty.' if the SDK returned nothing. This guards against OpenRouter silently returning an empty object instead of a normal choices payload.

Source

Thrown at sources/llm_provider.py:433

                raise  # Re-raise our custom exceptions
            raise Exception(f"Unexpected error: {str(e)}") from e

    def openrouter_fn(self, history, verbose=False):
        """
        Use OpenRouter API to generate text.
        """
        client = OpenAI(api_key=self.api_key, base_url="https://openrouter.ai/api/v1")
        if self.is_local:
            # This case should ideally not be reached if unsafe_providers is set correctly
            # and is_local is False in config for openrouter
            raise Exception("OpenRouter is not available for local use. Change config.ini")
        try:
            response = client.chat.completions.create(
                model=self.model,
                messages=history,
            )
            if response is None:
                raise Exception("OpenRouter response is empty.")
            thought = response.choices[0].message.content
            if verbose:
                print(thought)
            return thought
        except Exception as e:
            raise Exception(f"OpenRouter API error: {str(e)}") from e

    def minimax_fn(self, history, verbose=False):
        """
        Use MiniMax API to generate text via OpenAI-compatible interface.

        Supported models:
        - MiniMax-M3: Latest flagship model with enhanced reasoning and coding (default)
        - MiniMax-M2.7: Previous flagship, kept for compatibility
        - MiniMax-M2.7-highspeed: High-speed version of M2.7 for low-latency scenarios

        Note: temperature must be in range (0.0, 1.0], default is 1.0
        """

View on GitHub (pinned to ae57a23577)

Solutions

  1. Verify the model slug in config.ini exists on openrouter.ai/models
  2. Check your OpenRouter account balance/credits and API key validity
  3. Retry after a short delay if OpenRouter is having an outage (status.openrouter.ai)
  4. Wrap the call so None is handled explicitly and a fallback model can be used

Example fix

// before
model = "openai/gpt-4-32k"  # removed slug -> empty response
// after
model = "openai/gpt-4o"  # current valid slug
Defensive patterns

Strategy: type-guard

Validate before calling

def openrouter_ready(api_key, model):
    import os, requests
    if not api_key or not os.getenv('OPENROUTER_API_KEY'):
        return False
    r = requests.get('https://openrouter.ai/api/v1/models', timeout=10)
    return r.ok and any(m['id'] == model for m in r.json().get('data', []))

Type guard

def has_choices(resp):
    return resp is not None and getattr(resp, 'choices', None) and resp.choices[0].message.content is not None

Try / catch

try:
    out = provider.openrouter_fn(history)
except Exception as e:
    if 'response is empty' in str(e):
        log.warning("OpenRouter returned empty response; check model slug and credits")
    raise

Prevention

When it happens

Trigger: client.chat.completions.create(...) returns None — typically when OpenRouter returns an empty body, the requested model is unavailable/deprecated and routed to nothing, or the account has no credits and the relay returns an empty 200.

Common situations: OpenRouter model slug invalid or removed; free-tier model temporarily unavailable; account out of credits so the relay yields an empty response; transient OpenRouter outage returning empty bodies.

Related errors


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