速率限制 API
使用 Rate Limits API 以程式化方式查詢您組織的 API 速率限制。
速率限制 API 提供以程式化方式存取為您的組織及其工作區所設定之速率限制的功能。這與 Claude Console 中速率限制頁面上顯示的資訊相同。
使用此 API 來:
- 讓閘道和代理保持同步: 在啟動時及依排程讀取您目前的限制,而不是將數值寫死在程式中,因為當 Anthropic 調整限制時,這些數值會產生偏差。
- 支援內部警示: 將來自用量與成本 API 的使用量資料與您設定的限制進行比較。
- 稽核工作區設定: 驗證工作區覆寫設定是否符合您的佈建自動化所預期的內容。
本頁面上的 SDK 和 CLI 範例會建構預設用戶端,該用戶端會從 ANTHROPIC_API_KEY 環境變數讀取 Admin API 金鑰。SDK 將這些端點公開為 client.organization.rate_limits 和 client.organization.workspaces.rate_limits;Python、TypeScript、C#、Go 和 Java 的 list 方法會回傳一個自動為您追蹤 next_page 的迭代器,而 PHP、Ruby 和 curl 範例則只讀取一頁。
快速開始
列出為您的組織設定的速率限制:
client = anthropic.Anthropic()
rate_limits = client.organization.rate_limits.list()
for entry in rate_limits:
models = f" ({', '.join(entry.models)})" if entry.models else ""
print(f"{entry.group.type}{models}")
for limit in entry.limits:
print(f" {limit.type}: {limit.value}")組織速率限制
/v1/organizations/rate_limits 端點會回傳在組織層級套用於 Messages API 及其支援資源的速率限制。其他產品(例如 Claude Managed Agents)的限制不包含在內。
關鍵概念
- 速率限制群組: 回應中的每個項目代表一個速率限制群組。模型速率限制會被分組,讓多個模型版本共用同一組限制;其他群組則涵蓋 Message Batches API、Files API、Token Counting API、agent skills 和網頁搜尋工具等資源。
group物件: 存在於每個項目中,用於識別該項目所套用的速率限制群組。它一定包含type(為group_type值之一)以及id(帶有rlg_前綴的不透明識別碼)。在model_group項目中,它還包含display_name,即 Anthropic 目前為該群組使用的標籤,例如Claude Sonnet 4.x。此標籤僅供顯示用途,且可能會變更。其他群組類型沒有display_name。group內的id: 一個群組在每個組織及每個工作區覆寫中都具有相同的id,且永遠不會變更。使用它來比對不同組織之間的項目,或與您自己的目錄進行比對。項目本身的id在每個組織中都不同,而當 Anthropic 將模型移至其他群組時,models也會改變。兩者都不是群組的穩定鍵值。group_type: 已棄用,改用group內的type。它仍會被回傳,其值永遠等於該值,且沒有移除日期。group_type查詢參數並未被棄用。請參閱依群組類型篩選以取得值的清單。models清單: 對於model_group項目,models欄位會列出計入該群組限制的每個模型 ID 和別名。使用此清單來查詢任何模型字串屬於哪個群組。對於其他群組類型,models為null。limits清單: 每個群組都帶有一個{type, value}配對的清單。type欄位識別限制器(例如requests_per_minute、input_tokens_per_minute或output_tokens_per_minute),而value是所設定的限制。請參閱速率限制以了解每個限制器的測量與執行方式。- 工作區限制上的
source: 在工作區端點上,每個限制值還帶有source,說明value的來源:{"type": "workspace"}表示儲存在工作區上的覆寫,{"type": "organization"}表示從組織繼承的值。預設情況下,工作區端點只回傳覆寫,因此source.type在該處一律為workspace;當您傳入include_inherited=true時,才會出現繼承的值。請參閱工作區速率限制。
如需完整的參數詳細資訊和回應結構描述,請參閱組織速率限制 API 參考。
列出所有組織速率限制
client = anthropic.Anthropic()
rate_limits = client.organization.rate_limits.list()
for entry in rate_limits:
models = f" ({', '.join(entry.models)})" if entry.models else ""
print(f"{entry.group.type}{models}")
for limit in entry.limits:
print(f" {limit.type}: {limit.value}"){
"data": [
{
"type": "rate_limit",
"group_type": "model_group",
"group": {
"type": "model_group",
"id": "rlg_01Hq7YkP3mZ9dTwRx4cVbN2s",
"display_name": "Claude Opus 5.5"
},
"models": ["claude-opus-5-5"],
"limits": [
{ "type": "requests_per_minute", "value": 4000 },
{ "type": "input_tokens_per_minute", "value": 10000000 },
{ "type": "output_tokens_per_minute", "value": 800000 }
]
},
{
"type": "rate_limit",
"group_type": "model_group",
"group": {
"type": "model_group",
"id": "rlg_01Kd5wMv8nSq2LcXy6tRfJ4b",
"display_name": "Claude Opus 4.x"
},
"models": [
"claude-opus-4-5",
"claude-opus-4-5-20251101",
"claude-opus-4-6",
"claude-opus-4-7",
"claude-opus-4-8"
],
"limits": [
{ "type": "requests_per_minute", "value": 4000 },
{ "type": "input_tokens_per_minute", "value": 10000000 },
{ "type": "output_tokens_per_minute", "value": 800000 }
]
},
{
"type": "rate_limit",
"group_type": "batch",
"group": { "type": "batch", "id": "rlg_01Wn3pBz6kCg9vHtQ7mLxD5a" },
"models": null,
"limits": [{ "type": "enqueued_batch_requests", "value": 500000 }]
}
],
"next_page": null
}查詢特定模型的限制
將任何模型 ID 或別名作為 model 查詢參數傳入,即可只回傳包含該模型的項目:
client = anthropic.Anthropic()
rate_limits = client.organization.rate_limits.list(model="claude-opus-5-5")
for entry in rate_limits:
models = f" ({', '.join(entry.models)})" if entry.models else ""
print(f"{entry.group.type}{models}")
for limit in entry.limits:
print(f" {limit.type}: {limit.value}")如果模型字串不符合任何群組,端點會回傳 404 錯誤。model 參數僅在組織端點上受支援;工作區端點不接受此參數。
工作區速率限制
/v1/organizations/workspaces/{workspace_id}/rate_limits 端點會回傳為單一工作區設定的速率限制覆寫。若也要查看工作區繼承的值,請傳入 include_inherited=true(請參閱包含繼承的值)。
預設情況下,回應只包含覆寫,因此其中缺少的任何內容都是從組織繼承而來:
- 不存在於
data中的群組完全沒有工作區覆寫。該工作區會繼承該群組的組織層級限制(並非無限制)。 - 在存在的群組中,不存在於
limits[]中的限制器類型沒有針對該限制器的工作區覆寫。該工作區會繼承其組織值。 - 對於每個存在的限制器,
org_limit是同一限制器的組織層級值,若組織未為該限制器類型設定限制則為null,而source為{"type": "workspace"}。
如需完整的參數詳細資訊和回應結構描述,請參閱工作區速率限制 API 參考。
client = anthropic.Anthropic()
rate_limits = client.organization.workspaces.rate_limits.list(
"wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ"
)
for entry in rate_limits:
models = f" ({', '.join(entry.models)})" if entry.models else ""
print(f"{entry.group.type}{models}")
for limit in entry.limits:
print(f" {limit.type}: {limit.value}"){
"data": [
{
"type": "workspace_rate_limit",
"group_type": "model_group",
"group": {
"type": "model_group",
"id": "rlg_01Hq7YkP3mZ9dTwRx4cVbN2s",
"display_name": "Claude Opus 5.5"
},
"models": ["claude-opus-5-5"],
"limits": [
{
"type": "requests_per_minute",
"value": 1000,
"org_limit": 4000,
"source": { "type": "workspace" }
},
{
"type": "input_tokens_per_minute",
"value": 500000,
"org_limit": 10000000,
"source": { "type": "workspace" }
}
]
},
{
"type": "workspace_rate_limit",
"group_type": "model_group",
"group": {
"type": "model_group",
"id": "rlg_01Kd5wMv8nSq2LcXy6tRfJ4b",
"display_name": "Claude Opus 4.x"
},
"models": [
"claude-opus-4-5",
"claude-opus-4-5-20251101",
"claude-opus-4-6",
"claude-opus-4-7",
"claude-opus-4-8"
],
"limits": [
{
"type": "requests_per_minute",
"value": 1000,
"org_limit": 4000,
"source": { "type": "workspace" }
},
{
"type": "input_tokens_per_minute",
"value": 500000,
"org_limit": 10000000,
"source": { "type": "workspace" }
}
]
}
],
"next_page": null
}包含繼承的值
若要在一次請求中讀取工作區適用的限制,請加入選用的 include_inherited 查詢參數。其預設值為 false;非布林值會回傳 400 錯誤。使用 include_inherited=true 時:
data會為每個適用於該工作區且具有組織層級值的群組提供一個項目,即使工作區未覆寫其中任何內容也是如此。當工作區可以存取模型群組中至少一個模型時,該模型群組即適用。- 每個項目的
limits[]會列出組織在該群組上具有值的每個限制器類型,以及工作區覆寫的任何類型。每個類型只出現一次,若有儲存工作區的覆寫則使用該覆寫,否則使用組織的值,因此一個項目可能混合兩者。 - 每個值的
source可用來區分兩者:{"type": "workspace"}是儲存的覆寫,而{"type": "organization"}是繼承的值,其中value等於org_limit。
client = anthropic.Anthropic()
rate_limits = client.organization.workspaces.rate_limits.list(
"wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ",
include_inherited=True,
)
for entry in rate_limits:
models = f" ({', '.join(entry.models)})" if entry.models else ""
print(f"{entry.group.type}{models}")
for limit in entry.limits:
print(f" {limit.type}: {limit.value} ({limit.source.type})"){
"data": [
{
"type": "workspace_rate_limit",
"group_type": "model_group",
"group": {
"type": "model_group",
"id": "rlg_01Hq7YkP3mZ9dTwRx4cVbN2s",
"display_name": "Claude Opus 5.5"
},
"models": ["claude-opus-5-5"],
"limits": [
{
"type": "requests_per_minute",
"value": 1000,
"org_limit": 4000,
"source": { "type": "workspace" }
},
{
"type": "input_tokens_per_minute",
"value": 500000,
"org_limit": 10000000,
"source": { "type": "workspace" }
},
{
"type": "output_tokens_per_minute",
"value": 800000,
"org_limit": 800000,
"source": { "type": "organization" }
}
]
},
{
"type": "workspace_rate_limit",
"group_type": "model_group",
"group": {
"type": "model_group",
"id": "rlg_01Kd5wMv8nSq2LcXy6tRfJ4b",
"display_name": "Claude Opus 4.x"
},
"models": [
"claude-opus-4-5",
"claude-opus-4-5-20251101",
"claude-opus-4-6",
"claude-opus-4-7",
"claude-opus-4-8"
],
"limits": [
{
"type": "requests_per_minute",
"value": 1000,
"org_limit": 4000,
"source": { "type": "workspace" }
},
{
"type": "input_tokens_per_minute",
"value": 500000,
"org_limit": 10000000,
"source": { "type": "workspace" }
},
{
"type": "output_tokens_per_minute",
"value": 800000,
"org_limit": 800000,
"source": { "type": "organization" }
}
]
},
{
"type": "workspace_rate_limit",
"group_type": "batch",
"group": { "type": "batch", "id": "rlg_01Wn3pBz6kCg9vHtQ7mLxD5a" },
"models": null,
"limits": [
{
"type": "enqueued_batch_requests",
"value": 500000,
"org_limit": 500000,
"source": { "type": "organization" }
}
]
}
],
"next_page": null
}依群組類型篩選
兩個端點都接受一個選用的 group_type 查詢參數,可將回應限制為單一類別:
client = anthropic.Anthropic()
rate_limits = client.organization.rate_limits.list(group_type="batch")
for entry in rate_limits:
models = f" ({', '.join(entry.models)})" if entry.models else ""
print(f"{entry.group.type}{models}")
for limit in entry.limits:
print(f" {limit.type}: {limit.value}")有效值為 model_group、batch、token_count、files、skills 和 web_search。
分頁
兩個端點皆接受 page 查詢參數並回傳 next_page 欄位。目前回應一律為單一頁面,因此 next_page 為 null。請以 next_page 進行迴圈,如此當回應內容增加時,您的用戶端無需修改即可正確分頁。
常見問題
哪些模型字串會出現在 models 清單中?
計入該群組的每個模型 ID 與別名,包括帶日期的 ID(例如 claude-sonnet-4-5-20250929)與不帶日期的別名(例如 claude-sonnet-4-5)。查詢您傳給 Messages API 的任何模型字串,您都會在恰好一個 model_group 項目中找到它。
如果工作區回應中缺少某個群組,代表什麼意思?
預設情況下,工作區回應只列出覆寫,因此缺少的群組沒有工作區覆寫,並繼承組織層級的限制。傳入 include_inherited=true 即可在工作區端點上查看繼承的值,或查詢組織端點。使用 include_inherited=true 時,只有當群組不適用於該工作區,或組織未為其設定限制時,該群組才會缺少。
我可以使用此 API 更新速率限制嗎?
不可以。若要設定工作區速率限制,請前往 Claude Console 中的速率限制頁面,從工作區下拉選單中選擇工作區,然後點擊模型旁的編輯。
另請參閱
Was this page helpful?