Perplexity icon

Perplexity

Interact with Perplexity AI API

Overview

This n8n node allows you to interact with the Perplexity AI API, specifically to create chat completions using various available models. It is designed for scenarios where you want to automate conversations or generate responses using Perplexity's large language models within your workflows. Common use cases include building chatbots, automating customer support, generating content, or integrating advanced conversational AI into business processes.

Practical examples:

  • Automate answering user queries by sending a series of messages and receiving an AI-generated response.
  • Use as part of a workflow to summarize documents or provide reasoning based on user input.
  • Integrate with other systems (e.g., CRM, helpdesk) to provide intelligent, context-aware replies.

Properties

Display Name Type Description
Model options The model to use for completion. Choices include Sonar, Sonar Pro, Llama 3.1 variants, etc.
Messages fixedCollection The messages to send to the API. Each message has a Role (System/User/Assistant) and Content.
Additional Fields collection Optional parameters:
- Temperature (number, 0–2): Sampling temperature.
- Max Tokens (number): Maximum tokens to generate.
- Top P (number, 0–1): Nucleus sampling parameter.

Details

  • Model: Selects which Perplexity AI model will process your request.
  • Messages: A list of message objects, each with:
    • Role: The role of the sender (system, user, or assistant).
    • Content: The text content of the message.
  • Additional Fields:
    • Temperature: Controls randomness in output (higher = more random).
    • Max Tokens: Limits the length of the generated response.
    • Top P: Alternative to temperature for controlling diversity.

Output

The node outputs a single item per input, with the following structure:

{
  "json": {
    // The full JSON response from the Perplexity AI API.
    // Typically includes fields like 'id', 'object', 'created', 'model', 'choices', etc.
  }
}
  • If an error occurs and "Continue On Fail" is enabled, the output will be:
{
  "json": {
    "error": "Error message here"
  }
}

Note: The exact structure of the successful response depends on the Perplexity API, but it generally contains the generated message(s) and metadata.

Dependencies

  • External Service: Requires access to the Perplexity AI API.
  • API Key: You must configure Perplexity API credentials in n8n under the name perplexityApi.
  • n8n Configuration: No additional environment variables are required beyond the API key setup.

Troubleshooting

Common Issues:

  • Invalid API Key: If the API key is missing or incorrect, authentication will fail.
  • Model Not Supported: Selecting a model not available in your Perplexity account may result in errors.
  • Input Validation: Supplying invalid values for properties (e.g., out-of-range temperature) can cause API errors.
  • Malformed Messages: Omitting required fields in messages (role/content) may lead to request failures.

Error Handling:

  • If "Continue On Fail" is enabled, errors are returned in the json.error field.
  • Otherwise, the node will stop execution and throw the error.

Common Error Messages:

  • "Request failed with status code 401": Check your API credentials.
  • "Invalid model": Ensure the selected model is correct and available.
  • "Missing required property: messages": Make sure at least one message is provided.

Links and References

Discussion