{"record":{"id":"364f7b4fe98e9855","repo":"Mintplex-Labs/anything-llm","slug":"no-togetherai-api-key-was-set","errorCode":null,"errorMessage":"No TogetherAI API key was set.","messagePattern":"No TogetherAI API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/togetherAi/index.js","lineNumber":83,"sourceCode":"\n    return validModels;\n  } catch (error) {\n    console.error(\"Error fetching Together AI models:\", error);\n    // If cache exists but is stale, still use it as fallback\n    if (fs.existsSync(cacheModelPath)) {\n      return safeJsonParse(\n        fs.readFileSync(cacheModelPath, { encoding: \"utf-8\" }),\n        []\n      );\n    }\n    return [];\n  }\n}\n\nclass TogetherAiLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.TOGETHER_AI_API_KEY)\n      throw new Error(\"No TogetherAI API key was set.\");\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.className = \"TogetherAiLLM\";\n    this.openai = new OpenAIApi({\n      baseURL: \"https://api.together.xyz/v1\",\n      apiKey: process.env.TOGETHER_AI_API_KEY ?? null,\n    });\n    this.model = modelPreference || process.env.TOGETHER_AI_MODEL_PREF;\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,\n      user: this.promptWindowLimit() * 0.7,\n    };\n\n    this.embedder = !embedder ? new NativeEmbedder() : embedder;\n    this.defaultTemp = 0.7;\n  }\n\n  #appendContext(contextTexts = []) {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/togetherAi/index.js#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create a key at https://api.together.ai and set TOGETHER_AI_API_KEY in server/.env, then restart.","Verify the process sees it: `node -e \"console.log(Boolean(process.env.TOGETHER_AI_API_KEY))\"`.","For Docker, ensure the variable is passed through and recreate the container.","Strip surrounding quotes/whitespace."],"exampleFix":"// before\n// TOGETHER_AI_API_KEY unset -> throws\nconst llm = new TogetherAiLLM(embedder, \"meta-llama/Llama-3-70b-chat-hf\");\n\n// after\n// server/.env\n// TOGETHER_AI_API_KEY=<key>\nconst llm = new TogetherAiLLM(embedder, \"meta-llama/Llama-3-70b-chat-hf\");","handlingStrategy":"validation","validationCode":"function assertTogetherKey() {\n  if (!process.env.TOGETHER_AI_API_KEY || !process.env.TOGETHER_AI_API_KEY.trim()) {\n    throw new Error(\"TOGETHER_AI_API_KEY is missing — create one at https://api.together.ai\");\n  }\n}\nassertTogetherKey();\nconst llm = new TogetherAiLLM(embedder, modelPref);","typeGuard":"function hasTogetherKey(env = process.env) {\n  return typeof env.TOGETHER_AI_API_KEY === \"string\" && env.TOGETHER_AI_API_KEY.trim().length > 0;\n}","tryCatchPattern":"let llm;\ntry {\n  llm = new TogetherAiLLM(embedder, modelPref);\n} catch (e) {\n  if (/No TogetherAI API key/i.test(e.message)) {\n    return { ok: false, reason: \"missing-together-key\" };\n  }\n  throw e;\n}","preventionTips":["Validate provider keys centrally at boot with one consolidated missing-key report.","Use the exact name TOGETHER_AI_API_KEY — common typos are TOGETHER_API_KEY / TOGETHERAI_API_KEY.","Restart/recreate the process after rotating keys.","Use a secrets manager to avoid copy artifacts."],"tags":["configuration","api-key","env","llm-provider","togetherai","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}