eyaltoledano/claude-task-master · error · Error

Azure API key is required

Error message

Azure API key is required

What it means

AzureProvider.validateAuth() runs before every AI call and requires an Azure API key in params.apiKey. The Azure provider authenticates with a key + endpoint URL pair; without a key the provider cannot build authenticated requests, so it fails fast with a clear message instead of a 401 from the remote API.

Source

Thrown at src/ai-providers/azure.js:30

		this.name = 'Azure OpenAI';
	}

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

	/**
	 * Validates Azure-specific authentication parameters
	 * @param {object} params - Parameters to validate
	 * @throws {Error} If required parameters are missing
	 */
	validateAuth(params) {
		if (!params.apiKey) {
			throw new Error('Azure API key is required');
		}

		if (!params.baseURL) {
			throw new Error(
				'Azure endpoint URL is required. Set it in .taskmasterconfig global.azureBaseURL or models.[role].baseURL'
			);
		}
	}

	/**
	 * Normalizes the base URL to ensure it ends with /openai for proper Azure API routing.
	 * The Azure API expects paths like /openai/deployments/{model}/chat/completions
	 * @param {string} baseURL - Original base URL
	 * @returns {string} Normalized base URL ending with /openai
	 */
	normalizeBaseURL(baseURL) {
		if (!baseURL) return baseURL;

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Set AZURE_AZURE_OPENAI_API_KEY in your environment or .env file
  2. Add the key to the models config so it is injected into params
  3. Verify with `tm models --setup` that the azure role has credentials configured

Example fix

// before (.env)
# AZURE_AZURE_OPENAI_API_KEY not set
// after (.env)
AZURE_AZURE_OPENAI_API_KEY=your-azure-openai-key
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.AZURE_AZURE_OPENAI_API_KEY) throw new Error('Set AZURE_AZURE_OPENAI_API_KEY before using the azure provider');

Type guard

function hasAzureAuth(params) { return typeof params?.apiKey === 'string' && params.apiKey.length > 0; }

Try / catch

try {
  await provider.generateText(params);
} catch (err) {
  if (err.message === 'Azure API key is required') {
    console.error('Configure the Azure API key via env or `tm models --setup`');
  } else throw err;
}

Prevention

When it happens

Trigger: Calling generateText/streamText/etc. via the azure provider when AZURE_AZURE_OPENAI_API_KEY (or the configured key source) is unset, or params.apiKey is undefined in direct provider use.

Common situations: API key not exported in shell/env; .env not loaded; key set under the wrong env var name; models config maps a role to azure without a key.

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/92643aca774baec8. Report an issue: GitHub.