Claude Platform Docs
管理組織

Admin API

使用 Admin API 金鑰、org:admin OAuth 權杖,或個人金鑰或服務帳戶金鑰,透過 Admin API 以程式化方式管理組織成員、工作區、邀請和 API 金鑰。

Admin API 讓您能以程式化方式管理組織的成員、工作區、邀請和 API 金鑰,而不必在 Claude Console 中手動操作。

可用性

Admin API 適用於 Claude Console 和 Claude Enterprise 組織。

如果您的公司有 Claude Console 組織,您可以透過該組織使用 Admin API;請參閱 Admin API 金鑰與權杖頁面。個人 Console 帳戶必須先在 Claude Console 中的組織設定頁面(platform.claude.com/settings/organization)設定組織。

Claude Enterprise(claude.ai)組織使用在 claude.ai 中建立的 Enterprise Admin API 金鑰呼叫 Admin API。在本頁中,只有成員、邀請和組織資訊端點適用於這些組織。在本頁之外,它們也可以呼叫下列 API 和端點:

如需成員、邀請、群組和自訂角色的相關資訊,請參閱使用者管理。

雲端平台列出您可在 Claude Models on Google Cloud (Anthropic managed) 和 Claude Platform on AWS 上呼叫的端點。

驗證

Admin API 接受以下三種憑證中的任何一種:

  • 在 x-api-key 標頭或 authorization: Bearer 標頭中傳送的 Console Admin API 金鑰(以 sk-ant-admin... 開頭)。只有具備 admin 角色的組織成員才能佈建此金鑰。請參閱 Admin API 金鑰與權杖。
  • 在 authorization: Bearer 標頭中傳送、具有 org:admin 範圍的 OAuth bearer 權杖。使用者需要具備 admin 角色才能取得此權杖。請參閱 OAuth bearer 權杖。如需服務帳戶所需的角色,請參閱「Workload Identity Federation」(工作負載身分聯合,即 WIF)參考頁面上的權限邊界。
  • 在 x-api-key 標頭或 authorization: Bearer 標頭中傳送、範圍限定於組織的個人金鑰或服務帳戶金鑰。該金鑰擁有其所連結帳戶的權限。請參閱開發者 API 金鑰頁面上的金鑰類型。

Admin API 金鑰涵蓋大多數端點,但服務帳戶、聯合發行者和聯合規則端點僅接受 org:admin OAuth 權杖。以下範例分別使用 OAuth 權杖和 Admin API 金鑰呼叫組織資訊端點。

SDK 將本頁的端點公開於 client.organization 之下,而 ant CLI 則公開於 ant organization 之下。本頁範例使用預設用戶端,它會從 ANTHROPIC_API_KEY 讀取 Admin API 金鑰,或從 ANTHROPIC_AUTH_TOKEN 讀取 OAuth bearer 權杖。每個列表範例中的註解會說明該範例是擷取更多頁面,還是只讀取第一頁。如需各端點的參數和回應,請參閱 Admin API 參考。

OAuth bearer 權杖

您需要最新版本的 ant CLI。若要安裝,請參閱 CLI 快速入門中的安裝。

與一般僅在單一工作區內運作的登入不同,管理員登入可以在您的整個組織中進行變更。

以下指令會變更環境變數,因此請在您保留用於管理的 shell 中執行。這些指令會列出您的設定檔、取消設定 ANTHROPIC_API_KEY、以具有 org:admin 範圍的獨立設定檔登入,並匯出權杖。ant auth login 指令中的 --admin 旗標會將 org:admin 範圍加入登入原本就會請求的範圍中。

此登入也會將 admin 設定檔設為 CLI 的作用中設定檔。您的其他 shell 也會使用它。在您切換回來之前,這些 shell 中使用作用中設定檔的用戶端(例如 ant CLI)都能以管理員身分執行。

CLI
# 列出您的設定檔。星號標示目前作用中的設定檔。
# 請記下它,以便您稍後可以切換回來:
ant profile list

# 取消設定 API 金鑰變數。
# 在該變數已設定期間,SDK 與 CLI 會使用該金鑰而非權杖:
unset ANTHROPIC_API_KEY

ant auth login --profile admin --admin
export ANTHROPIC_AUTH_TOKEN=$(ant auth print-credentials \
  --profile admin --access-token)

