> ## 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.

# Chạy n8n cục bộ với CometAPI

> Sử dụng hướng dẫn này để chạy n8n cục bộ với CometAPI bằng cách cấu hình thiết lập triển khai cục bộ, thông tin xác thực và quyền truy cập model.

Triển khai n8n trên chính máy của bạn và kết nối nó với CometAPI thông qua community node để chạy các quy trình AI tự động hóa cục bộ.

## Điều kiện tiên quyết

* Linux (Ubuntu/Debian/CentOS, v.v.) hoặc macOS
* RAM 2 GB+, dung lượng đĩa trống 10 GB+
* Quyền truy cập shell có thể kết nối tới npm registry công khai
* Node.js 18.x hoặc 20.x LTS (xem Bước 1)
* Tài khoản CometAPI với API key đang hoạt động — [lấy tại đây](https://www.cometapi.com/console/token)

<Steps>
  <Step title="Lấy CometAPI API key của bạn">
    Đăng nhập vào [bảng điều khiển CometAPI](https://www.cometapi.com/console/token). Nhấp vào **Add API Key** và sao chép CometAPI API key của bạn.

    <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="Bảng điều khiển CometAPI hiển thị nút Add API Key" 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="Chi tiết CometAPI API key kèm base URL" width="2434" height="1232" data-path="images/overview/810968_364193.png" />
    </Frame>
  </Step>

  <Step title="Cài đặt Node.js qua nvm">
    n8n 1.x yêu cầu Node.js 18.x hoặc 20.x. Cách tiếp cận được khuyến nghị là [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>
      Nếu sau này bạn thấy `n8n: command not found`, hãy khởi động lại terminal hoặc đảm bảo thư mục npm global bin do nvm quản lý nằm trong `PATH` của bạn.
    </Note>
  </Step>

  <Step title="Cài đặt và khởi động n8n">
    ```bash theme={null}
    npm install -g n8n
    n8n -v       # verify the installed version
    n8n start    # runs on http://localhost:5678/
    ```

    Nếu cổng 5678 đã được sử dụng:

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

    Để giữ cho n8n tiếp tục chạy sau khi đóng terminal:

    ```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="Terminal hiển thị n8n khởi động thành công" 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="Log khởi động n8n trong terminal" width="759" height="460" data-path="images/integrations/810968_360464.png" />
    </Frame>
  </Step>

  <Step title="Tạo tài khoản Owner của bạn">
    Mở [http://localhost:5678/](http://localhost:5678/) trên trình duyệt. Trong lần chạy đầu tiên, trình hướng dẫn thiết lập sẽ yêu cầu bạn tạo tài khoản **Owner** (email + mật khẩu). Hoàn tất bước này và đăng nhập.

    <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="Trình hướng dẫn thiết lập lần đầu của n8n yêu cầu thông tin tài khoản Owner" width="1249" height="970" data-path="images/integrations/810968_360465.png" />
    </Frame>
  </Step>

  <Step title="Cài đặt node cộng đồng CometAPI">
    1. Vào **Settings** (góc dưới bên trái) → **Community nodes**
    2. Nhấp **Install a community node**
    3. Nhập tên package: `@cometapi-dev/n8n-nodes-cometapi`
    4. Chọn ô xác nhận rủi ro và nhấp **Install**

    Sau khi cài đặt, bạn có thể tìm kiếm **CometAPI** trong bảng node.

    <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="Bảng Settings của n8n hiển thị phần Community nodes" 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="Hộp thoại cài đặt với tên package CometAPI đã được nhập" width="1261" height="965" data-path="images/integrations/810968_360468.png" />
    </Frame>

    <Note>
      Nếu phần Community Nodes không xuất hiện: hãy đảm bảo bạn đã đăng nhập bằng tài khoản **Owner**, và kiểm tra **Settings → Security** để xác nhận rằng việc cài đặt community node đã được bật.
    </Note>
  </Step>

  <Step title="Tạo workflow và cấu hình credentials">
    1. Nhấp **+ New** ở phía trên để tạo một workflow.
    2. Nhấp **+** trên canvas và tìm kiếm **CometAPI** để thêm node.

    <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="Canvas workflow của n8n với ô tìm kiếm node CometAPI đang mở" 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="Node CometAPI đã được thêm vào canvas n8n" width="1724" height="854" data-path="images/integrations/810968_360472.png" />
    </Frame>

    3. Thêm node **Manual Trigger** và kết nối nó với node CometAPI.
    4. Trong node CometAPI, ở mục **Credential to connect with**, chọn **Create new**. Dán CometAPI API key của bạn vào **CometAPI Key** và nhấp **Save**. Base URL mặc định là `https://api.cometapi.com` và thường không cần thay đổi.

    <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="Hộp thoại credential của CometAPI với API key đã được nhập" width="1906" height="608" data-path="images/integrations/810968_360474.png" />
    </Frame>

    5. Cấu hình node:

    * **Model**: nhập model ID hiện tại mà bạn muốn sử dụng
    * **Messages**: đặt Role là `user`, Content là prompt thử nghiệm của bạn (ví dụ: `Hello`)
    * Tùy chọn: thêm message `system`, đặt **Max Tokens**, **Temperature**, v.v.

    6. Nhấp **Execute step** để chạy node. Bảng **Output** sẽ hiển thị phản hồi 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="Bảng output của n8n hiển thị phản hồi JSON CometAPI thành công" width="2092" height="1762" data-path="images/integrations/810968_360471.png" />
    </Frame>
  </Step>
</Steps>

<AccordionGroup>
  <Accordion title="Khắc phục sự cố">
    * **Lỗi `node-gyp` hoặc lỗi build native** — cài đặt build tools: `sudo apt install build-essential python3` (Debian/Ubuntu) hoặc Xcode Command Line Tools (macOS).
    * **Lỗi quyền npm (EACCES)** — sử dụng nvm để cài đặt Node.js ở cấp người dùng; không cần `sudo`.
    * **Xung đột cổng (`localhost:5678` không khả dụng)** — đặt `N8N_PORT=5679` (hoặc cổng trống khác) trước khi chạy `n8n start`.
    * **Không có phần Community Nodes** — đăng nhập bằng tài khoản **Owner** và kiểm tra **Settings → Security**.
    * **npm install thất bại trên mạng doanh nghiệp** — cấu hình proxy: `npm config set proxy http://user:pass@host:port`
    * **Node CometAPI trả về 401/403** — xác minh API key của bạn và đảm bảo model có thể truy cập trong gói CometAPI của bạn.
    * **Phản hồi rỗng hoặc lỗi giới hạn token** — tăng **Max Tokens**; điều chỉnh **Temperature** và **Top P** nếu cần.
    * **n8n dừng khi đóng terminal** — dùng 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": "Chạy n8n cục bộ với CometAPI",
        "description": "Sử dụng hướng dẫn này để chạy n8n cục bộ với CometAPI bằng cách cấu hình cài đặt triển khai cục bộ, credentials và quyền truy cập model.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-1",
            "position": 1,
            "name": "Lấy CometAPI API key của bạn",
            "text": "Tạo hoặc mở tài khoản CometAPI của bạn, sau đó sao chép một API key đang hoạt động từ bảng điều khiển."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-2",
            "position": 2,
            "name": "Cài đặt Node.js qua nvm",
            "text": "Hoàn thành bước Cài đặt Node.js qua nvm trong hướng dẫn Chạy n8n cục bộ với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-3",
            "position": 3,
            "name": "Cài đặt và khởi động n8n",
            "text": "Hoàn thành bước Cài đặt và khởi động n8n trong hướng dẫn Chạy n8n cục bộ với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-4",
            "position": 4,
            "name": "Tạo tài khoản Owner của bạn",
            "text": "Hoàn thành bước Tạo tài khoản Owner của bạn trong hướng dẫn Chạy n8n cục bộ với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-5",
            "position": 5,
            "name": "Cài đặt node cộng đồng CometAPI",
            "text": "Hoàn thành bước Cài đặt node cộng đồng CometAPI trong hướng dẫn Chạy n8n cục bộ với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/n8n-local-deployment#step-6",
            "position": 6,
            "name": "Tạo workflow và cấu hình credentials",
            "text": "Hoàn thành bước Tạo workflow và cấu hình credentials trong hướng dẫn Chạy n8n cục bộ với CometAPI."
          }
        ]
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "Tài liệu CometAPI",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "Tích hợp",
            "item": "https://apidoc.cometapi.com/integrations"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "Chạy n8n cục bộ với CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/n8n-local-deployment"
          }
        ]
      }
    ]
    }
    `}
</script>
