{"record":{"id":"cf3d01e1891477b4","repo":"nexu-io/open-design","slug":"openrouter-selected-but-openrouter-api-key-is-not","errorCode":null,"errorMessage":"OpenRouter selected but OPENROUTER_API_KEY is not configured.","messagePattern":"OpenRouter selected but OPENROUTER_API_KEY is not configured\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"design-templates/last30days/scripts/lib/providers.py","lineNumber":328,"sourceCode":"            config.get(\"OPENAI_CHATGPT_ACCOUNT_ID\"),\n        )\n\n    if provider_name == \"xai\":\n        if not xai_key:\n            raise RuntimeError(\"xAI selected but XAI_API_KEY is not configured.\")\n        runtime = schema.ProviderRuntime(\n            reasoning_provider=\"xai\",\n            planner_model=planner_model,\n            rerank_model=rerank_model,\n\n            x_search_backend=_resolve_x_backend(config),\n        )\n        return runtime, XAIClient(xai_key)\n\n    if provider_name == \"openrouter\":\n        openrouter_key = config.get(\"OPENROUTER_API_KEY\")\n        if not openrouter_key:\n            raise RuntimeError(\"OpenRouter selected but OPENROUTER_API_KEY is not configured.\")\n        runtime = schema.ProviderRuntime(\n            reasoning_provider=\"openrouter\",\n            planner_model=planner_model,\n            rerank_model=rerank_model,\n            x_search_backend=_resolve_x_backend(config),\n        )\n        return runtime, OpenRouterClient(openrouter_key)\n\n    raise RuntimeError(f\"Unsupported reasoning provider: {provider_name}\")\n\n\ndef _resolve_x_backend(config: dict[str, Any]) -> str | None:\n    preferred = (config.get(\"LAST30DAYS_X_BACKEND\") or \"\").lower()\n    if preferred in {\"xai\", \"bird\"}:\n        return preferred\n    return env.get_x_source(config)\n\n","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/design-templates/last30days/scripts/lib/providers.py#L310-L346","documentation":"Raised in resolve_runtime when provider_name is 'openrouter' but config.get('OPENROUTER_API_KEY') is empty. OpenRouter is read lazily (the key is fetched inside the branch, not at function top), so a missing key aborts right before OpenRouterClient construction.","triggerScenarios":"LAST30DAYS_REASONING_PROVIDER=openrouter without OPENROUTER_API_KEY. Auto-resolution can also reach here only if OPENROUTER_API_KEY was truthy at selection time but became falsy between selection and the branch (rare; usually means explicit selection).","commonSituations":"Using OpenRouter as a fallback provider in CI without injecting the secret. Key named OPENROUTER_KEY instead of OPENROUTER_API_KEY.","solutions":["Set OPENROUTER_API_KEY to a key from openrouter.ai/keys.","If you do not have one, switch provider to gemini/xai/openai/auto as available.","Verify the exact env-var name: OPENROUTER_API_KEY (not OPENROUTER_KEY)."],"exampleFix":"# before\nLAST30DAYS_REASONING_PROVIDER=openrouter\n\n# after\nLAST30DAYS_REASONING_PROVIDER=openrouter\nOPENROUTER_API_KEY=sk-or-...","handlingStrategy":"validation","validationCode":"def ensure_openrouter_key(config):\n    key = config.get(\"OPENROUTER_API_KEY\")\n    if not key:\n        raise RuntimeError(\"OpenRouter provider requires OPENROUTER_API_KEY (exact name).\")\n    return key","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use the exact env-var name OPENROUTER_API_KEY (not OPENROUTER_KEY).","Treat OpenRouter as the last-resort fallback in 'auto' mode and confirm its key in pre-flight.","Keep a single credential manifest mapping provider -> required env vars."],"tags":["config","credentials","openrouter","provider"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}