在此 shell 中,無論哪個設定檔處於作用中狀態,SDK 和 ant CLI 都會在每次呼叫時傳送匯出的權杖。

若要使用組織 webhook,請改用其他方式登入,如為組織 webhook 登入一節所述。

使用匯出的權杖呼叫 Admin API:

client = anthropic.Anthropic()

organization = client.organization.retrieve()

print(f"id: {organization.id}")
print(f"name: {organization.name}")

ANTHROPIC_AUTH_TOKEN 中的權杖效期很短,且該處不會自動更新它。當請求開始傳回 401 時,請依照下列步驟操作:

  1. 重新執行 export 命令,如果舊權杖已過期,該命令會取得新的權杖。
  2. 如果請求仍然傳回 401,請使用您先前使用的相同 ant auth login 命令重新登入,然後重新執行 export 命令。

完成管理工作後,請復原登入命令所做的變更。針對作用中的設定檔(profile)該執行什麼,取決於除了您登入時所用的設定檔之外,您是否還有其他設定檔:

  • 您有其他設定檔: 切換回您登入前作用中的設定檔。如果該設定檔是 default,請執行 ant profile activate default。
  • 您沒有其他設定檔: ant auth logout --all 會在伺服器上撤銷權杖,並移除所有設定檔和憑證。請執行此命令,以免您登入時所用的設定檔持續作為作用中的設定檔。

如果您已切換回原本的設定檔,您登入時所用的設定檔仍會在磁碟上保留其憑證。如果您下一次的管理工作階段不需要該憑證,請執行 ant auth logout --profile 並加上該設定檔的名稱,例如 admin。這會在伺服器上撤銷其權杖並刪除該憑證。

unset 和 export 命令只會變更您執行它們的那個 shell 中的環境變數。若要復原這些變更,請執行下列其中一項:

  • 關閉該 shell。
  • 若要繼續使用該 shell,請取消設定 ANTHROPIC_AUTH_TOKEN,並在您有使用 ANTHROPIC_API_KEY 的情況下重新設定它。

對於 CI 和其他非互動式工作負載,請使用工作負載身分聯合鑄造權杖,而非以互動方式登入。請參閱使用 Admin API 管理 WIF。

Admin API 金鑰

若要為您的組織類型建立 Admin API 金鑰,請參閱 Admin API 金鑰與權杖。

client = anthropic.Anthropic()

organization = client.organization.retrieve()

print(f"id: {organization.id}")
print(f"name: {organization.name}")

Admin API 的運作方式

使用驗證中的任一憑證進行驗證,然後管理以下資源:

  • 組織成員及其角色
  • 組織邀請
  • 工作區及其成員
  • API 金鑰
  • 服務帳戶、聯合發行者和聯合規則(僅限 org:admin OAuth 權杖)

常見用途包括自動化入職與離職流程、管理工作區存取權限,以及稽核 API 金鑰。

組織角色與權限

Claude Console 組織有五種組織層級角色。如需詳細資訊,請參閱 API Console 角色與權限。

角色權限
user可使用 playground
claude_code_user可使用 playground 和 Claude Code
developer可使用 playground 並管理 API 金鑰
billing可使用 playground 並管理帳單詳細資料
admin可執行上述所有操作,並可管理使用者

Claude Enterprise 組織有一組不同的角色,包括擁有者和主要擁有者。請參閱組織角色。

關鍵概念

組織成員

列出組織成員可檢視預覽,內含 API 參考文件連結——按 Tab 鍵直到焦點進入卡片,按 Escape 鍵返回。、更新其角色,以及移除成員。

列出您組織的成員:

client = anthropic.Anthropic()

users = client.organization.users.list(limit=10)

# 視需要自動擷取更多頁面,因此 `limit` 設定的是每頁大小,而非總數。
for user in users:
    print(f"{user.id}: {user.email} ({user.role})")

更新成員的角色:

client = anthropic.Anthropic()

user = client.organization.users.update(
    "user_01WxYzAbCdEfGhJkMnPqRsTu", role="developer"
)

print(f"id: {user.id}")
print(f"role: {user.role}")

從組織中移除成員:

client = anthropic.Anthropic()

removed_user = client.organization.users.remove("user_01WxYzAbCdEfGhJkMnPqRsTu")

