---
title: 身份驗證 | RunAPI
description: 建立 API 金鑰並驗證對 RunAPI 的請求。
url: https://runapi.ai/zh-HK/docs/guides/authentication.md
canonical: https://runapi.ai/zh-HK/docs/guides/authentication
locale: zh-HK
---

> HTML 版本: https://runapi.ai/zh-HK/docs/guides/authentication
> 智能代理網站索引: https://runapi.ai/llms.txt

# 身份驗證

RunAPI 使用 API 金鑰驗證 API 請求。每次存取帳戶或建立工作的請求均需附帶金鑰。

## 選擇正確的金鑰

* 標準 API 金鑰可呼叫 Task API、LLM API 及帳戶端點。[登入](https://runapi.ai/zh-HK/login)後，開啟「API 金鑰」頁面即可建立。
* 管理金鑰可建立及管理標準 API 金鑰與防護欄。[登入](https://runapi.ai/zh-HK/login)後，開啟「管理金鑰」頁面即可建立，並僅限與平台管理端點搭配使用。

## 建立 API 金鑰

為每個應用程式設定獨立的金鑰，以便在不影響其他整合的情況下輪換或撤銷存取權限。金鑰與一個帳戶綁定，請求只能存取該帳戶可見的資源。

付費 API 呼叫每個帳戶每分鐘限制 300 個請求。
`429 Too Many Requests` 回應包含 `Retry-After`、
`X-RateLimit-Limit-RPM`、`X-RateLimit-Remaining-RPM` 和
`X-RateLimit-Reset` 標頭。

## 驗證請求

在 `Authorization` 標頭中以持有者令牌形式傳送 API 金鑰：

```http
Authorization: Bearer YOUR_API_TOKEN
```

例如，使用 cURL 查詢您的當前餘額：

```shell
curl "https://runapi.ai/api/v1/me/balance" \
  -H "Authorization: Bearer YOUR_API_TOKEN"
```

## 託管 MCP OAuth

遠端 MCP 客戶端連接至 `https://mcp.runapi.ai/mcp`，並使用標準 OAuth 資源 `https://mcp.runapi.ai` 自動探索 RunAPI 授權流程。登入或建立 RunAPI 帳號，選擇一個帳號並批准存取，無需建立或共享 API 金鑰。

RunAPI 支援動態客戶端註冊、帶有 S256 PKCE 的授權碼，以及用於 Hosted MCP 存取的輪換重新整理令牌。

OAuth 探索端點：

* 受保護資源元數據：
  `https://runapi.ai/.well-known/oauth-protected-resource`
* 授權伺服器元數據：
  `https://runapi.ai/.well-known/oauth-authorization-server`

[登入](https://runapi.ai/zh-HK/login)，然後在 `/settings#oauth-connections` 開啟「已授權的應用程式」
以審查或撤銷用戶端存取權限。

## 保持金鑰安全

* 將 API 金鑰儲存於密鑰管理器或加密憑證中。
* 切勿將金鑰提交至原始碼管理或在瀏覽器代碼中暴露。
* 若金鑰可能已洩露，請立即輪換。
* 開發與生產環境應使用不同的金鑰。

## 身份驗證疑難排解

* `401 Unauthorized` 回應表示金鑰遺失、格式錯誤、已撤銷或無效。
* `403 Forbidden` 回應表示金鑰有效，但其憑證類別或帳戶角色無法執行該操作。
* 確認標頭以 `Bearer` 開頭，後跟一個空格及完整金鑰。
* 確認金鑰屬於您正在請求資源的帳戶。

---

## RunAPI 的更多內容

- [首頁](https://runapi.ai/zh-HK/.md)
- [模型目錄](https://runapi.ai/zh-HK/models.md)
- [收費](https://runapi.ai/zh-HK/pricing.md)
- [服務商](https://runapi.ai/zh-HK/models)
- [文件](https://runapi.ai/zh-HK/docs/guides)
- [SDK](https://runapi.ai/zh-HK/sdk.md)
- [CLI](https://runapi.ai/zh-HK/cli.md)
- [MCP Server](https://runapi.ai/zh-HK/mcp.md)
- [Claude Code 與 Cursor](https://runapi.ai/zh-HK/claude-code-vs-cursor.md)
- [Cursor API 設定](https://runapi.ai/zh-HK/cursor-api-setup.md)
- [RunAPI 與 OpenRouter](https://runapi.ai/zh-HK/openrouter-alternative.md)
- [企業版](https://runapi.ai/zh-HK/contact.md)
- [聯絡](https://runapi.ai/zh-HK/contact.md)
- [條款](https://runapi.ai/zh-HK/terms.md)
- [私隱](https://runapi.ai/zh-HK/privacy.md)
- [智能代理網站索引](https://runapi.ai/llms.txt)

聯絡我們: contact@runapi.ai

## 結構化資料

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-HK",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-HK",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/zh-HK/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-HK",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-HK",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/zh-HKicon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-HK",
    "@type": "TechArticle",
    "headline": "身份驗證",
    "description": "建立 API 金鑰並驗證對 RunAPI 的請求。",
    "url": "https://runapi.ai/zh-HK/docs/guides/authentication",
    "mainEntityOfPage": "https://runapi.ai/zh-HK/docs/guides/authentication"
  }
]
```
