{"record":{"id":"dbf6f6cad969c98b","repo":"mvanhorn/last30days-skill","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":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"skills/last30days/scripts/lib/providers.py","lineNumber":305,"sourceCode":"            openai_token\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    \"\"\"Resolve the X backend for runtime fetch.\n\n    Delegates to env.get_x_source which handles:\n    - Any known pin (X_BACKEND_KNOWN) exclusively: returns pin if available, None otherwise\n    - Unpinned: walks auto-chain (X_BACKEND_ORDER) only, never auto-selects opt-in backends\n    \"\"\"","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/mvanhorn/last30days-skill/blob/c7460f6114449ddfe6ea3fc2f23c3d910c0e740c/skills/last30days/scripts/lib/providers.py#L287-L323","documentation":"RuntimeError raised in resolve_runtime when provider is 'openrouter' but OPENROUTER_API_KEY is absent from config. Unlike the big-three providers the key is read inline from the config dict at this branch, so it must be present in whatever env/.env layer populates config.","triggerScenarios":"LAST30DAYS_REASONING_PROVIDER=openrouter with OPENROUTER_API_KEY not set in the environment or ~/.config/last30days/.env; or set in the shell but the engine was launched from another context (cron, harness gateway) without it.","commonSituations":"OpenRouter key obtained from openrouter.ai/keys but never added to config; per-harness env inheritance gaps (gateway processes stripping env); typo'd variable name.","solutions":["Add OPENROUTER_API_KEY to the loaded env layer (.env file or process env)","Verify the harness/gateway invoking the engine passes the variable through","Test with a trivial config load before the full run to confirm the key resolves"],"exampleFix":"# before\nLAST30DAYS_REASONING_PROVIDER=openrouter\n# no OPENROUTER_API_KEY\n\n# after\nLAST30DAYS_REASONING_PROVIDER=openrouter\nOPENROUTER_API_KEY=sk-or-v1-...","handlingStrategy":"validation","validationCode":"if (os.environ.get(\"LAST30DAYS_REASONING_PROVIDER\") or \"\").lower() == \"openrouter\":\n    if not os.environ.get(\"OPENROUTER_API_KEY\"):\n        raise SystemExit(\"Set OPENROUTER_API_KEY before selecting the openrouter provider\")","typeGuard":"def openrouter_ready(config: dict) -> bool:\n    provider = (config.get(\"LAST30DAYS_REASONING_PROVIDER\") or \"gemini\").lower()\n    return provider != \"openrouter\" or bool(config.get(\"OPENROUTER_API_KEY\"))","tryCatchPattern":"try:\n    runtime, client = resolve_runtime(config, depth)\nexcept RuntimeError as e:\n    if \"OPENROUTER_API_KEY\" in str(e):\n        set_key_via_setup(\"OPENROUTER_API_KEY\")","preventionTips":["Create the key at openrouter.ai/keys and store it in the loaded .env layer","Verify gateway/harness processes pass the env var through to the engine","Smoke-test config loading before long runs"],"tags":["providers","openrouter","credentials","configuration"],"backgroundTag":null,"analyzedSha":"c7460f6114449ddfe6ea3fc2f23c3d910c0e740c","analyzedAt":"2026-08-15T03:34:49.540Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}