> For the complete documentation index, see [llms.txt](https://docs.readyidc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.readyidc.com/gpu-as-a-service/linux/docker/how-to-using-n8n-automation-guide.md).

# How to using n8n Automation guide

> Build automated workflows that use your self-hosted vLLM endpoint. Examples: document summarization, chatbots, scheduled AI tasks, webhook-triggered processing. **Prerequisite:** A running vLLM endpoint (see the vLLM Docker Deployment Guide).

## 1. What is n8n?

[n8n](https://n8n.io/) is a workflow automation tool (like Zapier/Make, but self-hosted). It connects apps, APIs, and AI models into automated pipelines via a visual editor.

**Common LLM use cases:**

* Summarize incoming emails/documents automatically
* Build a chatbot triggered by webhook
* Scheduled content generation
* Extract structured data from text
* Multi-step AI pipelines (classify → route → respond)

## 2. Deployment

### Standalone `docker-compose.yml`

```yaml
services:
  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=0.0.0.0
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - NODE_ENV=production
      - GENERIC_TIMEZONE=Asia/Bangkok
      # Basic auth (recommended)
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=change-me-strong-password
    volumes:
      - ./n8n-data:/home/node/.n8n

volumes:
  n8n-data:
```

### Add to Existing vLLM Stack

If you want n8n in the **same compose file** as vLLM (so they share a Docker network), add the `n8n` service block above into your existing `docker-compose.yml`. This lets n8n reach vLLM via the service name `http://vllm:8000`.

### Launch

```bash
docker compose up -d
docker compose logs -f n8n
```

Access: `http://<your-server-ip>:5678`

On first launch, create your owner account.

## 3. Connecting n8n to vLLM

n8n has a built-in **OpenAI node** that works with any OpenAI-compatible API — including vLLM.

### Create OpenAI Credentials in n8n

1. In n8n: **Credentials → New → OpenAI API**
2. Set:
   * **API Key:** your vLLM `--api-key` value (e.g. `sk-llm-key`)
   * **Base URL:** your vLLM endpoint
     * Same compose stack: `http://vllm:8000/v1`
     * Separate host: `http://<server-ip>:8000/v1`
3. Save

### Network Note

| n8n location              | Base URL                          |
| ------------------------- | --------------------------------- |
| Same compose file as vLLM | `http://vllm:8000/v1`             |
| Different host/server     | `http://<vllm-server-ip>:8000/v1` |
| Behind reverse proxy      | `https://api.yourdomain.com/v1`   |

## 4. Example Workflows

### Example A: Webhook Chatbot

Receives a message via webhook, sends to vLLM, returns the answer.

**Nodes:** `Webhook` → `OpenAI` → `Respond to Webhook`

1. **Webhook node**
   * Method: POST
   * Path: `/chat`
2. **OpenAI node**
   * Resource: Chat
   * Model: `Qwen/Qwen2.5-7B-Instruct-AWQ`
   * Messages: `={{ $json.body.message }}`
3. **Respond to Webhook node**
   * Body: `={{ $json.choices[0].message.content }}`

Test:

```bash
curl -X POST http://<server-ip>:5678/webhook/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "What is Kubernetes?"}'
```

### Example B: Scheduled Document Summarizer

Runs daily, fetches documents, summarizes with the LLM.

**Nodes:** `Schedule Trigger` → `HTTP Request (fetch docs)` → `OpenAI (summarize)` → `Send Email / Save`

1. **Schedule Trigger** — daily at 09:00
2. **HTTP Request** — fetch your data source
3. **OpenAI node**
   * System prompt: "Summarize the following in 3 bullet points"
   * User: `={{ $json.content }}`
4. **Output** — email, Slack, database, etc.

### Example C: Text Classification & Routing

Classify incoming text, then route to different actions.

**Nodes:** `Webhook` → `OpenAI (classify)` → `Switch` → (multiple branches)

1. **OpenAI node**
   * Prompt: "Classify this message as: support / sales / spam. Reply with one word only."
2. **Switch node** — route based on classification
3. Branch actions per category

### Tips for LLM Nodes

* Set **temperature** low (0.1-0.3) for consistent/structured output
* Use **system prompts** to control format
* For JSON output, instruct the model explicitly and parse with a **Code node**
* Set reasonable **max tokens** to control response length

## 5. Troubleshooting

#### n8n can't reach vLLM

* Same compose file → use `http://vllm:8000/v1` (service name, not localhost)
* Different host → use the server IP and ensure port 8000 is reachable
* Test from n8n container:

  ```bash
  docker exec -it n8n wget -qO- http://vllm:8000/v1/models
  ```

#### "Unauthorized" / 401

* API key in n8n credentials must match vLLM `--api-key`
* If vLLM has no `--api-key`, you can put any placeholder in n8n

#### Model not found

* Use the exact model name from `curl http://<vllm>:8000/v1/models`
* Must match the `--model` value in your vLLM config

#### Workflow times out on long generations

* Increase n8n node timeout in workflow settings
* Reduce max tokens, or use a smaller/faster model

#### Data not persisting after restart

* Ensure the `./n8n-data:/home/node/.n8n` volume is mounted
* Without it, workflows are lost on container recreation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.readyidc.com/gpu-as-a-service/linux/docker/how-to-using-n8n-automation-guide.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
