HTTP Request fails with 401, but external cURL with same Bearer Token succeeds

Describe the problem/error/question

Hello n8n Community,

I am having a persistent 401 Unauthorized error when trying to connect to the Leonardo.AI API using the HTTP Request node.

The key issue is that my API key is 100% valid. I can get a successful 200 OK response using the exact same key with an external cURL command, but it fails every time from my n8n.cloud instance.

I have tried creating both Bearer Token Auth and Header Auth credentials in n8n, and both methods fail. This suggests there is an issue with how n8n is sending the Authorization header for my specific account.

What is the error message (if any)?

{
“errorMessage”: “Authorization failed - please check your credentials”,
“errorDescription”: “Authentication hook unauthorized this request”,
“errorDetails”: {
“httpCode”: “401”
}
}

Please share your workflow

{
“name”: “Probar Leonardo”,
“nodes”: [
{
“parameters”: {},
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
0,
0
],
“id”: “1c25359f-b755-4274-9e02-3f4c26213780”,
“name”: “When clicking ‘Test workflow’”
},
{
“parameters”: {
“url”: “https://cloud.leonardo.ai/api/rest/v1/me”,
“authentication”: “genericCredentialType”,
“genericAuthType”: “httpBearerAuth”,
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
220,
0
],
“id”: “617204af-a3ce-492f-a1b8-ff0f53f34204”,
“name”: “HTTP Request”,
“credentials”: {
“httpHeaderAuth”: {
“id”: “joWUbEmMhfPp9UAn”,
“name”: “Leonardo Key DEFINITIVA”
},
“httpBearerAuth”: {
“id”: “fM303SGEzWx634nv”,
“name”: “bearer leonardo 2”
}
}
}
],
“pinData”: {},
“connections”: {
“When clicking ‘Test workflow’”: {
“main”: [
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“active”: false,
“settings”: {
“executionOrder”: “v1”
},
“versionId”: “140bc24b-3e1e-4efc-9904-6f6315a8a4d0”,
“meta”: {
“instanceId”: “d48c228501075632274dfc5669b5f2df96777667ebc0a39be26af58bfd0d92da”
},
“id”: “LEBbs7fproisZ5gi”,
“tags”:
}

Share the output returned by the last node

The output is the same 401 Unauthorized error shown above.

Information on your n8n setup

  • n8n version: 1.91.3
  • Database (default: SQLite): Default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n.cloud
  • Operating system: Not applicable (using n8n.cloud)


Hi there, i noticed you are using the bearer auth, which is correct,but u have to note that the bearer auth, put the "Bearer " in the background, so in here (image below) no need to put any Bearer ${API_KEY} again, but just put ${API_KEY}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.