> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siflow.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n

> 了解如何在 n8n 中创建 OpenAI credential 并设置自定义 Base URL，接入 siflow endpoint，让 AI Agent、LLM chain 和 RAG 节点使用算秩模型。

[n8n](https://n8n.io) 是一个常用的工作流自动化平台，内置 [AI 能力](https://docs.n8n.io/build/integrate-ai/)，包括 AI Agent nodes、LLM chains 和 RAG components。它的 **OpenAI credential 支持自定义 Base URL**，因此所有 OpenAI 风格的 AI node 都可以接入 siflow endpoint（n8n Cloud 和自托管版步骤相同）。可用模型请查看 [模型广场](https://console.siflow.cn/model-inference/models)，例如 `glm-5.2`。

## 1. 创建 credential

在 [API 密钥](https://console.siflow.cn/model-inference/api_keys) 页面创建 API Key。然后在 n8n 中打开 **Credentials** 标签页，单击 **Create credential**，并在 app 选择器中选择 **OpenAI**。填写：

| 字段              | 值                                    |
| --------------- | ------------------------------------ |
| API Key         | 创建的 API Key                          |
| Organization ID | 留空                                   |
| Base URL        | `https://api.siflow.cn/model-api/v1` |

保存时，n8n 会使用 Base URL 调用 `GET /models` 测试 credential。出现 **Connection tested successfully** 表示 siflow endpoint 可访问且 key 有效。

<img src="https://mintcdn.com/siflow/CfO6jliU08Hhf849/model-inference/media/n8n-credential.png?fit=max&auto=format&n=CfO6jliU08Hhf849&q=85&s=a3dd6b582d2ee2a541bacd9db3781090" alt="n8n 中配置 siflow API 凭据并测试连接成功" width="3024" height="1654" data-path="model-inference/media/n8n-credential.png" />

## 2. 在 workflow 中使用

1. 创建一个包含 **Chat Trigger**（"On chat message"）和 **AI Agent** node 的 workflow。
2. 打开 AI Agent node，单击 **+ Chat Model**，选择 **OpenAI Chat Model**。
3. 在 OpenAI Chat Model node 中，选择 credential（在 n8n Cloud 中，需要先选择 **My own credential**）。**Model** 下拉菜单会从 `/models` endpoint 实时加载模型，选择 `glm-5.2`。n8n 1.82.0 起，AI Agent node 作为 Tools Agent 运行，因此模型必须支持原生 tool calling；`glm-5.2` 支持。切换模型前请查看平台的 tool-calling 模型列表。
4. 关闭 **Use Responses API**。该 toggle 面向 OpenAI 自有 API。
5. 至少连接一个 tool sub-node 到 AI Agent。这是文档要求，例如 Calculator tool。

该 credential 会被 **OpenAI Chat Model**、**Embeddings OpenAI** 和普通 **OpenAI** nodes 共享。建议优先使用 Chat Model sub-node：许多普通 OpenAI node operations（image、audio、files）会调用 OpenAI-specific endpoints。

对于基于 embeddings 的 workflows（RAG），在同一个 credential 上添加 **Embeddings OpenAI** node，并从 [模型广场](https://console.siflow.cn/model-inference/models) 选择 embedding 模型。

## 验证

打开 chat panel，发送一条会触发工具的消息，例如 "what is 17 \* 23?"。如果返回流式回复，并且 logs 中可以看到 tool call 和结果 `391`，即表示连接和 tool calling 均正常。若只想测试普通 completion，可使用 Basic LLM Chain root node，并配置相同的 OpenAI Chat Model sub-node。

<img src="https://mintcdn.com/siflow/CfO6jliU08Hhf849/model-inference/media/n8n-agent-reply.png?fit=max&auto=format&n=CfO6jliU08Hhf849&q=85&s=2aec76429287e92e3bf637d5ab810f2c" alt="n8n AI Agent 调用工具并使用算秩模型返回计算结果" width="3024" height="1654" data-path="model-inference/media/n8n-agent-reply.png" />

## FAQ

* **Model dropdown 为空**：说明 `GET /models` 调用失败。请重新检查 Base URL（需要 `/v1` 后缀，且不要带末尾斜杠）和 API Key。
* **快速测试建议使用哪个工具？** 建议使用 Calculator tool。如果使用 **Code** tool，每个参数都必须单独启用 AI 填充（单击参数上的 ✨，否则会出现 `No parameters are set up to be filled by AI`），并且 Code node 运行在独立 task runner 上；如果未启用该 runner，会在 60s 后超时。Calculator 可以避开这两个问题。
