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

# 身分驗證

> API 金鑰：建立、格式、用法、限制與安全最佳實務

## API 金鑰

所有 v1 端點都需要在 `x-api-key` 標頭中附上 API 金鑰。

### 建立 API 金鑰

1. 登入 [AFKCrypto 控制台](https://app.afkcrypto.com)
2. 前往 [API Keys](https://app.afkcrypto.com/api-keys) 區段
3. 按下「Generate API Key」
4. 為金鑰設定清楚的名稱
5. 選用：設定到期時間（7 天、30 天、90 天、180 天或 1 年）
6. 立即複製金鑰——之後不會再次顯示

### 金鑰格式

```text theme={null}
afk_<prefix>_<random>

範例：afk_xY3z_Ab12cD34Ef56Gh78Ij90Kl12Mn34Op56
```

* **Prefix**：4 個字元的快速識別代碼
* **Random**：32 個字元、密碼學安全的隨機字串

### 使用 API 金鑰

在每個請求的 `x-api-key` 標頭中附上金鑰：

```bash theme={null}
curl -X GET https://api.afkcrypto.com/api/v1/wallets \
  -H "x-api-key: afk_xY3z_Ab12cD34Ef56Gh78Ij90Kl12Mn34Op56"
```

### 安全最佳實務

* **切勿將金鑰提交到版本控制**：使用環境變數
* **定期輪替金鑰**：為臨時存取設定到期
* **依環境分離金鑰**：開發、預備、正式
* **立即撤銷未使用的金鑰**：降低攻擊面
* **安全儲存**：使用機密管理工具（如 AWS Secrets Manager、HashiCorp Vault）

### 金鑰到期

API 金鑰可於指定期間後到期：

* **永不過期**（預設）：直到被撤銷
* **7 天**：短期測試/展示
* **30 天**：外包或試用
* **90 天**：建議季度輪替
* **180 天**：半年輪替
* **1 年**：年度輪替，適用穩定整合

到期時會發生什麼？

* 使用該金鑰的請求將回傳 HTTP 401 `UNAUTHORIZED`
* 控制台仍保留該金鑰供稽核
* 建立新金鑰加以替換

到期監控

* 控制台標示「Expired」或「Expiring soon」（≤ 7 天）
* 設定提醒以避免服務中斷

### 金鑰限制

* **啟用中的金鑰上限**：每位使用者 10 個
* **適用速率限制**：參見 [Rate limiting](/api-reference/introduction/#rate-limiting)
* 撤銷未使用的金鑰以維持在上限內

### 撤銷 API 金鑰

可於控制台立即撤銷：

1. 開啟 [API Keys](https://app.afkcrypto.com/api-keys)
2. 找到要撤銷的金鑰
3. 按下「Revoke Key」
4. 確認操作

注意：撤銷為永久動作並立即生效。

## 相關

<CardGroup cols={2}>
  <Card title="API 參考" icon="terminal" href="/api-reference/introduction/" />

  <Card title="政策與安全" icon="shield" href="/api-reference/policies-security/" />

  <Card title="支援的網路" icon="link-simple" href="/api-reference/supported-chains/" />
</CardGroup>
