Mintplex-Labs/anything-llm · error · Error

Cohere API key must be provided to use agents.

Error message

Cohere API key must be provided to use agents.

What it means

Thrown by checkSetup() (server/utils/agents/index.js:128) when the resolved agent provider is 'cohere' but process.env.COHERE_API_KEY is unset/empty. It is a precondition gate in agent.init() ensuring the Cohere client is never built without an API key.

Source

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

      case "moonshotai":
        if (!process.env.MOONSHOT_AI_MODEL_PREF)
          throw new Error("Moonshot AI model must be set to use agents.");
        break;
      case "cometapi":
        if (!process.env.COMETAPI_LLM_API_KEY)
          throw new Error("CometAPI API Key must be provided to use agents.");
        break;
      case "foundry":
        if (!process.env.FOUNDRY_BASE_PATH)
          throw new Error("Foundry base path must be provided to use agents.");
        break;
      case "giteeai":
        if (!process.env.GITEE_AI_API_KEY)
          throw new Error("GiteeAI API Key must be provided to use agents.");
        break;
      case "cohere":
        if (!process.env.COHERE_API_KEY)
          throw new Error("Cohere API key must be provided to use agents.");
        break;
      case "docker-model-runner":
        if (!process.env.DOCKER_MODEL_RUNNER_BASE_PATH)
          throw new Error(
            "Docker Model Runner base path must be provided to use agents."
          );
        break;
      case "privatemode":
        if (!process.env.PRIVATEMODE_LLM_BASE_PATH)
          throw new Error(
            "Privatemode base path must be provided to use agents."
          );
        break;
      case "sambanova":
        if (!process.env.SAMBANOVA_LLM_API_KEY)
          throw new Error("SambaNova API key must be provided to use agents.");
        break;
      case "lemonade":

View on GitHub (pinned to 526360e320)

Solutions

  1. Set COHERE_API_KEY in .env to a valid Cohere key and restart the server.
  2. Confirm the process loaded the key (check exit code/status of a probe, never print the value).
  3. Switch provider if Cohere is no longer intended.

Example fix

// before (.env)
COHERE_API_KEY=
// after (.env)
COHERE_API_KEY=<your-cohere-key>
Defensive patterns

Strategy: validation

Validate before calling

function assertCohereReady(workspaceAgentProvider) {
  const using = workspaceAgentProvider === 'cohere' || process.env.LLM_PROVIDER === 'cohere';
  if (using && !process.env.COHERE_API_KEY)
    throw new Error('COHERE_API_KEY missing - set it before starting an agent.');
}

Try / catch

try { await agent.init(); } catch (e) { if (/Cohere API key must be provided/.test(e.message)) return showProviderConfig('cohere'); throw e; }

Prevention

When it happens

Trigger: A chat turn calls agent.init(); this.provider resolves to 'cohere'; case 'cohere' runs and process.env.COHERE_API_KEY is falsy.

Common situations: Cohere selected as agent provider but the key was not saved; key removed/expired and not rotated into .env; server not restarted after .env change.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/45d4beb183836819. Report an issue: GitHub.