Mintplex-Labs/anything-llm · error · Error

No TogetherAI API key was set.

Error message

No TogetherAI API key was set.

What it means

Thrown by the TogetherAiLLM constructor when process.env.TOGETHER_AI_API_KEY is falsy. Together AI is OpenAI-compatible at https://api.together.xyz/v1 and the constructor builds that client inline, so it refuses to instantiate without a key from api.together.ai.

Source

Thrown at server/utils/AiProviders/togetherAi/index.js:83

    return validModels;
  } catch (error) {
    console.error("Error fetching Together AI models:", error);
    // If cache exists but is stale, still use it as fallback
    if (fs.existsSync(cacheModelPath)) {
      return safeJsonParse(
        fs.readFileSync(cacheModelPath, { encoding: "utf-8" }),
        []
      );
    }
    return [];
  }
}

class TogetherAiLLM {
  constructor(embedder = null, modelPreference = null) {
    if (!process.env.TOGETHER_AI_API_KEY)
      throw new Error("No TogetherAI API key was set.");
    const { OpenAI: OpenAIApi } = require("openai");
    this.className = "TogetherAiLLM";
    this.openai = new OpenAIApi({
      baseURL: "https://api.together.xyz/v1",
      apiKey: process.env.TOGETHER_AI_API_KEY ?? null,
    });
    this.model = modelPreference || process.env.TOGETHER_AI_MODEL_PREF;
    this.limits = {
      history: this.promptWindowLimit() * 0.15,
      system: this.promptWindowLimit() * 0.15,
      user: this.promptWindowLimit() * 0.7,
    };

    this.embedder = !embedder ? new NativeEmbedder() : embedder;
    this.defaultTemp = 0.7;
  }

  #appendContext(contextTexts = []) {

View on GitHub (pinned to 526360e320)

Solutions

  1. Create a key at https://api.together.ai and set TOGETHER_AI_API_KEY in server/.env, then restart.
  2. Verify the process sees it: `node -e "console.log(Boolean(process.env.TOGETHER_AI_API_KEY))"`.
  3. For Docker, ensure the variable is passed through and recreate the container.
  4. Strip surrounding quotes/whitespace.

Example fix

// before
// TOGETHER_AI_API_KEY unset -> throws
const llm = new TogetherAiLLM(embedder, "meta-llama/Llama-3-70b-chat-hf");

// after
// server/.env
// TOGETHER_AI_API_KEY=<key>
const llm = new TogetherAiLLM(embedder, "meta-llama/Llama-3-70b-chat-hf");
Defensive patterns

Strategy: validation

Validate before calling

function assertTogetherKey() {
  if (!process.env.TOGETHER_AI_API_KEY || !process.env.TOGETHER_AI_API_KEY.trim()) {
    throw new Error("TOGETHER_AI_API_KEY is missing — create one at https://api.together.ai");
  }
}
assertTogetherKey();
const llm = new TogetherAiLLM(embedder, modelPref);

Type guard

function hasTogetherKey(env = process.env) {
  return typeof env.TOGETHER_AI_API_KEY === "string" && env.TOGETHER_AI_API_KEY.trim().length > 0;
}

Try / catch

let llm;
try {
  llm = new TogetherAiLLM(embedder, modelPref);
} catch (e) {
  if (/No TogetherAI API key/i.test(e.message)) {
    return { ok: false, reason: "missing-together-key" };
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `new TogetherAiLLM(...)` with TOGETHER_AI_API_KEY unset/empty. Selecting Together AI in the workspace before configuring the key, or running the server without the variable.

Common situations: New integration without a together.ai key yet; variable named TOGETHER_API_KEY or TOGETHERAI_API_KEY instead of TOGETHER_AI_API_KEY; .env edited but server not restarted; key rotated on the portal but not redeployed.

Related errors


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