eyaltoledano/claude-task-master · error · Error

API key environment variable name is required

Error message

API key environment variable name is required

What it means

The constructor also requires config.apiKeyEnvVar: the name of the environment variable holding the API key. Without it the provider cannot resolve credentials, so instantiation fails fast. thrown as a plain Error.

Source

Thrown at src/ai-providers/openai-compatible.js:31

 */
export class OpenAICompatibleProvider extends BaseAIProvider {
	/**
	 * @param {object} config - Provider configuration
	 * @param {string} config.name - Provider display name
	 * @param {string} config.apiKeyEnvVar - Environment variable name for API key
	 * @param {boolean} [config.requiresApiKey=true] - Whether API key is required
	 * @param {string} [config.defaultBaseURL] - Default base URL for the API
	 * @param {Function} [config.getBaseURL] - Function to determine base URL from params
	 * @param {boolean} [config.supportsStructuredOutputs] - Whether provider supports structured outputs
	 */
	constructor(config) {
		super();

		if (!config.name) {
			throw new Error('Provider name is required');
		}
		if (!config.apiKeyEnvVar) {
			throw new Error('API key environment variable name is required');
		}

		this.name = config.name;
		this.apiKeyEnvVar = config.apiKeyEnvVar;
		this.requiresApiKey = config.requiresApiKey !== false; // Default to true
		this.defaultBaseURL = config.defaultBaseURL;
		this.getBaseURLFromParams = config.getBaseURL;
		this.supportsStructuredOutputs = config.supportsStructuredOutputs;
	}

	/**
	 * Returns the environment variable name required for this provider's API key.
	 * @returns {string} The environment variable name for the API key
	 */
	getRequiredApiKeyName() {
		return this.apiKeyEnvVar;
	}

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Add 'apiKeyEnvVar: "YOUR_ENV_VAR"' to the provider config.
  2. Set the corresponding environment variable in your shell/.env so the value exists at runtime.
  3. Check for config schema drift (older 'apiKey' field vs 'apiKeyEnvVar').
  4. Validate all custom provider configs in a startup check.

Example fix

// before
// new OpenAICompatibleProvider({ name: 'together', defaultBaseURL: 'https://api.together.xyz/v1' })
// after
// new OpenAICompatibleProvider({ name: 'together', apiKeyEnvVar: 'TOGETHER_API_KEY', defaultBaseURL: 'https://api.together.xyz/v1' })
Defensive patterns

Strategy: validation

Validate before calling

function assertApiKeyEnvVar(config) {
  if (typeof config.apiKeyEnvVar !== 'string' || !config.apiKeyEnvVar.trim()) {
    throw new Error(`provider '${config?.name}' missing apiKeyEnvVar`);
  }
}

Type guard

function hasApiKeyEnvVar(c) {
  return typeof c === 'object' && c !== null && typeof c.apiKeyEnvVar === 'string' && c.apiKeyEnvVar.length > 0;
}

Try / catch

try {
  const provider = new OpenAICompatibleProvider(config);
} catch (e) {
  if (e.message.includes('API key environment variable name is required')) {
    console.error(`Add apiKeyEnvVar to provider '${config?.name}' config`);
  }
  throw e;
}

Prevention

When it happens

Trigger: new OpenAICompatibleProvider(config) where config.apiKeyEnvVar is missing/empty.

Common situations: Custom provider configs omitting apiKeyEnvVar, renaming conventions (apiKey vs apiKeyEnvVar) between config versions, copying a provider example without updating the env var name field.

Related errors


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