{"record":{"id":"1bbc13f6d3b9e37e","repo":"ruvnet/ruflo","slug":"authentication-1bbc13","errorCode":"AUTHENTICATION","errorMessage":"Cohere API key is required","messagePattern":"Cohere API key is required","errorType":"exception","errorClass":"AuthenticationError","httpStatus":401,"severity":"error","filePath":"v3/@claude-flow/providers/src/cohere-provider.ts","lineNumber":131,"sourceCode":"      },\n      'command': {\n        promptCostPer1k: 0.001,\n        completionCostPer1k: 0.002,\n        currency: 'USD',\n      },\n    },\n  };\n\n  private baseUrl: string = 'https://api.cohere.ai/v1';\n  private headers: Record<string, string> = {};\n\n  constructor(options: BaseProviderOptions) {\n    super(options);\n  }\n\n  protected async doInitialize(): Promise<void> {\n    if (!this.config.apiKey) {\n      throw new AuthenticationError('Cohere API key is required', 'cohere');\n    }\n\n    this.baseUrl = this.config.apiUrl || 'https://api.cohere.ai/v1';\n    this.headers = {\n      Authorization: `Bearer ${this.config.apiKey}`,\n      'Content-Type': 'application/json',\n    };\n  }\n\n  protected async doComplete(request: LLMRequest): Promise<LLMResponse> {\n    const cohereRequest = this.buildRequest(request);\n\n    const controller = new AbortController();\n    const timeout = setTimeout(() => controller.abort(), this.config.timeout || 60000);\n\n    try {\n      const response = await fetch(`${this.baseUrl}/chat`, {\n        method: 'POST',","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/providers/src/cohere-provider.ts#L113-L149","documentation":"CohereProvider.doInitialize() runs during provider.initialize(); if config.apiKey is falsy it throws AuthenticationError before any HTTP call. The key becomes the Authorization: Bearer header on every request to https://api.cohere.ai/v1 (or config.apiUrl).","triggerScenarios":"new CohereProvider({ name: 'cohere', config: { model: 'command-r-plus' } }) with no apiKey, or apiKey: process.env.COHERE_API_KEY when that env var is unset.","commonSituations":"COHERE_API_KEY missing in CI or a container; .env file not loaded by the runtime; key named differently (COHERE_KEY); a config object built for another provider reused for cohere.","solutions":["Pass apiKey in the config: config: { apiKey: process.env.COHERE_API_KEY, model: 'command-r-plus' }","Export COHERE_API_KEY in the environment where the process runs and verify with printenv COHERE_API_KEY","Add a startup assertion on required env vars so the failure carries your own actionable message"],"exampleFix":"// before\nconst provider = new CohereProvider({\n  name: 'cohere',\n  config: { model: 'command-r-plus' }, // no apiKey -> AuthenticationError at initialize()\n});\n\n// after\nconst provider = new CohereProvider({\n  name: 'cohere',\n  config: { apiKey: process.env.COHERE_API_KEY!, model: 'command-r-plus' },\n});","handlingStrategy":"validation","validationCode":"const apiKey = process.env.COHERE_API_KEY;\nif (!apiKey) {\n  throw new Error('COHERE_API_KEY is not set - cannot create cohere provider');\n}\nconst provider = new CohereProvider({ name: 'cohere', config: { apiKey, model: 'command-r-plus' } });","typeGuard":"import { AuthenticationError } from './types.js';\nfunction isAuthError(e: unknown): e is AuthenticationError {\n  return e instanceof AuthenticationError;\n}","tryCatchPattern":"try {\n  await provider.initialize();\n} catch (e) {\n  if (e instanceof AuthenticationError && !e.retryable) {\n    // missing/invalid key: fail fast with an operator-actionable message\n    throw new Error(`cohere credentials missing or invalid: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Validate required env vars in a startup config check before building providers","Fail the deployment when COHERE_API_KEY is absent instead of discovering it at first LLM call","Keep one module that maps provider -> required env var names and asserts all of them"],"tags":["authentication","config","env-var","cohere","initialization"],"backgroundTag":"missing-api-key","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}