Claude Platform Docs
管理监控

速率限制 API

使用速率限制 API 以编程方式查询您组织的 API 速率限制。

速率限制 API(Rate Limits API)提供对您的组织及其工作区所配置的 "rate limit"(速率限制)的编程访问。这与 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 的列表方法返回一个会自动跟随 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 中的速率限制页面,从 Workspace 下拉菜单中选择工作区,然后点击模型旁边的 Edit。

另请参阅

Was this page helpful?