Claude Platform Docs

擷取 API 金鑰(Admin API)

beta.organization.api_keys.retrieve(api_key_id) -> BetaAPIKey
GET/v1/organizations/api_keys/{api_key_id}

依 ID 查詢並擷取您組織中單一 API 金鑰的資訊。此 Admin API 端點需要 Admin API 金鑰,適用於以程式方式管理金鑰,且絕不會傳回金鑰的秘密值。若要檢視或建立您自己的 API 金鑰,請前往 Claude Console 中的 API 金鑰。

Parameters
api_key_id: str⁠Path parameter

ID of the API key.

Returns
class BetaAPIKey: type: "api_key"; id; created_at; ... # 8 more
擷取 API 金鑰(Admin API)
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ.get(
        "ANTHROPIC_API_KEY"
    ),  # This is the default and can be omitted
)
beta_api_key = client.beta.organization.api_keys.retrieve(
    "api_key_id",
)
print(beta_api_key.id)
Returns Examples
Response 200
{
  "id": "apikey_01Rj2N8SVvo6BePZj99NhmiT",
  "created_at": "2024-10-30T23:58:27.427722Z",
  "created_by": {
    "id": "user_01WCz1FkmYMm4gnmykNKUu3Q",
    "type": "user"
  },
  "expires_at": "2024-10-30T23:58:27.427722Z",
  "name": "Developer Key",
  "partial_key_hint": "sk-ant-api03-R2D...igAA",
  "principal": {
    "type": "user_actor",
    "user_id": "user_01WCz1FkmYMm4gnmykNKUu3Q"
  },
  "scope": {
    "type": "workspace",
    "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
  },
  "status": "active",
  "type": "api_key",
  "workspace_id": "wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
}