The Admin API is unavailable for individual accounts. To collaborate with teammates and add members, set up your organization in Console → Settings → Organization.
Claude Code 分析管理 API 提供對 Claude Code 使用者每日彙總使用指標的程式化存取,使組織能夠分析開發者生產力並建立自訂儀表板。此 API 填補了我們基本的分析儀表板與複雜的 OpenTelemetry 整合之間的差距。
此 API 使您能夠更好地監控、分析和優化您的 Claude Code 採用:
需要管理 API 金鑰
此 API 是管理 API 的一部分。這些端點需要管理 API 金鑰(以 sk-ant-admin... 開頭),與標準 API 金鑰不同。只有具有管理員角色的組織成員才能透過 Claude Console 配置管理 API 金鑰。
取得您組織特定日期的 Claude Code 分析:
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08&\
limit=20" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"為整合設定 User-Agent 標頭
如果您正在建立整合,請設定 User-Agent 標頭以幫助我們了解使用模式:
User-Agent: YourApp/1.0.0 (https://yourapp.com)透過 /v1/organizations/usage_report/claude_code 端點追蹤您組織中的 Claude Code 使用情況、生產力指標和開發者活動。
starting_at 參數指定的單日指標有關完整的參數詳情和回應結構描述,請參閱 Claude Code 分析 API 參考。
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"# 第一次請求
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08&\
limit=20" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"
# 使用回應中的游標進行後續請求
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?\
starting_at=2025-09-08&\
page=page_MjAyNS0wNS0xNFQwMDowMDowMFo=" \
--header "anthropic-version: 2023-06-01" \
--header "x-api-key: $ADMIN_API_KEY"| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
starting_at | string | 是 | UTC 日期,格式為 YYYY-MM-DD。僅返回該單日的指標 |
limit | integer | 否 | 每頁記錄數(預設:20,最大:1000) |
page | string | 否 | 來自前一個回應 next_page 欄位的不透明游標 token |
每個回應記錄包含單一使用者在單一天的以下指標:
user_actor 包含 email_address 或 api_actor 包含 api_key_name)api 代表 API 客戶,subscription 代表 Pro/Team 客戶)vscode、iTerm.app、tmux)按工具類型細分的工具操作接受和拒絕率:
對於每個使用的 Claude 模型:
claude-opus-4-6)USD)API 以以下格式返回資料:
{
"data": [
{
"date": "2025-09-01T00:00:00Z",
"actor": {
"type": "user_actor",
"email_address": "[email protected]"
},
"organization_id": "dc9f6c26-b22c-4831-8d01-0446bada88f1",
"customer_type": "api",
"terminal_type": "vscode",
"core_metrics": {
"num_sessions": 5,
"lines_of_code": {
"added": 1543,
"removed": 892
},
"commits_by_claude_code": 12,
"pull_requests_by_claude_code": 2
},
"tool_actions": {
"edit_tool": {
"accepted": 45,
"rejected": 5
},
"multi_edit_tool": {
"accepted": 12,
"rejected": 2
},
"write_tool": {
"accepted": 8,
"rejected": 1
},
"notebook_edit_tool": {
"accepted": 3,
"rejected": 0
}
},
"model_breakdown": [
{
"model": "claude-opus-4-6",
"tokens": {
"input": 100000,
"output": 35000,
"cache_read": 10000,
"cache_creation": 5000
},
"estimated_cost": {
"currency": "USD",
"amount": 1025
}
}
]
}
],
"has_more": false,
"next_page": null
}API 支援基於游標的分頁,適用於擁有大量使用者的組織:
limit 參數進行初始請求has_more 為 true,在下一次請求中使用 next_page 值has_more 為 false游標編碼了最後一筆記錄的位置,即使有新資料到達也能確保穩定的分頁。每個分頁工作階段維持一致的資料邊界,確保您不會遺漏或重複記錄。
Claude Code 分析資料通常在使用者活動完成後 1 小時內出現。為確保一致的分頁結果,回應中僅包含超過 1 小時的資料。
不行,此 API 僅提供每日彙總指標。如需即時監控,請考慮使用 OpenTelemetry 整合。
使用者透過 actor 欄位以兩種方式識別:
user_actor:包含透過 OAuth 驗證的使用者的 email_address(最常見)api_actor:包含透過 API 金鑰驗證的使用者的 api_key_namecustomer_type 欄位指示使用來自 api 客戶(API PAYG)還是 subscription 客戶(Pro/Team 方案)。
歷史 Claude Code 分析資料會被保留並可透過 API 存取。此資料沒有指定的刪除期限。
此 API 僅追蹤 Claude API(第一方)上的 Claude Code 使用情況。不包含 Amazon Bedrock、Google Vertex AI 或其他第三方平台上的使用情況。
Claude Code 分析 API 對所有有權存取管理 API 的組織免費使用。
工具接受率 = accepted / (accepted + rejected),適用於每種工具類型。例如,如果 edit 工具顯示 45 個接受和 5 個拒絕,接受率為 90%。
所有日期均為 UTC。starting_at 參數應為 YYYY-MM-DD 格式,代表該日的 UTC 午夜。
Claude Code 分析 API 幫助您了解和優化團隊的開發工作流程。了解更多相關功能:
Was this page helpful?