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

# 使用 CometAPI 在本地运行 n8n

> 使用本指南，通过配置本地部署设置、凭证和模型访问，在本地借助 CometAPI 运行 n8n。

在你自己的机器上部署 n8n，并通过社区节点将其连接到 CometAPI，以在本地运行自动化 AI 工作流。

## 先决条件

* Linux（Ubuntu/Debian/CentOS 等）或 macOS
* 2 GB 以上内存，10 GB 以上可用磁盘空间
* 可访问公共 npm 注册表的 Shell 环境
* Node.js 18.x 或 20.x LTS（见步骤 1）
* 一个拥有有效 API key 的 CometAPI 账户——[在此获取](https://www.cometapi.com/console/token)

<Steps>
  <Step title="获取你的 CometAPI API key">
    登录 [CometAPI 控制台](https://www.cometapi.com/console/token)。点击 **Add API Key** 并复制你的 CometAPI API key。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/overview/810968_364191.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=aef81a83f29f8eb16655ed4060425f50" alt="显示 Add API Key 按钮的 CometAPI 仪表盘" width="3824" height="1892" data-path="images/overview/810968_364191.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/HhtmQffktazbxUvS/images/overview/810968_364193.png?fit=max&auto=format&n=HhtmQffktazbxUvS&q=85&s=d893f659267150d0faf45f99eb5dffc1" alt="带有 Base URL 的 CometAPI API key 详情" width="2434" height="1232" data-path="images/overview/810968_364193.png" />
    </Frame>
  </Step>

  <Step title="通过 nvm 安装 Node.js">
    n8n 1.x 需要 Node.js 18.x 或 20.x。推荐使用 [nvm](https://github.com/nvm-sh/nvm)：

    ```bash theme={null}
    # Install nvm
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

    # Reload your shell profile
    source ~/.bashrc   # or ~/.zshrc on macOS

    # Install and activate the LTS version
    nvm install --lts
    nvm use --lts

    # Verify
    node -v
    npm -v
    ```

    <Note>
      如果你之后看到 `n8n: command not found`，请重启终端，或确保由 nvm 管理的 npm 全局 bin 目录已加入你的 `PATH`。
    </Note>
  </Step>

  <Step title="安装并启动 n8n">
    ```bash theme={null}
    npm install -g n8n
    n8n -v       # verify the installed version
    n8n start    # runs on http://localhost:5678/
    ```

    如果端口 5678 已被占用：

    ```bash theme={null}
    export N8N_PORT=5679
    n8n start
    ```

    要在关闭终端后仍保持 n8n 运行：

    ```bash theme={null}
    npm install -g pm2
    pm2 start "n8n" --name n8n
    pm2 save
    pm2 status
    ```

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360463.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=80fe6068a8af4ec3b3503ff41d378a17" alt="终端中显示 n8n 成功启动" width="715" height="451" data-path="images/integrations/810968_360463.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360464.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=77cadfd218dbe0fef19fe701550ea363" alt="终端中的 n8n 启动日志" width="759" height="460" data-path="images/integrations/810968_360464.png" />
    </Frame>
  </Step>

  <Step title="创建你的 owner 账户">
    在浏览器中打开 [http://localhost:5678/](http://localhost:5678/)。首次运行时，设置向导会要求你创建一个 **Owner** 账户（邮箱 + 密码）。完成后登录。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360465.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=8fdd100138f2bf01bbf834d9db1ea29e" alt="n8n 首次运行设置向导要求填写 Owner 账户信息" width="1249" height="970" data-path="images/integrations/810968_360465.png" />
    </Frame>
  </Step>

  <Step title="安装 CometAPI 社区节点">
    1. 前往 **Settings**（左下角）→ **Community nodes**
    2. 点击 **Install a community node**
    3. 输入包名：`@cometapi-dev/n8n-nodes-cometapi`
    4. 勾选风险确认框并点击 **Install**

    安装完成后，你可以在节点面板中搜索 **CometAPI**。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360467.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=1c107922e16332157d278bf834b3e32a" alt="显示 Community nodes 部分的 n8n Settings 面板" width="1265" height="975" data-path="images/integrations/810968_360467.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360468.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=98c05d77cb6adf333052b4d5014fc506" alt="已输入 CometAPI 包名的安装对话框" width="1261" height="965" data-path="images/integrations/810968_360468.png" />
    </Frame>

    <Note>
      如果看不到 Community Nodes 部分：请确认你是以 **Owner** 账户登录，并检查 **Settings → Security** 以确认已启用社区节点安装。
    </Note>
  </Step>

  <Step title="创建工作流并配置凭证">
    1. 点击顶部的 **+ New** 创建一个工作流。
    2. 点击画布上的 **+**，搜索 **CometAPI** 并添加该节点。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360469.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=b47e1304ec3165720dd3ef37e1429485" alt="打开 CometAPI 节点搜索的 n8n 工作流画布" width="1235" height="899" data-path="images/integrations/810968_360469.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360472.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=b765a2d8024f4c5d36305916c440d02f" alt="已添加到 n8n 画布中的 CometAPI 节点" width="1724" height="854" data-path="images/integrations/810968_360472.png" />
    </Frame>

    3. 添加一个 **Manual Trigger** 节点，并将其连接到 CometAPI 节点。
    4. 在 CometAPI 节点中，于 **Credential to connect with** 下选择 **Create new**。将你的 CometAPI API key 粘贴到 **CometAPI Key** 中，然后点击 **Save**。Base URL 默认为 `https://api.cometapi.com`，通常无需修改。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360474.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=deee1c999cbfb2c432daaa53904d6b38" alt="已输入 API key 的 CometAPI 凭证对话框" width="1906" height="608" data-path="images/integrations/810968_360474.png" />
    </Frame>

    5. 配置该节点：

    * **Model**：输入你想使用的当前 model ID
    * **Messages**：将 Role 设为 `user`，Content 设为你的测试 Prompt（例如 `Hello`）
    * 可选：添加 `system` 消息，设置 **Max Tokens**、**Temperature** 等

    6. 点击 **Execute step** 运行该节点。**Output** 面板会显示 JSON 响应。

    <Frame>
      <img src="https://mintcdn.com/cometapi/SZhlxZhCnMLn__BW/images/integrations/810968_360471.png?fit=max&auto=format&n=SZhlxZhCnMLn__BW&q=85&s=6953b97533f02e4f50cb1f0490ff057d" alt="显示 CometAPI 成功 JSON 响应的 n8n 输出面板" width="2092" height="1762" data-path="images/integrations/810968_360471.png" />
    </Frame>
  </Step>
</Steps>

<AccordionGroup>
  <Accordion title="故障排查">
    * **`node-gyp` 或原生构建错误** — 安装构建工具：`sudo apt install build-essential python3`（Debian/Ubuntu）或 Xcode Command Line Tools（macOS）。
    * **npm 权限错误（EACCES）** — 使用 nvm 进行用户级 Node.js 安装；无需 `sudo`。
    * **端口冲突（`localhost:5678` 不可用）** — 在运行 `n8n start` 前设置 `N8N_PORT=5679`（或其他空闲端口）。
    * **缺少 Community Nodes 部分** — 以 **Owner** 账户登录，并检查 **Settings → Security**。
    * **公司网络环境下 npm install 失败** — 配置代理：`npm config set proxy http://user:pass@host:port`
    * **CometAPI 节点返回 401/403** — 验证你的 API key，并确认你的 CometAPI 套餐可访问该模型。
    * **响应为空或 Token 限制错误** — 增加 **Max Tokens**；根据需要调整 **Temperature** 和 **Top P**。
    * **关闭终端后 n8n 停止运行** — 使用 pm2：`pm2 start "n8n" --name n8n && pm2 save`。
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#howto",
        "name": "使用 CometAPI 在本地运行 n8n",
        "description": "使用本指南，通过配置本地部署设置、凭证和模型访问，在本地运行集成了 CometAPI 的 n8n。",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-1",
            "position": 1,
            "name": "获取你的 CometAPI API key",
            "text": "创建或打开你的 CometAPI 账户，然后从仪表盘复制一个有效的 API key。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-2",
            "position": 2,
            "name": "通过 nvm 安装 Node.js",
            "text": "完成“使用 CometAPI 在本地运行 n8n”指南中的“通过 nvm 安装 Node.js”步骤。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-3",
            "position": 3,
            "name": "安装并启动 n8n",
            "text": "完成“使用 CometAPI 在本地运行 n8n”指南中的“安装并启动 n8n”步骤。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-4",
            "position": 4,
            "name": "创建你的 owner 账户",
            "text": "完成“使用 CometAPI 在本地运行 n8n”指南中的“创建你的 owner 账户”步骤。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-5",
            "position": 5,
            "name": "安装 CometAPI 社区节点",
            "text": "完成“使用 CometAPI 在本地运行 n8n”指南中的“安装 CometAPI 社区节点”步骤。"
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-6",
            "position": 6,
            "name": "创建工作流并配置凭证",
            "text": "完成“使用 CometAPI 在本地运行 n8n”指南中的“创建工作流并配置凭证”步骤。"
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI 文档",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "集成",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "使用 CometAPI 在本地运行 n8n",
            "item": "https://apidoc.cometapi.com/integrations/n8n-local-deployment"
          }
        ]
      }
    ]
    }
    `}
</script>
