harry0703/MoneyPrinterTurbo · error · ValueError

{llm_provider}: api_key is not set, please set it in the con

Error message

{llm_provider}: api_key is not set, please set it in the config.toml file.

What it means

Credential guard in _generate_response: the selected provider declares requires_api_key but the resolved api_key (from provider.config_key('api_key') in the runtime config snapshot) is empty. Raised before any network call so the failure is immediate and attributable.

Source

Thrown at app/services/llm.py:197

            api_key = "ollama"
            if not base_url:
                base_url = config.get_default_ollama_base_url()

        if adapter == "azure":
            api_version = runtime_app_config.get(
                provider.config_key("api_version"), "2024-02-15-preview"
            )

        extra_values = {
            field.config_suffix: (
                runtime_app_config.get(provider.config_key(field.config_suffix), "")
                or field.default_value
            )
            for field in provider.extra_fields
        }

        if provider.requires_api_key and not api_key:
            raise ValueError(
                f"{llm_provider}: api_key is not set, please set it in the config.toml file."
            )
        if provider.requires_model_name and not model_name:
            raise ValueError(
                f"{llm_provider}: model_name is not set, please set it in the config.toml file."
            )
        if provider.requires_base_url and not base_url:
            raise ValueError(
                f"{llm_provider}: base_url is not set, please set it in the config.toml file."
            )

        for field in provider.extra_fields:
            if field.required and not extra_values[field.config_suffix]:
                raise ValueError(
                    f"{llm_provider}: {field.config_suffix} is not set, "
                    "please set it in the config.toml file."
                )

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Set <provider>.api_key in config.toml (the exact key name is provider.config_key('api_key'), e.g. openai.api_key) or via the WebUI settings page
  2. Confirm the key is under the section matching the active llm_provider — keys are per-provider
  3. If using env-based config, verify the process environment actually contains it (docker-compose env, systemd Environment=)
  4. Call the provider validation/test-connection feature in the WebUI after setting the key

Example fix

# config.toml before
llm_provider = "openai"
[openai]
model_name = "gpt-4o-mini"  # api_key missing

# config.toml after
llm_provider = "openai"
[openai]
api_key = "sk-..."
model_name = "gpt-4o-mini"
Defensive patterns

Strategy: validation

Validate before calling

provider = get_llm_provider(cfg["llm_provider"])
if provider.requires_api_key and not cfg.get(provider.config_key("api_key")):
    raise ConfigError(f"{provider.config_key('api_key')} is empty")

Prevention

When it happens

Trigger: Any provider with requires_api_key=true (openai, qwen, gemini, etc.) whose <provider>.api_key config entry is missing, empty, or whitespace-only in the effective config snapshot.

Common situations: Fresh install where config.toml was copied from config.example.toml without filling keys, key set for a different provider than the selected llm_provider, env-var-based configs not loaded in service/docker contexts, or the WebUI config snapshot taken before the user saved their key.

Related errors


AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14). Data as JSON: /api/errors/adadf83b40bb36ed. Report an issue: GitHub.