print(f"id: {removed_user.id}")

組織邀請

邀請使用者加入您的組織,並管理待處理的邀請可檢視預覽,內含 API 參考文件連結——按 Tab 鍵直到焦點進入卡片,按 Escape 鍵返回。。

邀請使用者加入您的組織:

client = anthropic.Anthropic()

invite = client.organization.invites.create(email="user@example.com", role="developer")

print(f"id: {invite.id}")
print(f"email: {invite.email}")
print(f"status: {invite.status}")
print(f"expires_at: {invite.expires_at}")

列出待處理、已接受和已過期的邀請:

client = anthropic.Anthropic()

invites = client.organization.invites.list(limit=10)

# 視需要自動擷取更多頁面,因此 `limit` 設定的是每頁大小,而非總數。
for invite in invites:
    print(f"{invite.id}: {invite.email} ({invite.status})")

刪除邀請:

client = anthropic.Anthropic()

deleted_invite = client.organization.invites.delete("invite_015gWxHNr6h6TdRPZTmuCGnn")

print(f"id: {deleted_invite.id}")

工作區

如需 Console 和 API 範例,請參閱工作區。

工作區成員

管理使用者對特定工作區的存取權可檢視預覽,內含 API 參考文件連結——按 Tab 鍵直到焦點進入卡片,按 Escape 鍵返回。。

將成員新增至工作區:

client = anthropic.Anthropic()

member = client.organization.workspaces.members.add(
    "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
    user_id="user_01WxYzAbCdEfGhJkMnPqRsTu",
    workspace_role="workspace_developer",
)

print(f"user_id: {member.user_id}")
print(f"workspace_role: {member.workspace_role}")

列出工作區的成員:

client = anthropic.Anthropic()

members = client.organization.workspaces.members.list(
    "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ", limit=10
)

# 視需要自動擷取更多頁面,因此 `limit` 設定的是每頁大小,而非總數。
for member in members:
    print(f"{member.user_id}: {member.workspace_role}")

更新工作區成員的角色:

client = anthropic.Anthropic()

member = client.organization.workspaces.members.update(
    "user_01WxYzAbCdEfGhJkMnPqRsTu",
    workspace_id="wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
    workspace_role="workspace_admin",
)

print(f"user_id: {member.user_id}")
print(f"workspace_role: {member.workspace_role}")

從工作區中移除成員:

client = anthropic.Anthropic()

removed_member = client.organization.workspaces.members.remove(
    "user_01WxYzAbCdEfGhJkMnPqRsTu", workspace_id="wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
)

print(f"user_id: {removed_member.user_id}")

API 金鑰

監控和管理 API 金鑰可檢視預覽,內含 API 參考文件連結——按 Tab 鍵直到焦點進入卡片,按 Escape 鍵返回。。回應中的每個金鑰都包含以下欄位:

  • expires_at:金鑰的到期時間。對於沒有到期時間的金鑰,其值為 null(請參閱金鑰到期)。
  • principal:金鑰所代表的身分(請參閱金鑰類型)。個人金鑰為 {"type": "user_actor", "user_id": "user_..."},服務帳戶金鑰為 {"type": "service_account_actor", "service_account_id": "svac_..."},工作區金鑰則為 null。
  • scope:金鑰可在何處使用。範圍限定於單一工作區的金鑰為 {"type": "workspace", "workspace_id": "wrkspc_..."},範圍限定於組織的金鑰則為 {"type": "organization"},這類金鑰可在多個工作區中使用。

以預設工作區的 ID 依 workspace_id 篩選列表時,只會回傳範圍限定於預設工作區的金鑰。範圍限定於組織的金鑰不會出現在任何 workspace_id 篩選結果中。若要列出這類金鑰,請省略 workspace_id:列表隨後會包含您的憑證可列出的每個開發者 API 金鑰(請參閱開發者 API 金鑰)。

列出工作區中的作用中 API 金鑰:

client = anthropic.Anthropic()

api_keys = client.organization.api_keys.list(
    limit=10, status="active", workspace_id="wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
)

# 會視需要自動擷取更多頁面,因此 `limit` 設定的是每頁大小,而非總數。
for api_key in api_keys:
    print(f"{api_key.id}: {api_key.name} ({api_key.status})")

重新命名或停用 API 金鑰:

