{"record":{"id":"bd61a46f7cc8c33d","repo":"Fosowl/agenticSeek","slug":"openrouter-response-is-empty","errorCode":null,"errorMessage":"OpenRouter response is empty.","messagePattern":"OpenRouter response is empty\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":433,"sourceCode":"                raise  # Re-raise our custom exceptions\n            raise Exception(f\"Unexpected error: {str(e)}\") from e\n\n    def openrouter_fn(self, history, verbose=False):\n        \"\"\"\n        Use OpenRouter API to generate text.\n        \"\"\"\n        client = OpenAI(api_key=self.api_key, base_url=\"https://openrouter.ai/api/v1\")\n        if self.is_local:\n            # This case should ideally not be reached if unsafe_providers is set correctly\n            # and is_local is False in config for openrouter\n            raise Exception(\"OpenRouter is not available for local use. Change config.ini\")\n        try:\n            response = client.chat.completions.create(\n                model=self.model,\n                messages=history,\n            )\n            if response is None:\n                raise Exception(\"OpenRouter 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\"OpenRouter API error: {str(e)}\") from e\n\n    def minimax_fn(self, history, verbose=False):\n        \"\"\"\n        Use MiniMax API to generate text via OpenAI-compatible interface.\n\n        Supported models:\n        - MiniMax-M3: Latest flagship model with enhanced reasoning and coding (default)\n        - MiniMax-M2.7: Previous flagship, kept for compatibility\n        - MiniMax-M2.7-highspeed: High-speed version of M2.7 for low-latency scenarios\n\n        Note: temperature must be in range (0.0, 1.0], default is 1.0\n        \"\"\"","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L415-L451","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the model slug in config.ini exists on openrouter.ai/models","Check your OpenRouter account balance/credits and API key validity","Retry after a short delay if OpenRouter is having an outage (status.openrouter.ai)","Wrap the call so None is handled explicitly and a fallback model can be used"],"exampleFix":"// before\nmodel = \"openai/gpt-4-32k\"  # removed slug -> empty response\n// after\nmodel = \"openai/gpt-4o\"  # current valid slug","handlingStrategy":"type-guard","validationCode":"def openrouter_ready(api_key, model):\n    import os, requests\n    if not api_key or not os.getenv('OPENROUTER_API_KEY'):\n        return False\n    r = requests.get('https://openrouter.ai/api/v1/models', timeout=10)\n    return r.ok and any(m['id'] == model for m in r.json().get('data', []))","typeGuard":"def has_choices(resp):\n    return resp is not None and getattr(resp, 'choices', None) and resp.choices[0].message.content is not None","tryCatchPattern":"try:\n    out = provider.openrouter_fn(history)\nexcept Exception as e:\n    if 'response is empty' in str(e):\n        log.warning(\"OpenRouter returned empty response; check model slug and credits\")\n    raise","preventionTips":["Verify the model slug on openrouter.ai/models before use","Keep the account funded; monitor credit balance","Subscribe to OpenRouter status updates","Fall back to a secondary model when the primary returns empty"],"tags":["openrouter","empty-response","api"],"backgroundTag":"empty-api-response","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}