# n8n

Build powerful AI workflows with Tensorix and n8n, the open-source automation platform.

***

## Overview

[n8n](https://n8n.io/) is a popular workflow automation tool that supports custom AI integrations. With Tensorix's OpenAI-compatible API, you can use any of our models in your n8n workflows.

### What You Can Build

* 🤖 **AI Agents** - Autonomous agents with tool calling
* 📧 **Email Assistants** - Auto-respond, classify, summarize emails
* 📊 **Data Processing** - Analyze and transform data with AI
* 💬 **Chatbots** - Deploy conversational AI on any channel
* 📝 **Content Pipelines** - Generate, edit, translate content
* 🔍 **RAG Systems** - Build knowledge-based Q\&A workflows

***

## Prerequisites

* n8n instance (Cloud or self-hosted)
* Tensorix API key from [app.tensorix.ai](https://app.tensorix.ai)

***

## Method 1: OpenAI Chat Model Node (Recommended)

The easiest way to use Tensorix with n8n's AI features like AI Agents and LangChain nodes.

### Step 1: Create OpenAI Credentials

1. In n8n, go to **Credentials** → **Add Credential**
2. Search for **OpenAI API**
3. Configure the credential:

| Field               | Value                        |
| ------------------- | ---------------------------- |
| **API Key**         | Your Tensorix API key        |
| **Base URL**        | `https://api.tensorix.ai/v1` |
| **Organization ID** | Leave empty                  |

4. Click **Save**

### Step 2: Use in AI Agent Node

1. Add an **AI Agent** node to your workflow
2. Connect an **OpenAI Chat Model** sub-node
3. Select your Tensorix credential
4. Configure the model:

| Setting         | Recommended Value             |
| --------------- | ----------------------------- |
| **Model**       | `deepseek/deepseek-chat-v3.1` |
| **Temperature** | `0.7` (or as needed)          |
| **Max Tokens**  | `4096`                        |

### Step 3: Test Your Setup

Create a simple test workflow:

```
Manual Trigger → AI Agent → Output
```

Example prompt: "Explain quantum computing in simple terms"

***

## Method 2: HTTP Request Node (Advanced)

For full control over API calls or using features not exposed in the OpenAI node.

### Chat Completion Request

Add an **HTTP Request** node with these settings:

**Request Configuration:**

| Field          | Value                                         |
| -------------- | --------------------------------------------- |
| Method         | `POST`                                        |
| URL            | `https://api.tensorix.ai/v1/chat/completions` |
| Authentication | Header Auth                                   |

**Headers:**

| Header        | Value                 |
| ------------- | --------------------- |
| Authorization | `Bearer YOUR_API_KEY` |
| Content-Type  | `application/json`    |

**Body (JSON):**

```json
{
  "model": "deepseek/deepseek-chat-v3.1",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user", 
      "content": "{{ $json.userMessage }}"
    }
  ],
  "max_tokens": 1000,
  "temperature": 0.7
}
```

### Extract the Response

Add a **Code** node after the HTTP Request:

```javascript
const response = $input.first().json;
const aiMessage = response.choices[0].message.content;

return [{
  json: {
    response: aiMessage,
    model: response.model,
    tokens: response.usage
  }
}];
```

***

## Method 3: Custom n8n Credential (Pro Tip)

Create a reusable HTTP credential for Tensorix:

1. Go to **Credentials** → **Add Credential**
2. Select **Header Auth**
3. Configure:

| Field | Value                 |
| ----- | --------------------- |
| Name  | `tensorix-api`        |
| Name  | `Authorization`       |
| Value | `Bearer YOUR_API_KEY` |

Now use this credential in any HTTP Request node targeting `https://api.tensorix.ai`.

***

## Example Workflows

### 1. Email Classifier Agent

Automatically classify incoming emails and route them:

```
Email Trigger (IMAP)
    ↓
AI Agent (Tensorix)
    ↓
Switch (by classification)
    ↓
├── Support → Create Ticket
├── Sales → Forward to Sales
└── Spam → Archive
```

**System Prompt:**

```
You are an email classifier. Analyze the email and respond with exactly one of:
- SUPPORT (customer service issues)
- SALES (product inquiries, pricing)
- SPAM (promotional, unwanted)
- OTHER (everything else)

Email content: {{ $json.text }}
```

### 2. Content Generator Pipeline

Generate blog posts from topics:

```
Webhook
    ↓
AI Agent (Generate Outline)
    ↓
Loop Over Items
    ↓
AI Agent (Write Section)
    ↓
Merge
    ↓
Google Docs (Create)
```

### 3. RAG-Powered Support Bot

Build a knowledge-based chatbot:

```
Chat Trigger
    ↓
Pinecone (Search)
    ↓
AI Agent (with context)
    ↓
Respond to Chat
```

**System Prompt:**

```
You are a support assistant. Answer questions using ONLY the provided context.
If the answer isn't in the context, say "I don't have information about that."

Context:
{{ $json.searchResults }}

Question: {{ $json.userQuestion }}
```

### 4. Slack AI Assistant

```
Slack Trigger (message)
    ↓
AI Agent (Tensorix)
    ↓
Slack (reply)
```

***

## Recommended Models

| Use Case              | Model                         | Notes                               |
| --------------------- | ----------------------------- | ----------------------------------- |
| **General AI Agent**  | `deepseek/deepseek-chat-v3.1` | Best balance of capability and cost |
| **Complex Reasoning** | `deepseek/deepseek-r1-0528`   | For multi-step analysis             |
| **Code Generation**   | `z-ai/glm-5.1`                | Optimized for coding tasks          |
| **Long Documents**    | `meta-llama/llama-4-maverick` | Long document processing            |
| **Tool Calling**      | `deepseek/deepseek-chat-v3.1` | Strong function calling support     |

***

## Troubleshooting

### "Invalid API Key" Error

* Verify your API key is correct
* Ensure you're using the full key (starts with `tn_` or similar)
* Check that Base URL is exactly `https://api.tensorix.ai/v1`

### Model Not Found

* Use the full model identifier (e.g., `deepseek/deepseek-chat-v3.1`)
* Check [available models](https://tensorix.ai/models) for exact names

### Timeout Errors

* Increase timeout in HTTP Request node options
* Consider using streaming for long responses
* For reasoning models, set timeout to 120+ seconds

### Rate Limits

If you hit rate limits:

1. Add a **Wait** node between API calls
2. Use the **Split in Batches** node for bulk processing
3. Implement retry logic with the **Error Trigger**

***

## Best Practices

1. **Use System Prompts** - Always include clear instructions
2. **Set Temperature Appropriately** - Lower (0.3) for factual, higher (0.8) for creative
3. **Limit Max Tokens** - Prevent unexpectedly long responses
4. **Cache Responses** - Store results to avoid redundant API calls
5. **Handle Errors Gracefully** - Use Error Trigger for fallbacks
6. **Secure Credentials** - Never expose API keys in workflow data

***

## See Also

* [API Reference](https://github.com/Tensorix-ai/tensorix-docs/blob/main/api-reference/overview/README.md) - Complete API documentation
* [Models](https://github.com/Tensorix-ai/tensorix-docs/blob/main/api-reference/models/README.md) - Available models and capabilities
* [n8n AI Documentation](https://docs.n8n.io/advanced-ai/) - Official n8n AI guides


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorix.ai/automation-platforms/n8n.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
