eyaltoledano/claude-task-master · error · Error
API key is required
Error message
${this.name} API key is required What it means
The default validateAuth() on BaseAIProvider requires params.apiKey for providers that don't override it. Since ${this.name} resolves to the concrete provider's class name, the message identifies which provider is missing its key. It fails fast so requests never reach the remote API unauthenticated.
Solutions
- Set the provider's API key env var (e.g., OPENAI_API_KEY) or pass apiKey in params
- Run `tm models --setup` to configure credentials for the active role
- Check the provider name in the message to know which key is missing
Example fix
// before
const provider = new OpenAIProvider({});
// after
const provider = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY }); Defensive patterns
Strategy: validation
Validate before calling
if (!params?.apiKey) throw new Error(`Provide an API key for ${providerName} before calling the provider`); Type guard
function hasApiKey(params) { return typeof params?.apiKey === 'string' && params.apiKey.length > 0; } Try / catch
try {
await provider.generateText(params);
} catch (err) {
if (err.message.endsWith('API key is required')) {
console.error(`Missing API key for ${provider.name}; check env/config`);
} else throw err;
} Prevention
- Load .env at process start and verify required keys exist
- Match the key env var to the actual active provider
- Run `tm models --setup` after changing provider roles
When it happens
Trigger: Calling any generation method on a provider using the default validateAuth when params.apiKey is undefined/null/empty — e.g., provider env var like OPENAI_API_KEY or ANTHROPIC_API_KEY unset, or apiKey omitted in direct instantiation.
Common situations: Missing env var / unexported key; .env not loaded; key configured for a different provider than the active role; providers like ollama that override validateAuth are unaffected.
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
- Azure API key is required
- API_KEY_STATUS_ERROR
- AUTHENTICATION_ERROR
- Base URL is required for OpenAI-compatible providers…
- Grok CLI API key not found. Set GROK_CLI_API_KEY…
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/fa9b4f63ec27cb75.
Report an issue: GitHub.
Appendix: source
Thrown at src/ai-providers/base-provider.js:161
*/
this.needsExplicitJsonSchema = false;
/**
* Whether this provider supports temperature parameter
* Can be overridden by subclasses
* @type {boolean}
*/
this.supportsTemperature = true;
}
/**
* Validates authentication parameters - can be overridden by providers
* @param {object} params - Parameters to validate
*/
validateAuth(params) {
// Default: require API key (most providers need this)
if (!params.apiKey) {
throw new Error(`${this.name} API key is required`);
}
}
/**
* Creates a custom fetch function with proxy support.
* Only enables proxy when TASKMASTER_ENABLE_PROXY environment variable is set to 'true'
* or enableProxy is set to true in config.json.
* Automatically reads http_proxy/https_proxy environment variables when enabled.
* @returns {Function} Custom fetch function with proxy support, or undefined if proxy is disabled
*/
createProxyFetch() {
// Cache project root to avoid repeated lookups
if (!this._projectRoot) {
this._projectRoot = findProjectRoot();
}
const projectRoot = this._projectRoot;
if (!isProxyEnabled(null, projectRoot)) {View on GitHub (pinned to c0c98d367c)