{"record":{"id":"cd84f8bf30870b72","repo":"eyaltoledano/claude-task-master","slug":"api-key-environment-variable-name-is-required","errorCode":null,"errorMessage":"API key environment variable name is required","messagePattern":"API key environment variable name is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ai-providers/openai-compatible.js","lineNumber":31,"sourceCode":" */\nexport class OpenAICompatibleProvider extends BaseAIProvider {\n\t/**\n\t * @param {object} config - Provider configuration\n\t * @param {string} config.name - Provider display name\n\t * @param {string} config.apiKeyEnvVar - Environment variable name for API key\n\t * @param {boolean} [config.requiresApiKey=true] - Whether API key is required\n\t * @param {string} [config.defaultBaseURL] - Default base URL for the API\n\t * @param {Function} [config.getBaseURL] - Function to determine base URL from params\n\t * @param {boolean} [config.supportsStructuredOutputs] - Whether provider supports structured outputs\n\t */\n\tconstructor(config) {\n\t\tsuper();\n\n\t\tif (!config.name) {\n\t\t\tthrow new Error('Provider name is required');\n\t\t}\n\t\tif (!config.apiKeyEnvVar) {\n\t\t\tthrow new Error('API key environment variable name is required');\n\t\t}\n\n\t\tthis.name = config.name;\n\t\tthis.apiKeyEnvVar = config.apiKeyEnvVar;\n\t\tthis.requiresApiKey = config.requiresApiKey !== false; // Default to true\n\t\tthis.defaultBaseURL = config.defaultBaseURL;\n\t\tthis.getBaseURLFromParams = config.getBaseURL;\n\t\tthis.supportsStructuredOutputs = config.supportsStructuredOutputs;\n\t}\n\n\t/**\n\t * Returns the environment variable name required for this provider's API key.\n\t * @returns {string} The environment variable name for the API key\n\t */\n\tgetRequiredApiKeyName() {\n\t\treturn this.apiKeyEnvVar;\n\t}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/src/ai-providers/openai-compatible.js#L13-L49","documentation":"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.","triggerScenarios":"new OpenAICompatibleProvider(config) where config.apiKeyEnvVar is missing/empty.","commonSituations":"Custom provider configs omitting apiKeyEnvVar, renaming conventions (apiKey vs apiKeyEnvVar) between config versions, copying a provider example without updating the env var name field.","solutions":["Add 'apiKeyEnvVar: \"YOUR_ENV_VAR\"' to the provider config.","Set the corresponding environment variable in your shell/.env so the value exists at runtime.","Check for config schema drift (older 'apiKey' field vs 'apiKeyEnvVar').","Validate all custom provider configs in a startup check."],"exampleFix":"// before\n// new OpenAICompatibleProvider({ name: 'together', defaultBaseURL: 'https://api.together.xyz/v1' })\n// after\n// new OpenAICompatibleProvider({ name: 'together', apiKeyEnvVar: 'TOGETHER_API_KEY', defaultBaseURL: 'https://api.together.xyz/v1' })","handlingStrategy":"validation","validationCode":"function assertApiKeyEnvVar(config) {\n  if (typeof config.apiKeyEnvVar !== 'string' || !config.apiKeyEnvVar.trim()) {\n    throw new Error(`provider '${config?.name}' missing apiKeyEnvVar`);\n  }\n}","typeGuard":"function hasApiKeyEnvVar(c) {\n  return typeof c === 'object' && c !== null && typeof c.apiKeyEnvVar === 'string' && c.apiKeyEnvVar.length > 0;\n}","tryCatchPattern":"try {\n  const provider = new OpenAICompatibleProvider(config);\n} catch (e) {\n  if (e.message.includes('API key environment variable name is required')) {\n    console.error(`Add apiKeyEnvVar to provider '${config?.name}' config`);\n  }\n  throw e;\n}","preventionTips":["Include apiKeyEnvVar in every custom provider config","Standardize env var naming (e.g. <PROVIDER>_API_KEY)","Add a startup validation pass over all provider configs","Document required config fields next to provider examples"],"tags":["configuration","validation","environment-variable","openai-compatible"],"backgroundTag":"missing-config-property","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}