> 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/tai-lieu-api/introduction/authentication.md).

# Xác thực

Mọi request đến một trong ba giao diện API đều cần xác thực, ngoại trừ các request kiểm tra kết nối `HEAD` (`HEAD /api/openai`, `HEAD /api/anthropic`, `HEAD /api/gemini`).

Các cách xác thực được chấp nhận trên route được bảo vệ:

* `x-api-key: <api-key>`
* `Authorization: Bearer <api-key>`

### Tạo API key

1. Đăng nhập tại [avis.net](https://avis.net).
2. Vào **Settings → API Keys**.
3. Nhấn **Create key**, đặt tên cho key và lưu ở nơi an toàn. Key gốc chỉ hiển thị một lần khi tạo; sau đó bạn có thể xem lại key trên cùng trang này.

Mỗi tài khoản có thể bị giới hạn số lượng API key. Tạo vượt quá giới hạn sẽ trả về `403 Forbidden`.

### Định dạng header

Gửi key trong mỗi request qua header `x-api-key`. Header này dùng chung cho cả ba giao diện:

```
x-api-key: <your-api-key>
```

Bạn cũng có thể dùng `Authorization: Bearer <your-api-key>` trên cả ba giao diện. Cách này hữu ích với các công cụ chỉ cho phép cấu hình bearer token, chẳng hạn Codex CLI. Không gửi cả hai header với giá trị khác nhau; nếu có cả hai, `x-api-key` sẽ được ưu tiên.

```
Authorization: Bearer <your-api-key>
```

**Chỉ dành cho giao diện Anthropic** — các header bổ sung (không dùng để xác thực) sau đây sẽ được chuyển tiếp tới nhà cung cấp upstream nếu có:

| Header              | Mục đích                          |
| ------------------- | --------------------------------- |
| `anthropic-version` | Phiên bản API, ví dụ `2023-06-01` |
| `anthropic-beta`    | Cờ bật tính năng beta             |

### Khi nào request nhận lỗi 401?

| Tình huống                                           | Phản hồi                                     |
| ---------------------------------------------------- | -------------------------------------------- |
| Không cung cấp thông tin xác thực hợp lệ             | `401`                                        |
| Key không tồn tại, đã bị thu hồi hoặc bị vô hiệu hóa | `401` (lỗi xác thực API key)                 |
| Key hợp lệ nhưng số dư tài khoản đã hết              | Đây **không phải** lỗi 401 — xem Lỗi (`403`) |


---

# 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/tai-lieu-api/introduction/authentication.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.
