Perplexity AI Content Generation Module (Sonar Models) - n8n Workflow

Automate content generation using Perplexity's powerful Sonar models. This reusable n8n workflow template handles API calls, dynamic prompting, and secure authentication.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Automation specialists looking for pre-built n8n templates for advanced AI tasks.

  • Developers needing a centralized Perplexity integration module within a larger n8n workflow.

  • Content creators aiming to rapidly generate text using reliable LLM APIs via an n8n node.

  • Users leveraging n8n to build multi-step AI agents requiring dynamic system and user prompts.

Overview

This n8n workflow template solves the complexity of integrating external LLM APIs by wrapping the Perplexity API call into a clean, modular structure. Designed specifically as a sub-workflow, it accepts required system and user prompts, handles the necessary JSON body construction, and ensures secure authentication using HTTP headers. This reusable design dramatically simplifies maintenance and allows you to call the LLM service from any other parent n8n workflow using the "Execute Workflow" n8n node, ensuring separation of concerns and robust error handling across your main n8n automation.

How it Works

The execution of this robust n8n workflow starts with the When Executed by Another Workflow n8n trigger. This trigger is configured to receive two critical inputs: SystemPrompt (to define the AI's behavior) and UserPrompt (the specific instruction).


  1. Input Reception: The n8n trigger receives the dynamic prompts from the parent n8n workflow.

  2. Parameter Setting: The Parameters n8n node immediately sets the desired Perplexity model, defaulting to sonar. This value is easily changeable to sonar-pro if required.

  3. API Execution: The flow moves to the Perplexity API Request n8n node (an HTTP Request node). This n8n node constructs the complex JSON payload required by the Perplexity /chat/completions endpoint. It securely injects the defined model name and maps the incoming SystemPrompt and UserPrompt into the standardized messages array.

  4. Security: Authentication is handled securely via generic HTTP Header Authentication, requiring the API key to be set up as an n8n credential.

  5. Output: The Perplexity API response, containing the generated AI text, is passed as the final output, ready to be consumed by the calling n8n workflow.

Installation Guide

To use this powerful n8n workflow template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it into your n8n instance using the "New" -> "Import from JSON" option.

  2. Setup Credentials: This n8n workflow requires a Perplexity API key credential.

In the Perplexity API Request n8n node, select Authentication: Generic Credential Type.
Choose HTTP Header Auth.
* Create a new credential: The Header Name must be Authorization. The Header Value should be your Perplexity API Key, usually prefixed with Bearer (e.g., Bearer pp-xxxxxxxx).

  1. Activate and Test: Activate the n8n workflow. Because this module is designed to be triggered by an 'Execute Workflow' n8n node, you must set up a separate parent n8n workflow to pass the necessary SystemPrompt and UserPrompt test data.

Node Details

When Executed by Another Workflow (n8n trigger):
Function: Serves as the entry point, enabling this n8n workflow to function as a reusable API module callable from any other n8n workflow.
Key Configuration: Defines two required inputs: SystemPrompt and UserPrompt.

Parameters (Set n8n node):
Function: Sets a static variable (model) for the LLM model used in the API call, ensuring easy configuration.
Key Configuration: Sets the field model to the default value of sonar.

Perplexity API Request (HTTP Request n8n node):
Function: Executes the core action: sending the secure chat completion request to the Perplexity API endpoint.
Key Configuration:
Method: POST.
Body: Dynamic JSON construction, referencing the model from the Parameters n8n node and the two prompts from the n8n trigger to form the message payload.
Authentication: Uses HTTP Header Auth for secure API key management, a vital security measure for this n8n automation.

Related n8n Workflows

Free

Nodes: 4 Nodes
Updated: December 26 2025
View all
Created by
Aleksey Panov
Aleksey Panov

Featured*