client = anthropic.Anthropic()

api_key = client.organization.api_keys.update(
    "apikey_01Rj2N8SVvo6BePZj99NhmiT", status="inactive", name="New Key Name"
)

print(f"id: {api_key.id}")
print(f"name: {api_key.name}")
print(f"status: {api_key.status}")

服務帳戶

建立和管理服務帳戶(svac_...),即服務帳戶金鑰和工作負載身分聯合權杖所代表的非人類身分。這些端點與聯合簽發者和聯合規則端點一樣,需要 org:admin OAuth 權杖。請參閱使用 Admin API 管理 WIF 中的服務帳戶。

聯合發行者

註冊 OIDC 身分提供者(fdis_...),其權杖可為您的組織宣告工作負載身分。請參閱使用 Admin API 管理 WIF 中的聯合簽發者。

聯合規則

管理將簽發者權杖對應至服務帳戶和範圍的規則(fdrl_...)。請參閱使用 Admin API 管理 WIF 中的聯合規則。

存取組織資訊

/v1/organizations/me 端點會回傳您的憑證所屬的組織:

client = anthropic.Anthropic()

organization = client.organization.retrieve()

print(f"id: {organization.id}")
print(f"name: {organization.name}")
{
  "id": "12345678-1234-5678-1234-567812345678",
  "type": "organization",
  "name": "Organization Name"
}

如需參數詳細資訊和回應結構描述,請參閱組織資訊 API 參考文件可檢視預覽,內含 API 參考文件連結——按 Tab 鍵直到焦點進入卡片,按 Escape 鍵返回。。

用量與成本報告

使用用量與成本分析 API 追蹤您組織的用量與成本。用量與成本 API 是提供此資料的舊版 API。

Claude Code 分析

使用 Claude Code 分析 API 監控開發人員生產力和 Claude Code 採用情況。

速率限制

使用速率限制 API,讀取為您的組織及其工作區設定的速率限制,並設定工作區的速率限制。

Compliance API

使用 Compliance API 擷取您組織的稽核與活動資料。Admin API 金鑰只能讀取 Activity Feed。例外是 Safety Cases API:在您的組織可使用該 API 期間所建立的 Admin API 金鑰,也能存取該 API。透過該 API,此金鑰可以讀取被標記的訊息並回應 Safety Cases。如需完整存取權限,請參閱設定 Compliance API。

組織 webhook

使用組織 webhook註冊「webhook」(網路掛鉤)端點,以接收與您組織的使用者設定檔相關之執行措施事件。

雲端平台

在以下雲端平台上,請將請求傳送至該平台的基礎 URL。請使用該平台的憑證,而非驗證中所列的憑證。

在 Claude Platform on AWS 上,僅提供以下 Admin API 端點:

如需基礎 URL 和憑證,請參閱在 Claude Platform on AWS 上發出請求。

在 Claude Models on Google Cloud (Anthropic managed) 上,請使用在 Claude Models on Google Cloud (Anthropic managed) 上發送請求中所述的組織層級基礎 URL。您可以呼叫以下 Admin API 端點:

  • 工作區端點:/v1/organizations/workspaces 上的建立、取得、列出、更新和封存。
  • 用於 CMEK 的外部金鑰端點:/v1/organizations/external_keys 上的建立、取得、列出、更新和刪除。若要驗證並附加金鑰,請依照使用 Google Cloud KMS 設定 CMEK 操作。
  • 用量與成本分析 API 端點(目前處於 beta 階段):/v1/organizations/analytics/usage 和 /v1/organizations/analytics/cost。
  • 舊版用量與成本 API 的用量端點:/v1/organizations/usage_report/messages。
  • 讀取限制的速率限制 API 端點:GET /v1/organizations/rate_limits 和 GET /v1/organizations/workspaces/{workspace_id}/rate_limits。

最佳實務

  • 為工作區和 API 金鑰使用有意義的名稱和描述
  • 處理失敗操作所產生的錯誤
  • 定期稽核成員角色與權限
  • 封存未使用的工作區,並刪除不再需要的待處理邀請
  • 監控 API 金鑰用量、稽核每個金鑰的 expires_at(請參閱金鑰到期),並定期輪替金鑰

常見問題

如有工作區相關問題,請參閱工作區常見問題。

這個頁面有幫助嗎?