ruvnet/ruflo · error · AuthenticationError

AUTHENTICATION

AUTHENTICATION

Error message

Cohere API key is required

What it means

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).

Source

Thrown at v3/@claude-flow/providers/src/cohere-provider.ts:131

      },
      'command': {
        promptCostPer1k: 0.001,
        completionCostPer1k: 0.002,
        currency: 'USD',
      },
    },
  };

  private baseUrl: string = 'https://api.cohere.ai/v1';
  private headers: Record<string, string> = {};

  constructor(options: BaseProviderOptions) {
    super(options);
  }

  protected async doInitialize(): Promise<void> {
    if (!this.config.apiKey) {
      throw new AuthenticationError('Cohere API key is required', 'cohere');
    }

    this.baseUrl = this.config.apiUrl || 'https://api.cohere.ai/v1';
    this.headers = {
      Authorization: `Bearer ${this.config.apiKey}`,
      'Content-Type': 'application/json',
    };
  }

  protected async doComplete(request: LLMRequest): Promise<LLMResponse> {
    const cohereRequest = this.buildRequest(request);

    const controller = new AbortController();
    const timeout = setTimeout(() => controller.abort(), this.config.timeout || 60000);

    try {
      const response = await fetch(`${this.baseUrl}/chat`, {
        method: 'POST',

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Pass apiKey in the config: config: { apiKey: process.env.COHERE_API_KEY, model: 'command-r-plus' }
  2. Export COHERE_API_KEY in the environment where the process runs and verify with printenv COHERE_API_KEY
  3. Add a startup assertion on required env vars so the failure carries your own actionable message

Example fix

// before
const provider = new CohereProvider({
  name: 'cohere',
  config: { model: 'command-r-plus' }, // no apiKey -> AuthenticationError at initialize()
});

// after
const provider = new CohereProvider({
  name: 'cohere',
  config: { apiKey: process.env.COHERE_API_KEY!, model: 'command-r-plus' },
});
Defensive patterns

Strategy: validation

Validate before calling

const apiKey = process.env.COHERE_API_KEY;
if (!apiKey) {
  throw new Error('COHERE_API_KEY is not set - cannot create cohere provider');
}
const provider = new CohereProvider({ name: 'cohere', config: { apiKey, model: 'command-r-plus' } });

Type guard

import { AuthenticationError } from './types.js';
function isAuthError(e: unknown): e is AuthenticationError {
  return e instanceof AuthenticationError;
}

Try / catch

try {
  await provider.initialize();
} catch (e) {
  if (e instanceof AuthenticationError && !e.retryable) {
    // missing/invalid key: fail fast with an operator-actionable message
    throw new Error(`cohere credentials missing or invalid: ${e.message}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/1bbc13f6d3b9e37e. Report an issue: GitHub.