{"record":{"id":"f185e357c3f3a39e","repo":"n8n-io/n8n","slug":"failed-to-retrieve-api-key","errorCode":null,"errorMessage":"Failed to retrieve API Key","messagePattern":"Failed to retrieve API Key","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/credentials/api-key.ts","lineNumber":43,"sourceCode":"\t\t\t);\n\t\t}\n\n\t\tthis.logger.info('Using API Key authentication for Azure OpenAI.');\n\n\t\treturn {\n\t\t\tazureOpenAIApiKey: configCredentials.apiKey,\n\t\t\tazureOpenAIApiInstanceName: configCredentials.resourceName,\n\t\t\tazureOpenAIApiVersion: configCredentials.apiVersion,\n\t\t\tazureOpenAIEndpoint: configCredentials.endpoint,\n\t\t};\n\t} catch (error) {\n\t\tif (error instanceof OperationalError) {\n\t\t\tthrow error;\n\t\t}\n\n\t\tthis.logger.error(`Error setting up API Key authentication: ${error.message}`, error);\n\n\t\tthrow new NodeOperationError(this.getNode(), 'Failed to retrieve API Key', error);\n\t}\n}\n","sourceCodeStart":25,"sourceCodeEnd":46,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/llms/LmChatAzureOpenAi/credentials/api-key.ts#L25-L46","documentation":"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.","triggerScenarios":"this.getCredentials() throws — credential not found, decryption error, encrypted credential blob missing, DB issue — or any non-Operational error while reading the Azure credential.","commonSituations":"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.","solutions":["Confirm the Azure OpenAI API credential still exists and is selected in the node.","Verify the n8n encryption key is unchanged (credentials decrypt correctly).","Read the wrapped cause — for OperationalError, follow its message; otherwise treat as a credential/data issue.","Recreate the credential if it cannot be decrypted or read."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: confirm the credential exists\ntry {\n  await this.getCredentials(credentialName);\n} catch (e) {\n  throw new Error(`Credential '${credentialName}' not available: ${(e as Error).message}`);\n}","typeGuard":"const isOperationalError = (e: unknown): e is OperationalError =>\n  e instanceof OperationalError;","tryCatchPattern":"try {\n  return config;\n} catch (e) {\n  if (e instanceof OperationalError) throw e;\n  logger.error(e);\n  throw new NodeOperationError(this.getNode(), 'Failed to retrieve API Key', e as Error);\n}","preventionTips":["Confirm the credential still exists before execution.","Keep the n8n encryption key stable so credentials decrypt reliably.","Preserve OperationalError so upstream context is not lost."],"tags":["azure","openai","credentials","wrapping","operational"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}