---
title: "介紹 Admin APIs"
description: "Apps Management 和 Usage 現已正式推出（GA）。透過一個 endpoint 與一組 Access Key，即可建立 app、管理 allowlist，並取得 dashboard 使用量資料。"
---

# 介紹 Admin APIs

<ImageBlock
  src="https://media.alchemy.com/admin-apis.png"
  alt="介紹 Alchemy Admin APIs，用於應用程式管理與用量查詢"
  width={3840}
  height={2160}
  priority
/>

儀表板對於管理單一 app 來說已經很夠用。但對於大規模使用 Alchemy 的團隊,像是為每個客戶、每個合作夥伴、或每個環境都建立專屬 app 的情況,就會產生大量重複性工作。每次都要點同樣的建立流程、更新 allowlist、檢查用量。

因此,我們很高興開放兩個 [Admin APIs](https://www.alchemy.com/docs/reference/admin-api/overview),讓開發者的工作更簡單、更流暢:

- **[Apps Management API](https://www.alchemy.com/docs/admin-api/apps/list-apps):** 建立、設定、刪除 app,管理 allowlist。
- **[Usage API](https://www.alchemy.com/docs/admin-api/usage/get-usage-summary):** 取得與儀表板 Usage 頁籤相同的用量數據。

這兩個 API 都可透過同一個 endpoint、同一組 Access Key 存取。從儀表板的 Settings → Security 取得一組 Access Key,設定權限範圍為 App Management 或 Usage,指向 `https://admin-api.alchemy.com/v1` 即可。

## Apps Management API

Apps Management API 處理原本需要在儀表板手動操作的 CRUD:建立 app、設定其 network allowlist,並管理其 address、domain、IP allowlist。

<CodeSnippet
  language="bash"
  code={`curl -X POST 'https://admin-api.alchemy.com/v1/apps' \\
  --header 'Content-Type: application/json' \\
  --header 'Authorization: Bearer {your access key}' \\
  --data '{
    "name": "app-tenant-42",
    "networkAllowlist": ["ETH_MAINNET"],
    "products": ["node-api"]
  }'`}
/>

這取代了原本需要手動處理的情境:為每個客戶建立專屬 app 的平台、為每個合作夥伴或節點營運商建立獨立 app 以隔離用量的團隊,或是為每個環境都建立新 app 的 pipeline。Access Key 本身帶有各自的權限範圍、到期時間與輪換機制,因此 app 的建立流程可以整合進 CI/CD,而不必只能在儀表板上手動操作。

## Usage API

Usage API 是一個唯讀的 endpoint,提供原本需要從儀表板 Usage 頁籤取得的數據:總體及依 network 劃分的 [CUs](https://www.alchemy.com/docs/reference/compute-units),以及本月累計數據;付費方案還可取得依 app、method、network 劃分的細項,涵蓋 HTTP、WebSocket、webhook 流量、以美元計價的用量,以及請求數量。

<CodeSnippet
  language="bash"
  code={`curl 'https://admin-api.alchemy.com/v1/usage/summary' \\
  --header 'Authorization: Bearer {your access key}'`}
/>

歷史資料範圍與細節程度依方案而異:

<EmbeddedTable
  table={{
    columns: [
      { key: "plan", width: 180, title: "Plan", dataType: "object" },
      {
        key: "access",
        width: 420,
        title: "What's included",
        dataType: "object",
      },
    ],
    data: [
      {
        plan: { title: "Free", tooltip: "", icon: "" },
        access: {
          title: "High-level CU summary, 1 day of history",
          tooltip: "",
          icon: "",
        },
        id: 0,
      },
      {
        plan: { title: "PAYG", tooltip: "", icon: "" },
        access: {
          title: "Full breakdown, 7 days of history",
          tooltip: "",
          icon: "",
        },
        id: 1,
      },
      {
        plan: { title: "Enterprise", tooltip: "", icon: "" },
        access: {
          title: "Full breakdown, 30 days of history",
          tooltip: "",
          icon: "",
        },
        id: 2,
      },
    ],
  }}
/>

以下兩種憑證皆可作為 bearer token 進行驗證:設定為唯讀 Usage 權限的 Access Key,可取得整個團隊的數據;或者,如果只需要單一 app 的數據,也可使用既有的 app-scoped API key,傳遞方式相同。

## 開始使用

從 Security 頁籤建立一組 Access Key,設定所需的權限範圍,然後呼叫 `https://admin-api.alchemy.com/v1`。

深入閱讀[文件](https://www.alchemy.com/docs/reference/admin-api/overview),如有任何問題或想討論大規模使用的專屬解決方案,歡迎[聯絡我們的團隊](https://www.alchemy.com/contact-sales)。

## FAQ

### Apps Management 和 Usage 有什麼差別?

Apps Management 用於建立與設定 app:名稱、network allowlist,以及 address、domain、IP allowlist。Usage 則是唯讀的,回傳 compute unit 總量,付費方案還可取得依時間序列劃分的細項。請將 Access Key 的權限範圍限制在實際需要的權限即可。

### 如何驗證 Admin API?

在儀表板 Security 頁籤建立一組 Access Key,啟用 App Management 和/或 Usage,然後以 `Authorization: Bearer {your access key}` 的形式傳送給 `https://admin-api.alchemy.com/v1`。

### 可以取得多久的用量歷史資料?

時間序列範圍在 Free 方案為 1 天,PAYG 為 7 天,Enterprise 為 30 天。Free 只提供高層級的 CU 摘要;PAYG 和 Enterprise 則可取得完整細項。
