How to use Perplexity API in n8n?
How to use Perplexity API in n8n is explained in simple steps below. You can call the Perplexity API from n8n by using the HTTP Request node, adding your API key in headers, and sending a JSON POST to the Perplexity endpoint. This short guide shows Docker setup, example commands, and a sample Node.js request.
What You Need
- An n8n instance (Docker recommended).
- A Perplexity API key.
- Basic knowledge of HTTP and JSON.
- Node.js available for local testing (optional).
How to use Perplexity API in n8n – Step-by-step
How to Install n8n with Docker
Start n8n in Docker with a persistent folder and port 5678. The command below runs n8n locally for quick testing.
docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n
Step 1: Store Perplexity API key
Set your API key as an environment variable in Docker or in n8n credentials. Using environment variables keeps the key out of workflows.
export PERPLEXITY_API_KEY="sk_live_your_api_key_here"
# Or set in Docker as: -e PERPLEXITY_API_KEY=$PERPLEXITY_API_KEY
Step 2: Create an HTTP Request node in n8n
Add an HTTP Request node to your workflow. Use POST, set the URL to the Perplexity endpoint, and add headers:
Method: POST
URL: https://api.perplexity.ai/search
Headers:
Authorization: Bearer {{ $env.PERPLEXITY_API_KEY }}
Content-Type: application/json
Body (JSON):
{ "query": "What is n8n?" }
Step 3: Test with curl (quick verification)
Use curl to test your API key and endpoint before wiring n8n. This verifies network and key settings.
curl -X POST "https://api.perplexity.ai/search" \
-H "Authorization: Bearer $PERPLEXITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query":"What is n8n?"}'
Step 4: Parse the response in n8n
Use a Set node or Function node to extract fields from the JSON response. For simple parsing, add a Set node and reference the response data path.
// Example Function node JavaScript to read response
const body = items[0].json.body; // adjust path to real response
return [{ json: { answer: body.answer || body.result || body } }];
Step 5: Use results in automation
Pass the extracted text to actions such as email, Slack, or database nodes. Keep payloads small to reduce latency and cost.
Update
APIs change. Check Perplexity API docs for new endpoints or parameter updates. Update node settings in n8n after any breaking change. Keep n8n updated to the latest stable release to get fixes and new features.
Security
Store the API key in environment variables or n8n credentials, not in plain workflow text. Use HTTPS endpoints only. Rotate keys regularly and limit their scope if the provider supports it. Restrict your n8n instance with a firewall or VPN and enable basic authentication for the UI.
Done
You now have a working pattern for how to use Perplexity API in n8n. Use the HTTP Request node, secure your key, and parse responses for automation steps. Expand this flow by adding triggers and downstream actions.