eyaltoledano/claude-task-master · critical · TaskMasterError

AUTHENTICATION_ERROR

AUTHENTICATION_ERROR

Error message

API key is required

What it means

BaseProvider's constructor requires a non-empty apiKey in the BaseProviderConfig; without credentials no provider can authenticate, so it throws a TaskMasterError with code AUTHENTICATION_ERROR immediately at instantiation time rather than failing on the first API call.

Source

Thrown at packages/tm-core/src/modules/ai/providers/base-provider.ts:80

 * Prepared request after preprocessing
 */
interface PreparedRequest {
	prompt: string;
	options: AIOptions;
	metadata: Record<string, any>;
}

/**
 * Abstract base provider implementing Template Method pattern
 * Provides common error handling, retry logic, and validation
 */
export abstract class BaseProvider implements IAIProvider {
	protected readonly apiKey: string;
	protected model: string;

	constructor(config: BaseProviderConfig) {
		if (!config.apiKey) {
			throw new TaskMasterError(
				'API key is required',
				ERROR_CODES.AUTHENTICATION_ERROR
			);
		}
		this.apiKey = config.apiKey;
		this.model = config.model || this.getDefaultModel();
	}

	/**
	 * Template method for generating completions
	 * Handles validation, retries, and error handling
	 */
	async generateCompletion(
		prompt: string,
		options?: AIOptions
	): Promise<AIResponse> {
		// Validate input
		const validation = this.validateInput(prompt, options);

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Set the provider's API key env var (or pass apiKey in the provider config)
  2. Ensure dotenv/config is loaded before constructing the provider
  3. Verify the key is non-empty: console.log(Boolean(process.env.MY_API_KEY)) — then restart the shell/CI after adding the secret

Example fix

// before
const provider = new ZAIProvider({ apiKey: process.env.ZAI_API_KEY });
// after
const apiKey = process.env.ZAI_API_KEY;
if (!apiKey) throw new Error('Set ZAI_API_KEY in your environment');
const provider = new ZAIProvider({ apiKey });
Defensive patterns

Strategy: validation

Validate before calling

function requireApiKey(envVar: string): string {
  const key = process.env[envVar];
  if (!key) throw new Error(`Missing ${envVar}; set it in your environment or .env`);
  return key;
}
const provider = new ZAIProvider({ apiKey: requireApiKey('ZAI_API_KEY') });

Type guard

function hasApiKey(config: BaseProviderConfig): config is BaseProviderConfig & { apiKey: string } {
  return typeof config.apiKey === 'string' && config.apiKey.length > 0;
}

Try / catch

try {
  provider = new ZAIProvider({ apiKey });
} catch (err) {
  if (err instanceof TaskMasterError && err.code === ERROR_CODES.AUTHENTICATION_ERROR) {
    throw new Error('Provider not configured: API key missing. Check your .env / CI secrets.');
  }
  throw err;
}

Prevention

When it happens

Trigger: new ZAIProvider({ apiKey: undefined }) when the env var (e.g. ZAI_API_KEY / OPENAI_API_KEY / ANTHROPIC_API_KEY) is unset or empty; config files loaded from the wrong directory; dotenv not initialized before constructing the provider.

Common situations: Missing .env file in CI or Docker (secrets not mounted); renamed env variables after a version change; typos in the env var name; using a wrong-provider key that ended up undefined after key-per-provider lookup.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/2e421dff014fac44. Report an issue: GitHub.