{"record":{"id":"0925718071b66546","repo":"mem0ai/mem0","slug":"together-api-key-is-required","errorCode":null,"errorMessage":"Together API key is required","messagePattern":"Together API key is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/embeddings/together.ts","lineNumber":14,"sourceCode":"import { OpenAIEmbedder } from \"./openai\";\nimport { EmbeddingConfig } from \"../types\";\n\nconst DEFAULT_BASE_URL = \"https://api.together.ai/v1\";\nconst DEFAULT_MODEL = \"intfloat/multilingual-e5-large-instruct\";\n\nexport class TogetherEmbedder extends OpenAIEmbedder {\n  constructor(config: EmbeddingConfig) {\n    const openAICompatibleConfig = { ...config };\n    delete openAICompatibleConfig.embeddingDims;\n\n    const apiKey = config.apiKey || process.env.TOGETHER_API_KEY;\n    if (!apiKey) {\n      throw new Error(\"Together API key is required\");\n    }\n\n    super({\n      ...openAICompatibleConfig,\n      apiKey,\n      // Honor TOGETHER_API_BASE like the Together LLM does, so a user behind a\n      // gateway who sets it gets it for embeddings too instead of silently\n      // hitting api.together.ai.\n      baseURL:\n        config.baseURL ||\n        config.url ||\n        process.env.TOGETHER_API_BASE ||\n        DEFAULT_BASE_URL,\n      model: config.model || DEFAULT_MODEL,\n    });\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/embeddings/together.ts#L1-L32","documentation":"TogetherEmbedder (which extends OpenAIEmbedder) requires an API key at construction time. It checks config.apiKey first, then the TOGETHER_API_KEY environment variable; if neither is set it throws immediately, before any network call. This is a fail-fast configuration error, not a runtime API error.","triggerScenarios":"Constructing Memory or TogetherEmbedder with provider 'together' while passing no apiKey and having no TOGETHER_API_KEY in the environment; env var name typo (TOGETHER_APIKEY, TOGETHER_KEY); .env file loaded after module initialization or not loaded at all.","commonSituations":"CI environment missing the secret; dotenv imported after Memory construction; key set in one shell but the process runs elsewhere (Docker, serverless); confusing the Together key with the OpenAI key.","solutions":["Set TOGETHER_API_KEY in the environment or pass apiKey in the embedder config","If using dotenv, ensure import 'dotenv/config' (or config()) runs before the Memory/TogetherEmbedder is constructed","Check the exact spelling TOGETHER_API_KEY and that it is exported in the deploy environment","Get a valid key from api.together.ai if you do not have one"],"exampleFix":"// before\nconst memory = new Memory({ embedder: { provider: \"together\" } }); // no key anywhere\n\n// after\nconst memory = new Memory({\n  embedder: { provider: \"together\", config: { apiKey: process.env.TOGETHER_API_KEY! } },\n});","handlingStrategy":"validation","validationCode":"const apiKey = config.apiKey ?? process.env.TOGETHER_API_KEY;\nif (!apiKey) throw new Error(\"TOGETHER_API_KEY missing - set it before constructing Memory\");","typeGuard":"function isMissingApiKeyError(err: unknown): boolean {\n  return err instanceof Error && err.message === \"Together API key is required\";\n}","tryCatchPattern":"try {\n  new TogetherEmbedder(config);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Together API key is required\") {\n    throw new Error(\"Configuration error: provide config.apiKey or set TOGETHER_API_KEY\");\n  }\n  throw err;\n}","preventionTips":["Fail fast on config: assert required env vars at process start, not on first embed","Load dotenv at the entry point before any SDK construction","Add a startup config schema check (e.g. zod) covering apiKey fields"],"tags":["together","api-key","configuration","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}