How to Connect n8n to Perplexity: Add Real-Time AI Research to Any Workflow (2025)
Most LLM nodes in n8n answer from stale training data. Perplexity's Sonar API is different: every response is grounded in a live web search and comes back with the actual source URLs it used. This guide shows you how to connect n8n to Perplexity through the HTTP Request node, parse the answer and its citations, and wire it into a real monitoring workflow that ships a source-backed summary to Slack or email.
What Perplexity's Sonar API adds over a plain LLM
When you call GPT-4, Claude, or Gemini directly, you get a well-written answer based on what the model memorized during training. That's fine for reasoning and rewriting, but it fails the moment you ask “what happened this week” or “what's the current pricing of X.” The model either refuses, hallucinates, or gives you outdated information with total confidence.
Perplexity's Sonar models close that gap in two concrete ways:
- Live web retrieval on every call. Sonar runs a real search before answering, so responses reflect the current state of the web, not a training cutoff.
- Citations you can verify. The API returns a citations array of the URLs it actually read. That's the killer feature for business use: you can attach sources to a briefing, fact-check a claim, or route a human to the original document.
For any workflow where accuracy and freshness matter — competitive monitoring, market research, news digests, due diligence — that combination is what makes Sonar worth wiring in.
Step 1: Get a Perplexity API key
The API is separate from a Perplexity Pro chat subscription. Here's the path:
- Go to the Perplexity API settings at perplexity.ai/settings/api and sign in.
- Add a payment method — the API is pay-as-you-go and billed against a prepaid credit balance, so you'll need to load a small amount (a few dollars is plenty to test).
- Click Generate to create an API key. It starts with pplx-.
- Copy it immediately and store it as an n8n credential so it never sits in plain text inside a node.
In n8n, the cleanest approach is to create a Header Auth credential: set the name to Authorization and the value to Bearer pplx-your-key-here. Then the HTTP Request node just references the credential instead of exposing your key in the workflow JSON.
Step 2: Configure the HTTP Request node
Perplexity's API is OpenAI-compatible, so it's a single POST to a chat-completions endpoint. Configure the n8n HTTP Request node like this:
- Method: POST
- URL: https://api.perplexity.ai/chat/completions
- Authentication: the Header Auth credential you created (or, if you prefer, add the header manually).
- Headers: Authorization: Bearer pplx-your-key and Content-Type: application/json
- Body Content Type: JSON
The JSON body follows the standard chat format. A minimal request looks like this:
- model — which Sonar model to use (see below)
- messages — an array with a system message (how to behave) and a user message (the actual question)
A concrete body you can paste into the node:
{ "model": "sonar", "messages": [ { "role": "system", "content": "You are a research assistant. Answer concisely and cite your sources." }, { "role": "user", "content": "What are the most significant n8n product updates in the last 7 days?" } ] }
To inject data from an earlier node, switch the body field to an expression and drop your variable into the user content — for example =... "content": "Summarize this week's news about {{ $json.topic }}" .... That one change turns a static call into a reusable research engine driven by whatever topic upstream nodes feed it.
Which model to pick
- sonar — the fast, low-cost default. Great for short factual lookups, monitoring, and digests.
- sonar-pro — higher quality with deeper search and longer, more thorough answers. Use it when the output is a real deliverable someone will read.
- sonar-reasoning / sonar-reasoning-pro — add a chain-of-thought step for multi-part questions that need synthesis, not just retrieval.
Start with sonar while you build, then upgrade the model string to sonar-pro for production reports. It's a one-word change in the body.
Skip the build — grab the ready-to-import template
A complete n8n pipeline that turns any topic into a cited, source-backed research report with Perplexity Sonar — no wiring required.
Get the Perplexity Research Pipeline template →
Step 3: Parse the answer and the citations
The response mirrors the OpenAI shape, plus Perplexity's extra citations field. The two things you'll almost always want are:
- The answer text: found at choices[0].message.content. In an n8n expression that's {{ $json.choices[0].message.content }}.
- The sources: a top-level citations array of URLs — {{ $json.citations }}.
Add a Set (Edit Fields) node right after the HTTP Request to pull those into clean fields — say summary and sources — so downstream nodes aren't digging through the raw payload. If you want a tidy numbered source list for an email, a small Code node does it well: map over $json.citations and join each URL with a newline and an index, producing something like “1. https://... / 2. https://...” that you can append under the summary.
Step 4: A concrete workflow — monitor a topic, summarize with sources, notify
Here's an end-to-end pattern you can build today. It watches a topic and drops a cited briefing into your inbox or Slack on a schedule.
- Schedule Trigger — run it every morning at 8:00, or hourly for fast-moving topics.
- Set node — define your topic once (e.g. topic = "AI automation tools") so it's easy to change or loop over several topics.
- HTTP Request (Perplexity) — POST to the chat-completions endpoint with model sonar-pro and a user message like “Summarize the most important developments about {{ $json.topic }} in the last 24 hours. Give 3–5 bullet points and cite sources.”
- Set / Code node — extract summary from choices[0].message.content and format the citations array into a readable source list.
- Slack or Send Email node — post the summary followed by the numbered sources. Now every briefing is verifiable in one click.
Because Sonar does the searching, you don't need a separate search API, scraper, or RSS glue. One HTTP call replaces an entire retrieval stack.
Cost notes
Sonar is priced pay-as-you-go on two axes: the usual input and output tokens, plus a small per-request search fee because each call performs a live web search. In practice that means:
- sonar is cheap enough to run on a schedule many times a day — monitoring workflows cost pennies.
- sonar-pro costs more per call (bigger context, deeper search), so reserve it for reports that justify it.
- Keep prompts tight and cap output length — you pay for tokens you don't strictly need. Ask for “3–5 bullets” instead of an open-ended essay.
Load a small prepaid balance, watch the usage dashboard for your first week, and you'll quickly learn what a run actually costs at your volume.
Common errors and how to fix them
- 401 Unauthorized — your Authorization header is wrong. It must read Bearer pplx-... with a space after “Bearer.” A common n8n mistake is putting just the key without the Bearer prefix.
- 400 Bad Request — malformed JSON body or an invalid model name. Double-check the model string is exactly sonar or sonar-pro, and that messages is an array of objects with role and content.
- 429 Too Many Requests — you hit a rate limit or ran out of credit balance. Add a small wait between calls, or top up your balance.
- Empty or truncated answer — your output got cut off. Add a reasonable max_tokens to the body and lower temperature (e.g. 0.2) for factual, consistent research output.
- No citations returned — a very narrow or opinion-style prompt can return few or no sources. Rephrase toward a factual, searchable question and citations will populate.
Ready to automate?
You now have every piece: an API key, the HTTP Request config, the JSON body, and a way to parse the answer plus its sources into a Slack or email briefing. If you'd rather not wire all five nodes and tune the prompts yourself, the Perplexity Sonar Research Pipeline template gives you the whole flow pre-built — topic in, cited report out. Import it, drop in your key, and you're monitoring in minutes instead of an afternoon.