eyaltoledano/claude-task-master · error · Error
${this.name} API key is required
Error message
${this.name} API key is required What it means
validateAuth throws when the provider is configured with requiresApiKey=true (the default) and no API key is present in params.apiKey. It interpolates the provider's name so you know which provider's credentials are missing.
Source
Thrown at src/ai-providers/openai-compatible.js:64
getRequiredApiKeyName() {
return this.apiKeyEnvVar;
}
/**
* Returns whether this provider requires an API key.
* @returns {boolean} True if API key is required
*/
isRequiredApiKey() {
return this.requiresApiKey;
}
/**
* Override auth validation based on requiresApiKey setting
* @param {object} params - Parameters to validate
*/
validateAuth(params) {
if (this.requiresApiKey && !params.apiKey) {
throw new Error(`${this.name} API key is required`);
}
}
/**
* Determines the base URL to use for the API.
* @param {object} params - Client parameters
* @returns {string|undefined} The base URL to use
*/
getBaseURL(params) {
// If custom baseURL provided in params, use it
if (params.baseURL) {
return params.baseURL;
}
// If provider has a custom getBaseURL function, use it
if (this.getBaseURLFromParams) {
return this.getBaseURLFromParams(params);
}View on GitHub (pinned to c0c98d367c)
Solutions
- Set the API key in the environment variable specified by the provider's apiKeyEnvVar config.
- Ensure your .env file is loaded (dotenv config) before creating the client.
- Pass apiKey explicitly in the params if not relying on env vars.
- If the provider needs no key, set requiresApiKey: false in the provider config.
Example fix
// before // MY_PROVIDER_KEY= (empty) // after // echo 'export MY_PROVIDER_KEY=sk-...' >> ~/.bashrc && source ~/.bashrc
Defensive patterns
Strategy: validation
Validate before calling
function assertApiKey(provider, params = {}) {
if (provider.requiresApiKey !== false && !params.apiKey) {
const key = process.env[provider.apiKeyEnvVar];
if (!key) throw new Error(`Set ${provider.apiKeyEnvVar} before calling ${provider.name}`);
return { ...params, apiKey: key };
}
return params;
} Type guard
function hasApiKey(p) {
return typeof p === 'object' && p !== null && typeof p.apiKey === 'string' && p.apiKey.length > 0;
} Try / catch
try {
await provider.validateAuth(params);
} catch (e) {
if (e.message.endsWith('API key is required')) {
console.error(`Missing key: export ${provider.apiKeyEnvVar}=<your key>`);
process.exitCode = 1;
return;
}
throw e;
} Prevention
- Load .env files before constructing clients
- Check required env vars at app startup with a fail-fast check
- Set requiresApiKey: false for keyless providers
- Never rely on keys being present in CI — inject them as secrets
When it happens
Trigger: Calling an API method (via getClient/validateAuth) without an apiKey param while the provider config does not set requiresApiKey: false.
Common situations: Environment variable named in apiKeyEnvVar is unset, .env file not loaded, key set under a different variable name, or provider genuinely needs no key but config didn't set requiresApiKey:false.
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
- API key environment variable name is required
- Grok CLI API key not found. Set GROK_CLI_API_KEY environment
- Required API key ${envVarName} for provider '${providerName}
- ${lastCleanErrorMessage}
- Base URL is required for OpenAI-compatible providers. Please
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/477acf3520f37b7e.
Report an issue: GitHub.