n8n-io/n8n · error · NodeOperationError

Failed to retrieve API Key

Error message

Failed to retrieve API Key

What it means

Catch in setupApiKeyAuthentication(): it re-throws an OperationalError unchanged (preserving the original message from upstream credential fetching) and wraps any other exception as NodeOperationError 'Failed to retrieve API Key' with the original as cause. Logs the error first. This pattern keeps expected operational errors distinguishable from unexpected ones.

Source

Thrown at packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/credentials/api-key.ts:43

			);
		}

		this.logger.info('Using API Key authentication for Azure OpenAI.');

		return {
			azureOpenAIApiKey: configCredentials.apiKey,
			azureOpenAIApiInstanceName: configCredentials.resourceName,
			azureOpenAIApiVersion: configCredentials.apiVersion,
			azureOpenAIEndpoint: configCredentials.endpoint,
		};
	} catch (error) {
		if (error instanceof OperationalError) {
			throw error;
		}

		this.logger.error(`Error setting up API Key authentication: ${error.message}`, error);

		throw new NodeOperationError(this.getNode(), 'Failed to retrieve API Key', error);
	}
}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Confirm the Azure OpenAI API credential still exists and is selected in the node.
  2. Verify the n8n encryption key is unchanged (credentials decrypt correctly).
  3. Read the wrapped cause — for OperationalError, follow its message; otherwise treat as a credential/data issue.
  4. Recreate the credential if it cannot be decrypted or read.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: confirm the credential exists
try {
  await this.getCredentials(credentialName);
} catch (e) {
  throw new Error(`Credential '${credentialName}' not available: ${(e as Error).message}`);
}

Type guard

const isOperationalError = (e: unknown): e is OperationalError =>
  e instanceof OperationalError;

Try / catch

try {
  return config;
} catch (e) {
  if (e instanceof OperationalError) throw e;
  logger.error(e);
  throw new NodeOperationError(this.getNode(), 'Failed to retrieve API Key', e as Error);
}

Prevention

When it happens

Trigger: this.getCredentials() throws — credential not found, decryption error, encrypted credential blob missing, DB issue — or any non-Operational error while reading the Azure credential.

Common situations: Credential deleted between workflow save and execution; encryption key changed so stored credentials can't be decrypted; DB row missing; bug in credential type definition causing a parse failure.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/f185e357c3f3a39e. Report an issue: GitHub.