Mintplex-Labs/anything-llm · error · Error

OpenAI API key must be provided to use agents.

Error message

OpenAI API key must be provided to use agents.

What it means

Setup guard in checkSetup(): the agent framework was configured with provider 'openai' but the OPEN_AI_KEY environment variable is unset, so no API client can be constructed. It is a fail-fast configuration sentinel, not a runtime API failure — the credential must be present before any agent session starts.

Solutions

  1. Set the OPEN_AI_KEY environment variable.
  2. Or select a different agent provider in the workspace settings.
Defensive patterns

Strategy: validation

When it happens

Trigger: OpenAI was selected as the agent provider but no API key is configured.

Common situations: This error is raised at runtime in server/utils/agents/index.js. It occurs when the required configuration for this provider is missing or invalid (unset environment variables, empty API key or base path), when the external service is unreachable or returns an unexpected response, or when invalid input reaches the call site. To prevent it, validate the relevant provider settings and environment variables at startup and confirm the service is reachable before this code path executes.


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/0fb08cec9236e454. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/agents/index.js:132

            from: WORKSPACE_AGENT.name,
            to: USER_AGENT.name,
            content: response?.text || "",
            state: "success",
          }
        );
      });
      return agentHistory;
    } catch (e) {
      this.log("Error loading chat history", e.message);
      return [];
    }
  }

  checkSetup() {
    switch (this.provider) {
      case "openai":
        if (!process.env.OPEN_AI_KEY)
          throw new Error("OpenAI API key must be provided to use agents.");
        break;
      case "anthropic":
        if (!process.env.ANTHROPIC_API_KEY)
          throw new Error("Anthropic API key must be provided to use agents.");
        break;
      case "lmstudio":
        if (!process.env.LMSTUDIO_BASE_PATH)
          throw new Error("LMStudio base path must be provided to use agents.");
        break;
      case "ollama":
        if (!process.env.OLLAMA_BASE_PATH)
          throw new Error("Ollama base path must be provided to use agents.");
        break;
      case "groq":
        if (!process.env.GROQ_API_KEY)
          throw new Error("Groq API key must be provided to use agents.");
        break;
      case "togetherai":

View on GitHub (pinned to 20f6d3546c)