{"record":{"id":"0cf9a8d0a4d2c127","repo":"n8n-io/n8n","slug":"authentication-failed-invalid-api-key-or-endpoin","errorCode":null,"errorMessage":"Authentication failed - invalid API key or endpoint.","messagePattern":"Authentication failed - invalid API key or endpoint\\.","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.ts","lineNumber":299,"sourceCode":"\t\tif (error instanceof NodeOperationError) {\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Log the full error for debugging\n\t\tcontext.logger.debug('Azure AI Search connection error:', {\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\tcode: (error as any).code,\n\t\t\tstatusCode: (error as any).statusCode,\n\t\t\tdetails: (error as any).details,\n\t\t});\n\n\t\t// Check for authentication errors\n\t\tif (\n\t\t\terror.message?.includes('401') ||\n\t\t\terror.message?.includes('Unauthorized') ||\n\t\t\terror.message?.includes('authentication failed')\n\t\t) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tcontext.getNode(),\n\t\t\t\t'Authentication failed - invalid API key or endpoint.',\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Please verify your API Key and Search Endpoint are correct in the credentials configuration.',\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Check for authorization errors (403)\n\t\tif (error.message?.includes('403') || error.message?.includes('Forbidden')) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tcontext.getNode(),\n\t\t\t\t'Authorization failed - insufficient permissions.',\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription:","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.ts#L281-L317","documentation":"In the connection/initialization catch block of getAzureAISearchClient, an error whose message contains '401', 'Unauthorized', or 'authentication failed' is reclassified as an authentication NodeOperationError. It means Azure AI Search rejected the API key or endpoint during client setup/index access.","triggerScenarios":"Any error thrown while constructing the SearchClient or accessing the index during connection, where error.message includes '401' / 'Unauthorized' / 'authentication failed'.","commonSituations":"Wrong API key; endpoint URL belongs to a different search service; key was revoked or expired in Azure; a query key used where the operation needs an admin key during setup.","solutions":["Verify the API key and Search Endpoint in the credential match the Azure search service.","Regenerate/confirm the key in the Azure portal and update the credential.","Ensure the endpoint URL exactly matches your Azure AI Search service name.","Run a manual REST call to the endpoint with the key to isolate n8n vs Azure."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Smoke-test the credential with a lightweight call before the workflow runs.\nconst res = await fetch(`${endpoint}/indexes?api-version=2023-11-01`, {\n  headers: { 'api-key': apiKey },\n});\nif (res.status === 401) throw new Error('Azure AI Search key/endpoint rejected (401).');","typeGuard":null,"tryCatchPattern":"try {\n  client = await getAzureAISearchClient(context, embeddings, itemIndex);\n} catch (e) {\n  if (/401|Unauthorized|authentication failed/i.test(e.message ?? '')) {\n    // prompt user to fix API key/endpoint\n  }\n}","preventionTips":["Run a connection test against the Azure AI Search endpoint after entering credentials.","Avoid relying on error.message substring matching in your own code — prefer error.statusCode when available."],"tags":["azure-ai-search","vector-store","authentication","error-classification","http-401"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}