mvanhorn/last30days-skill · critical · RuntimeError

xAI selected but XAI_API_KEY is not configured.

Error message

xAI selected but XAI_API_KEY is not configured.

What it means

RuntimeError raised in resolve_runtime when provider is 'xai' but the XAI_API_KEY environment/config entry is falsy. Straightforward missing-credential gate mirroring the Gemini and OpenAI branches.

Source

Thrown at skills/last30days/scripts/lib/providers.py:292

        return runtime, GeminiClient(google_key)

    if provider_name == "openai":
        if not openai_token or config.get("OPENAI_AUTH_STATUS") != env.AUTH_STATUS_OK:
            raise RuntimeError("OpenAI selected but no valid OpenAI auth is configured.")
        runtime = schema.ProviderRuntime(
            reasoning_provider="openai",
            planner_model=planner_model,
            rerank_model=rerank_model,
    
            x_search_backend=_resolve_x_backend(config),
        )
        return runtime, OpenAIClient(
            openai_token
        )

    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),

View on GitHub (pinned to c7460f6114)

Solutions

  1. Set XAI_API_KEY in ~/.config/last30days/.env or the process environment
  2. Confirm the exact variable name is XAI_API_KEY (no typos)
  3. In CI, add XAI_API_KEY as a masked secret on the job

Example fix

# before
LAST30DAYS_REASONING_PROVIDER=xai
# XAI_API_KEY missing

# after
LAST30DAYS_REASONING_PROVIDER=xai
XAI_API_KEY=xai-your-key
Defensive patterns

Strategy: validation

Validate before calling

if (os.environ.get("LAST30DAYS_REASONING_PROVIDER") or "").lower() == "xai":
    if not os.environ.get("XAI_API_KEY"):
        raise SystemExit("Set XAI_API_KEY before selecting the xai provider")

Type guard

def xai_ready(config: dict) -> bool:
    provider = (config.get("LAST30DAYS_REASONING_PROVIDER") or "gemini").lower()
    return provider != "xai" or bool(config.get("XAI_API_KEY"))

Try / catch

try:
    runtime, client = resolve_runtime(config, depth)
except RuntimeError as e:
    if "XAI_API_KEY" in str(e):
        set_key_via_setup("XAI_API_KEY")

Prevention

When it happens

Trigger: LAST30DAYS_REASONING_PROVIDER=xai with XAI_API_KEY unset, empty string, or only defined in a shell the agent subprocess does not inherit.

Common situations: xAI key created in the xAI console but never exported; key name typo (XAI_KEY, XAI_TOKEN); CI jobs missing the secret; .env not on the engine's load path.

Related errors


AI-assisted analysis of mvanhorn/last30days-skill@c7460f6114 (2026-08-15). Data as JSON: /api/errors/57afbb0a8fbfe857. Report an issue: GitHub.