Perplexity icon

Perplexity

Interact with Perplexity AI API

Overview

The Perplexity node for n8n enables you to interact with the Perplexity AI API, specifically to create chat completions using a variety of large language models. This node is ideal for scenarios where you want to automate conversations, generate text responses, or build chatbots powered by Perplexity's AI models within your workflows.

Practical examples:

  • Automating customer support replies.
  • Generating creative content or summaries based on user prompts.
  • Building conversational agents that leverage advanced reasoning models.

Properties

Model

  • Type: Options (dropdown)
  • Description: The model to use for completion.
  • Required: Yes
  • Options:
    • Sonar Deep Research
    • Sonar Reasoning Pro
    • Sonar Reasoning
    • Sonar Pro
    • Sonar
    • R1 1776
    • Llama 3.1 Sonar Small (Legacy)
    • Llama 3.1 Sonar Large (Legacy)
    • Llama 3.1 Sonar Huge (Legacy)

Messages

  • Type: Collection (multiple values allowed)
  • Description: The messages to send to the API, forming the conversation history.
  • Fields per message:
    • Role: Options (System, User, Assistant) — Specifies who is sending the message.
    • Content: String — The actual message content.

Additional Fields

  • Type: Collection (optional)
  • Description: Extra parameters to fine-tune the completion.
  • Options:
    • Temperature: Number (0–2, default 0.7) — Sampling temperature; higher values make output more random.
    • Max Tokens: Number (default 1024) — Maximum number of tokens to generate in the response.
    • Top P: Number (0–1, default 0.9) — Nucleus sampling parameter; controls diversity via probability mass.

Output

  • json: The response from the Perplexity AI API. The structure will match the API's response for a chat completion request, typically including fields such as:
    • id: Unique identifier for the completion.
    • object: Type of object returned.
    • created: Timestamp of creation.
    • model: The model used.
    • choices: Array of generated completions, each containing:
      • message: The AI's reply (role and content).
      • finish_reason: Why the completion stopped.
    • usage: Token usage statistics.

If an error occurs and "Continue On Fail" is enabled, the output will be:

{
  "error": "Error message here"
}

Dependencies

  • External Service: Requires access to the Perplexity AI API.
  • API Key: You must configure Perplexity API credentials in n8n under the name perplexityApi.

Troubleshooting

Common issues:

  • Invalid API Key: If the API key is missing or incorrect, you'll receive authentication errors. Ensure your credentials are set up correctly in n8n.
  • Model Not Supported: Selecting a model not available to your account may result in an error from the API.
  • Malformed Messages: If the messages array is empty or improperly structured, the API may return a validation error.
  • Exceeded Token Limit: Setting max_tokens too high can cause the API to reject the request.

Error Handling:

  • If "Continue On Fail" is enabled, errors are returned in the output JSON under the error field.
  • Otherwise, the workflow execution will stop and display the error message.

Links and References

Discussion