How to Integrate with N8N

Learn how to use the SnackPrompt AI Engine API as a knowledge source for AI agents and workflows in N8N.

Overview

N8N offers several ways to integrate external APIs with its AI capabilities:

Method
Use Case
Description

HTTP Request Tool

Agents with tools

Agent decides when to query the API

HTTP Request Node

RAG in workflows

Direct call at a specific point in the workflow

Custom Retriever

Advanced RAG

Replace native vector store with external API

Integration Architecture

┌─────────────────────────────────────────────────────────┐
│                        N8N                              │
│  ┌─────────────┐    ┌─────────────┐    ┌────────────┐   │
│  │   Trigger   │───▶│  AI Agent   │───▶│  Response │   │
│  └─────────────┘    └──────┬──────┘    └────────────┘   │
│                            │                            │
│                     ┌──────▼──────┐                     │
│                     │ HTTP Tool   │                     │
│                     └──────┬──────┘                     │
└────────────────────────────┼────────────────────────────┘


              ┌──────────────────────────────┐
              │  SnackPrompt AI Engine API   │
              │  /v1/kb/search or /v1/kb/chat│
              └──────────────────────────────┘

Use when you want the agent to autonomously decide when to search your knowledge base.

Step 1: Configure the AI Agent

  1. Add an AI Agent node to your workflow

  2. Configure the LLM model (OpenAI, Anthropic, etc.)

  3. Connect an HTTP Request Tool as a tool

Step 2: Configure the HTTP Request Tool

Tool Settings:

Field
Value

Name

search_knowledge_base

Description

Use this tool to search for information in the company knowledge base. Send a natural language query to find relevant documents about products, policies, procedures, etc.

Method

POST

URL

https://api-integrations.snackprompt.com/v1/kb/search

Headers:

Body (JSON):

Step 3: Optimize the Response

In the HTTP Request Tool Options section:

  • Optimize Response: Enabled

  • Response Format: JSON

  • Limit Response Size: Recommended to reduce tokens

Complete Workflow Example

The agent will receive a question, decide if it needs to query the knowledge base, perform the search, and use the results to formulate the response.


Method 2: HTTP Request Node (Direct RAG)

Use when you want a deterministic workflow where the search always happens.

Simple RAG Workflow

HTTP Request Node Configuration

Method: POST

URL:

Headers:

Body:

Formatting the Context

Use a Set Node or Code Node to format the results:

AI Chain Prompt


Method 3: Chat Endpoint for Complete Responses

Use the /v1/kb/chat endpoint when you want the API to handle all the RAG and return a ready response.

Configuration

URL:

Headers:

Body:

Response

The API returns:

  • answer: AI-generated response

  • sources: Sources used to generate the response

You can use it directly or enrich with additional logic in N8N.


Practical Use Cases

1. Support Chatbot

Ideal for simple chatbots that need to answer questions about products, policies, etc.

2. Multi-tool Agent

The agent can search for information AND execute actions.

3. RAG with Multiple Sources

Search in different categories and combine the results.

4. Response Validation

The agent generates a response, searches for validation in the knowledge base, and refines.


Configuration Tips

1. Tool Description is Crucial

The HTTP Request Tool description determines when the agent will use it:

2. Limit the Results

Too many results = too many tokens = higher cost and possible confusion:

3. Use Filters for Context

Direct the search with tags when you know the context:

4. Handle Errors

Add an Error Trigger or use Continue On Fail to handle API failures.


Complete Example: Sales Chatbot

Workflow

  1. Chat Trigger: Receives user message

  2. AI Agent: Processes with GPT-4

  3. HTTP Request Tool: Searches products and prices

  4. HTTP Request Tool: Searches discount policies

  5. Response: Returns response to user

Agent Configuration

System Prompt:

Tools:

Tool
Description

search_products

Search for product information, specifications, and pricing

search_policies

Search for discount policies, payment terms, and conditions


Troubleshooting

Error: "tenant_id is required"

Make sure tenant_id is inside the filters object:

Agent doesn't use the tool

  1. Improve the tool description

  2. Add examples in the system prompt

  3. Verify if the question actually requires the tool

Response too long/truncated

  1. Reduce the results limit

  2. Enable Optimize Response on the tool

  3. Use a Code Node to summarize before passing to the LLM


External Resources

Last updated

Was this helpful?