> For the complete documentation index, see [llms.txt](https://docs.avis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avis.net/vi/tich-hop/coding/copilot.md).

# Copilot CLI

## Hướng dẫn tích hợp GitHub Copilot CLI

Hướng dẫn này trình bày cách kết nối [GitHub Copilot CLI](https://github.com/github/copilot-cli) với AVIS bằng tính năng **BYOK (Bring Your Own Key – sử dụng key riêng)** dành cho các nhà cung cấp mô hình tùy chỉnh.

### GitHub Copilot CLI là gì

GitHub Copilot CLI là agent lập trình của GitHub, chạy trên terminal để đọc và sửa tệp cũng như thực thi lệnh trong vòng lặp agent. Theo mặc định, công cụ dùng các mô hình Copilot của GitHub. Tuy nhiên, công cụ cũng hỗ trợ kết nối qua biến môi trường đến mọi endpoint tương thích với OpenAI Chat Completions hoặc Anthropic, nên không bị giới hạn ở các mô hình trong gói thuê bao GitHub Copilot.

### 1) Cài đặt Copilot CLI

```bash
# npm
npm install -g @github/copilot

# Homebrew
brew install copilot-cli

# macOS / Linux (curl)
curl -fsSL https://gh.io/copilot-install | bash

# Windows Package Manager
winget install GitHub.Copilot
```

### 2) Lấy AVIS API key

Đăng nhập tại [avis.net](https://avis.net), mở **Settings → API Keys** và tạo key. Xem thêm phần Xác thực.

### 3) Cấu hình AVIS làm nhà cung cấp tùy chỉnh

Copilot CLI đọc cấu hình nhà cung cấp hoàn toàn từ biến môi trường — không có tệp cấu hình cho phần này.

| Biến                        | Bắt buộc                  | Giá trị                                                                                             |
| --------------------------- | ------------------------- | --------------------------------------------------------------------------------------------------- |
| `COPILOT_PROVIDER_BASE_URL` | Có                        | Base URL API của AVIS (xem các tùy chọn bên dưới)                                                   |
| `COPILOT_PROVIDER_TYPE`     | Không (mặc định `openai`) | `openai` cho giao diện tương thích OpenAI của AVIS, `anthropic` cho giao diện tương thích Anthropic |
| `COPILOT_PROVIDER_API_KEY`  | Có (với AVIS)             | AVIS API key của bạn                                                                                |
| `COPILOT_MODEL`             | Có                        | Model ID (xem §4)                                                                                   |

#### Cách A — Giao diện tương thích OpenAI (khuyến nghị, hỗ trợ mọi mô hình AVIS)

```bash
export COPILOT_PROVIDER_BASE_URL="https://api.avis.net/api/openai/v1"
export COPILOT_PROVIDER_API_KEY="<your-avis-api-key>"
export COPILOT_MODEL="claude-sonnet-5"
copilot
```

`COPILOT_PROVIDER_TYPE` mặc định là `openai`, vì vậy có thể bỏ qua ở đây.

#### Cách B — Giao diện tương thích Anthropic (chỉ các mô hình thương hiệu Anthropic)

```bash
export COPILOT_PROVIDER_TYPE=anthropic
export COPILOT_PROVIDER_BASE_URL="https://api.avis.net/api/anthropic"
export COPILOT_PROVIDER_API_KEY="<your-avis-api-key>"
export COPILOT_MODEL="claude-sonnet-5"
copilot
```

### 4) Chọn mô hình

* Với **Cách A** (tương thích OpenAI), `COPILOT_MODEL` phải là id chuẩn dạng phẳng của AVIS (không có tiền tố `anthropic/`/`openai/`) — truy vấn danh mục trực tiếp:

  ```bash
  curl https://api.avis.net/api/openai/v1/models \
    -H "x-api-key: $COPILOT_PROVIDER_API_KEY" | jq '.data[].id'
  ```
* Với **Cách B** (tương thích Anthropic), `COPILOT_MODEL` là tên mô hình gốc của Anthropic không có tiền tố (ví dụ `claude-opus-5`), khớp với những gì Claude Code và Claude Desktop gửi — xem §4 trong hướng dẫn tích hợp Claude Code để hiểu thêm về cách giao diện này xử lý model id.

Copilot CLI yêu cầu mô hình hỗ trợ tool/function calling và streaming, với context window tối thiểu được khuyến nghị là 128k token — hãy chọn mô hình phù hợp từ danh mục của AVIS.

### 5) Chạy Copilot CLI

```bash
cd your-project
copilot
```

Liệt kê các ví dụ thiết lập nhà cung cấp (có sẵn trong CLI):

```bash
copilot help providers
```

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

* `401 Unauthorized`
  * `COPILOT_PROVIDER_API_KEY` chưa được export trong shell mà Copilot CLI được khởi chạy.
  * AVIS key không hợp lệ hoặc đã bị thu hồi — kiểm tra trực tiếp: `curl -H "x-api-key: $COPILOT_PROVIDER_API_KEY" https://api.avis.net/api/openai/v1/models`.
* `404` / không tìm thấy mô hình
  * `COPILOT_MODEL` không khớp với danh mục của AVIS cho giao diện bạn đã chọn — id phẳng với loại `openai`, id gốc Anthropic không tiền tố với loại `anthropic` (§4).
* `403` với key hợp lệ
  * Số dư tài khoản đã hết — xem phần Lỗi.
* Mô hình hoạt động kém / tool call thất bại
  * Xác nhận mô hình được chọn thực sự hỗ trợ tool calling và streaming, và có context window ít nhất 128k — đây là yêu cầu do chính Copilot CLI đưa ra, không riêng của AVIS.
* Copilot vẫn gọi các mô hình của GitHub thay vì AVIS
  * Một trong các biến môi trường bắt buộc (`COPILOT_PROVIDER_BASE_URL`, `COPILOT_PROVIDER_API_KEY`, `COPILOT_MODEL`) chưa được đặt trong shell mà `copilot` được khởi chạy — BYOK chỉ được kích hoạt khi có đủ mọi biến bắt buộc cho `COPILOT_PROVIDER_TYPE` đã chọn.

### 7) Danh sách kiểm tra tối thiểu từ đầu đến cuối

1. Đã tạo AVIS API key (§2).
2. Đã export `COPILOT_PROVIDER_BASE_URL`, `COPILOT_PROVIDER_API_KEY`, `COPILOT_MODEL` (và `COPILOT_PROVIDER_TYPE` nếu dùng Cách B) (§3).
3. Đã xác nhận model ID với đúng danh mục AVIS cho giao diện đã chọn (§4).
4. `copilot` khởi động và một tin nhắn trả về kết quả từ mô hình chạy qua AVIS.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avis.net/vi/tich-hop/coding/copilot.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
