I am using n8n Cloud and trying to call the Perplexity API.
When I call the API from my Mac terminal with curl, it works fine:
curl “https://api.perplexity.ai/chat/completions”
-H “Authorization: Bearer pplx-XXXX”
-H “Content-Type: application/json”
-d ‘{“model”:“sonar”,“messages”:[{“role”:“user”,“content”:“test”}]}’
This returns a valid JSON response with choices etc. (so the API key and endpoint are correct).
However, when I try to do the exact same request from an HTTP Request node on n8n Cloud, I always get:
Authorization failed - please check your credentials
401 Authorization Required – openresty/1.27.4
Here is my node configuration:
-
Method: POST
-
URL:
https://api.perplexity.ai/chat/completions -
Authentication: None
-
Send Headers: ON
-
Headers:
-
Authorization: Bearer pplx-XXXX -
Content-Type: application/json
-
-
Body Content Type: JSON
-
Body parameters:
-
model: sonar -
messages[0][role]: user -
messages[0][content]: test
-
So in theory, this should be identical to the curl request that works.
I am on n8n Cloud (simondupont.app.n8n.cloud).
Is there any known issue with calling Perplexity from n8n Cloud (proxy, Cloudflare, header being rewritten, etc.) that could explain why the HTTP Request node gets a 401 while curl with the same API key works?
I can share screenshots of the node configuration and the raw HTTP logs if needed.
Thanks!