{"record":{"id":"807836d585e7fe4f","repo":"chroma-core/chroma","slug":"cohere-api-key-is-required-please-provide-it-in-t","errorCode":null,"errorMessage":"Cohere API key is required. Please provide it in the constructor or set the environment variable ${cohere_api_key_env_var}.","messagePattern":"Cohere 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/CohereEmbeddingFunction.ts","lineNumber":127,"sourceCode":"     * base64 encoded PNG data URIs.\n     */\n    isImage = false,\n  }: {\n    cohere_api_key?: string;\n    model?: string;\n    cohere_api_key_env_var: string;\n    /**\n     * If true, the input texts passed to `generate` are expected to be\n     * base64 encoded PNG data URIs.\n     */\n    isImage?: boolean;\n  }) {\n    this.model = model;\n    this.isImage = isImage;\n\n    const apiKey = cohere_api_key ?? process.env[cohere_api_key_env_var];\n    if (!apiKey) {\n      throw new Error(\n        `Cohere API key is required. Please provide it in the constructor or set the environment variable ${cohere_api_key_env_var}.`,\n      );\n    }\n\n    this.apiKey = apiKey;\n    this.apiKeyEnvVar = cohere_api_key_env_var;\n  }\n\n  private async initCohereClient() {\n    if (this.cohereAiApi) return;\n    try {\n      // @ts-ignore\n      this.cohereAiApi = await import(\"cohere-ai\").then((cohere) => {\n        // @ts-ignore\n        if (cohere.CohereClient) {\n          return new CohereAISDK7({ apiKey: this.apiKey });\n        } else {\n          return new CohereAISDK56({ apiKey: this.apiKey });","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/CohereEmbeddingFunction.ts#L109-L145","documentation":"CohereEmbeddingFunction resolves its key as cohere_api_key ?? process.env[cohere_api_key_env_var] (default 'CHROMA_COHERE_API_KEY') in the constructor and throws this Error when both are absent. The key is handed to the cohere-ai SDK on first use; only the env-var name is persisted in the collection config, so buildFromConfig restores require the variable to be set again.","triggerScenarios":"new CohereEmbeddingFunction({ model_name: 'embed-english-v3.0' }) with CHROMA_COHERE_API_KEY unset; custom cohere_api_key_env_var never injected in the deploy environment; opening a collection configured with Cohere on a machine without the var.","commonSituations":"Local .env not loaded before constructing the EF; secret present in dev but missing in CI/prod; the env var was renamed during a migration but deployment templates still use the old name.","solutions":["Export the env var: export CHROMA_COHERE_API_KEY='<cohere-key>'.","Or pass the key directly in the constructor: new CohereEmbeddingFunction({ model_name, cohere_api_key: process.env.COHERE_KEY }).","Add the secret to your platform's env config and log a presence check (not the value) at startup."],"exampleFix":"// before\nconst ef = new CohereEmbeddingFunction({ model_name: 'embed-english-v3.0' });\n\n// after\nimport 'dotenv/config';\nconst ef = new CohereEmbeddingFunction({\n  model_name: 'embed-english-v3.0',\n  cohere_api_key: process.env.CHROMA_COHERE_API_KEY,\n});","handlingStrategy":"validation","validationCode":"const cohereKey = process.env.CHROMA_COHERE_API_KEY;\nif (!cohereKey) {\n  throw new Error('Set CHROMA_COHERE_API_KEY (or pass cohere_api_key) before constructing CohereEmbeddingFunction');\n}\nconst ef = new CohereEmbeddingFunction({ model_name: 'embed-english-v3.0', cohere_api_key: cohereKey });","typeGuard":null,"tryCatchPattern":"try {\n  new CohereEmbeddingFunction({ model_name });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Cohere API key is required')) {\n    // add the secret to the environment (or constructor) and construct again\n  }\n  throw e;\n}","preventionTips":["Assert the env var at startup rather than at first embed.","Load dotenv/config as the first import so the var exists before EF construction.","If you use a custom cohere_api_key_env_var, document it for every deployment stage."],"tags":["embeddings","cohere","api-key","environment-variable","credentials"],"backgroundTag":"missing-api-key","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}