{"record":{"id":"9b4a8aed2254c744","repo":"chroma-core/chroma","slug":"together-ai-api-key-is-required-please-provide-it","errorCode":null,"errorMessage":"Together AI API key is required. Please provide it in the constructor or set the environment variable ${api_key_env_var}.","messagePattern":"Together AI API key is required\\. Please provide it in the constructor or set the environment variable (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/TogetherAIEmbeddingFunction.ts","lineNumber":29,"sourceCode":"export class TogetherAIEmbeddingFunction implements IEmbeddingFunction {\n  name = \"together_ai\";\n\n  private model_name: string;\n  private api_key_env_var: string;\n  private headers: { [key: string]: string };\n\n  constructor({\n    together_ai_api_key,\n    model_name,\n    api_key_env_var = \"CHROMA_TOGETHER_AI_API_KEY\",\n  }: {\n    together_ai_api_key?: string;\n    model_name: string;\n    api_key_env_var: string;\n  }) {\n    const apiKey = together_ai_api_key ?? process.env[api_key_env_var];\n    if (!apiKey) {\n      throw new Error(\n        `Together AI API key is required. Please provide it in the constructor or set the environment variable ${api_key_env_var}.`,\n      );\n    }\n\n    this.model_name = model_name;\n    this.api_key_env_var = api_key_env_var;\n\n    this.headers = {\n      Authorization: `Bearer ${apiKey}`,\n      \"Content-Type\": \"application/json\",\n      accept: \"application/json\",\n    };\n  }\n\n  public async generate(texts: string[]): Promise<number[][]> {\n    try {\n      const payload = {\n        model: this.model_name,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/TogetherAIEmbeddingFunction.ts#L11-L47","documentation":"TogetherAIEmbeddingFunction requires an API key at construction: the explicit together_ai_api_key parameter or the environment variable named by api_key_env_var, which defaults to CHROMA_TOGETHER_AI_API_KEY. If neither yields a truthy string the constructor throws synchronously before any request is made.","triggerScenarios":"new TogetherAIEmbeddingFunction({ model_name: \"togethercomputer/m2-bert-80M-8k-retrieval\" }) with CHROMA_TOGETHER_AI_API_KEY unset and no together_ai_api_key passed; or a custom api_key_env_var name that is not exported in the runtime environment.","commonSituations":"Assuming TOGETHER_API_KEY is read automatically (the default is CHROMA_TOGETHER_AI_API_KEY); dotenv loaded after client construction; CI/containers missing the secret.","solutions":["Pass the key explicitly: new TogetherAIEmbeddingFunction({ together_ai_api_key: process.env.TOGETHER_API_KEY!, model_name: \"...\", api_key_env_var: \"TOGETHER_API_KEY\" })","Or export CHROMA_TOGETHER_AI_API_KEY=... to match the default name","Or set api_key_env_var to your existing variable name and export it","Verify inside the process: node -e \"console.log(!!process.env.CHROMA_TOGETHER_AI_API_KEY)\""],"exampleFix":"// before: throws — default env var is CHROMA_TOGETHER_AI_API_KEY\nconst ef = new TogetherAIEmbeddingFunction({ model_name: \"togethercomputer/m2-bert-80M-8k-retrieval\" });\n\n// after: be explicit\nconst ef = new TogetherAIEmbeddingFunction({\n  together_ai_api_key: process.env.TOGETHER_API_KEY!,\n  api_key_env_var: \"TOGETHER_API_KEY\",\n  model_name: \"togethercomputer/m2-bert-80M-8k-retrieval\",\n});","handlingStrategy":"validation","validationCode":"function requireEnv(name: string): string {\n  const v = process.env[name];\n  if (!v) throw new Error(`Missing required env var ${name}`);\n  return v;\n}\n// before constructing — note the default name is CHROMA_TOGETHER_AI_API_KEY:\nconst together_ai_api_key = requireEnv(\"TOGETHER_API_KEY\");\nconst ef = new TogetherAIEmbeddingFunction({ together_ai_api_key, api_key_env_var: \"TOGETHER_API_KEY\", model_name: \"togethercomputer/m2-bert-80M-8k-retrieval\" });","typeGuard":null,"tryCatchPattern":"try {\n  ef = new TogetherAIEmbeddingFunction({ model_name: \"togethercomputer/m2-bert-80M-8k-retrieval\" });\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"API key is required\")) {\n    // config error: name CHROMA_TOGETHER_AI_API_KEY (default) in the ops message; do not retry\n  }\n  throw e;\n}","preventionTips":["Pass together_ai_api_key explicitly rather than relying on the CHROMA_TOGETHER_AI_API_KEY default","Validate env vars once at boot with a schema check before constructing clients","Load dotenv at the entrypoint, before any embedding function is constructed"],"tags":["api-key","env-var","together-ai","configuration","embeddings"],"backgroundTag":"missing-api-key","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}