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

# Sử dụng Claude Code với CometAPI

> Sử dụng hướng dẫn này để cấu hình Claude Code với CometAPI thông qua thông tin xác thực tương thích Anthropic, cài đặt base URL và Claude model IDs.

Sử dụng hướng dẫn này để kết nối [Claude Code](https://code.claude.com/docs/en/overview) với CometAPI.

Tài liệu tham khảo chính thức:

* [Claude Code Overview](https://code.claude.com/docs/en/overview)
* [Claude Code Getting Started](https://code.claude.com/docs/en/getting-started)

<Note>
  Tính khả dụng của model thay đổi theo thời gian. Để biết Claude model IDs hiện tại, hãy kiểm tra
  [trang Models của CometAPI](/vi/overview/models).
</Note>

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

* Một CometAPI key từ [dashboard](https://www.cometapi.com) của bạn (bắt đầu bằng `sk-`)
* Đã cài đặt Git
* Hệ điều hành được hỗ trợ: macOS, Linux hoặc Windows

## Cài đặt Claude Code

<Steps>
  <Step title="Chạy trình cài đặt chính thức">
    <Tabs>
      <Tab title="macOS / Linux">
        ```bash theme={null}
        curl -fsSL https://claude.ai/install.sh | bash
        ```
      </Tab>

      <Tab title="Homebrew">
        ```bash theme={null}
        brew install --cask claude-code
        ```
      </Tab>

      <Tab title="Windows">
        PowerShell:

        ```powershell theme={null}
        irm https://claude.ai/install.ps1 | iex
        ```

        CMD:

        ```batch theme={null}
        curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
        ```

        <Info>Windows yêu cầu cài đặt [Git for Windows](https://git-scm.com/downloads/win) trước.</Info>
      </Tab>
    </Tabs>
  </Step>

  <Step title="Xác minh cài đặt">
    ```bash theme={null}
    claude --version
    ```
  </Step>
</Steps>

## Cấu hình endpoint CometAPI

Tạo hoặc chỉnh sửa tệp cài đặt:

* macOS / Linux: `~/.claude/settings.json`
* Windows: `%USERPROFILE%\.claude\settings.json`

```json theme={null}
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "sk-your-cometapi-key",
    "ANTHROPIC_BASE_URL": "https://api.cometapi.com"
  }
}
```

Thay `sk-your-cometapi-key` bằng CometAPI key thực tế của bạn, sau đó khởi động Claude Code:

```bash theme={null}
cd your-project
claude
```

## Khắc phục sự cố

<AccordionGroup>
  <Accordion title="settings.json không có hiệu lực">
    1. Khởi động lại hoàn toàn terminal của bạn bằng cách đóng tất cả cửa sổ và mở lại.
    2. Nếu vẫn không hoạt động, hãy tạo `~/.claude.json` và thêm:

    ```json theme={null}
    {
      "hasCompletedOnboarding": true
    }
    ```

    3. Để dự phòng, hãy export trực tiếp các biến môi trường:

    ```bash theme={null}
    # Add to ~/.zshrc (macOS) or ~/.bashrc (Linux)
    export ANTHROPIC_AUTH_TOKEN="sk-your-cometapi-key"
    export ANTHROPIC_BASE_URL="https://api.cometapi.com"
    ```
  </Accordion>

  <Accordion title="API Key không hợp lệ hoặc Please run /login">
    Kiểm tra rằng `~/.claude/settings.json` tồn tại và định dạng JSON hợp lệ, không có dấu phẩy thừa ở cuối và dùng dấu ngoặc kép đúng. Xác thực tại [jsonlint.com](https://jsonlint.com).
  </Accordion>

  <Accordion title="Đang sử dụng thông tin xác thực chính thức đã được lưu cache">
    Claude Code ưu tiên thông tin xác thực chính thức đã được lưu cache. Chạy `/logout` bên trong Claude Code, đóng ứng dụng, rồi khởi động lại.

    Nếu vẫn lỗi, hãy xóa file auth đã được cache:

    ```bash theme={null}
    rm -rf ~/.config/claude-code/auth.json
    ```
  </Accordion>

  <Accordion title="Trạng thái hiển thị offline">
    Claude Code kiểm tra kết nối thông qua Google. `offline` nghĩa là không thể truy cập Google. Điều này không ảnh hưởng đến việc sử dụng CometAPI.
  </Accordion>

  <Accordion title="Fetch hoặc duyệt web thất bại">
    Tính năng Fetch của Claude Code trước tiên gọi dịch vụ gốc của Anthropic, dịch vụ này yêu cầu truy cập internet trực tiếp. Có thể cần proxy trên toàn hệ thống.
  </Accordion>
</AccordionGroup>

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "HowTo",
        "@id": "https://apidoc.cometapi.com/integrations/claude-code#howto",
        "name": "Sử dụng Claude Code với CometAPI",
        "description": "Sử dụng hướng dẫn này để cấu hình Claude Code với CometAPI thông qua thông tin xác thực tương thích Anthropic, cài đặt base URL và các model ID của Claude.",
        "step": [
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/claude-code#step-1",
            "position": 1,
            "name": "Xem lại các điều kiện tiên quyết",
            "text": "Hoàn thành bước Xem lại các điều kiện tiên quyết trong hướng dẫn Sử dụng Claude Code với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/claude-code#step-2",
            "position": 2,
            "name": "Cài đặt Claude Code",
            "text": "Hoàn thành bước Cài đặt Claude Code trong hướng dẫn Sử dụng Claude Code với CometAPI."
          },
          {
            "@type": "HowToStep",
            "@id": "https://apidoc.cometapi.com/integrations/claude-code#step-3",
            "position": 3,
            "name": "Cấu hình endpoint CometAPI",
            "text": "Hoàn thành bước Cấu hình endpoint CometAPI trong hướng dẫn Sử dụng Claude Code 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": "Sử dụng Claude Code với CometAPI",
            "item": "https://apidoc.cometapi.com/integrations/claude-code"
          }
        ]
      }
    ]
    }
    `}
</script>
