nexu-io/open-design · error · RuntimeError

OpenRouter selected but OPENROUTER_API_KEY is not configured

Error message

OpenRouter selected but OPENROUTER_API_KEY is not configured.

What it means

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.

Source

Thrown at design-templates/last30days/scripts/lib/providers.py:328

            config.get("OPENAI_CHATGPT_ACCOUNT_ID"),
        )

    if provider_name == "xai":
        if not xai_key:
            raise RuntimeError("xAI selected but XAI_API_KEY is not configured.")
        runtime = schema.ProviderRuntime(
            reasoning_provider="xai",
            planner_model=planner_model,
            rerank_model=rerank_model,

            x_search_backend=_resolve_x_backend(config),
        )
        return runtime, XAIClient(xai_key)

    if provider_name == "openrouter":
        openrouter_key = config.get("OPENROUTER_API_KEY")
        if not openrouter_key:
            raise RuntimeError("OpenRouter selected but OPENROUTER_API_KEY is not configured.")
        runtime = schema.ProviderRuntime(
            reasoning_provider="openrouter",
            planner_model=planner_model,
            rerank_model=rerank_model,
            x_search_backend=_resolve_x_backend(config),
        )
        return runtime, OpenRouterClient(openrouter_key)

    raise RuntimeError(f"Unsupported reasoning provider: {provider_name}")


def _resolve_x_backend(config: dict[str, Any]) -> str | None:
    preferred = (config.get("LAST30DAYS_X_BACKEND") or "").lower()
    if preferred in {"xai", "bird"}:
        return preferred
    return env.get_x_source(config)

View on GitHub (pinned to 5be4028344)

Solutions

  1. Set OPENROUTER_API_KEY to a key from openrouter.ai/keys.
  2. If you do not have one, switch provider to gemini/xai/openai/auto as available.
  3. Verify the exact env-var name: OPENROUTER_API_KEY (not OPENROUTER_KEY).

Example fix

# before
LAST30DAYS_REASONING_PROVIDER=openrouter

# after
LAST30DAYS_REASONING_PROVIDER=openrouter
OPENROUTER_API_KEY=sk-or-...
Defensive patterns

Strategy: validation

Validate before calling

def ensure_openrouter_key(config):
    key = config.get("OPENROUTER_API_KEY")
    if not key:
        raise RuntimeError("OpenRouter provider requires OPENROUTER_API_KEY (exact name).")
    return key

Type guard

null

Try / catch

null

Prevention

When it happens

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

Common situations: Using OpenRouter as a fallback provider in CI without injecting the secret. Key named OPENROUTER_KEY instead of OPENROUTER_API_KEY.

Related errors


AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12). Data as JSON: /api/errors/cf3d01e1891477b4. Report an issue: GitHub.