Source: https://aiprimetech.io/zh/docs/api-reference/rate-limits/ [首页](/zh/) / [文档](/zh/docs/) / 速率限制 # 速率限制 限流机制、429 在这里的含义,以及如何构建不会触发该状态码的客户端。 复制页面 [ 以 Markdown 查看](/zh/docs/api-reference/rate-limits.md) [ 向 ChatGPT 提问](https://chatgpt.com/?q=Read%20https%3A//aiprimetech.io/docs/api-reference/rate-limits.md%20and%20answer%20questions%20about%20it.%20Start%20with%20a%20short%20summary.) [ 在 Claude 中提问](https://claude.ai/new?q=Read%20https%3A//aiprimetech.io/docs/api-reference/rate-limits.md%20and%20answer%20questions%20about%20it.%20Start%20with%20a%20short%20summary.) 限制旨在确保公平使用共享的上游容量。限制按账户生效,而非按密钥生效,因此增加密钥不会提高你的上限。 ## 限制项 | 维度 | 行为 | 并发请求数 | 每个账户正在处理的请求数。这通常是出现 429 的原因。 | 每分钟请求数 | 持续调用速率。 | 每分钟 token 数 | 输入和输出的合计吞吐量。 无限量套餐采用公平使用限制,而非额度余额机制——它们免除按 token 收费,但不会取消并发上限。 ## 正确处理 429 - 采用带随机抖动的指数退避——1 秒、2 秒、4 秒、8 秒,每次都随机增加或减少一小部分时间。 - 在客户端使用信号量限制并发,而不是一次性发出所有请求,再重试被拒绝的请求。 - 将批量任务排队处理,而不是尽可能提高并行度;吞吐量受每分钟 token 数限制,而非你打开的套接字数量。 - 将 529 以不同于以下情况的方式处理: 429 ——那是上游容量问题,并非你的问题,通常会在几秒内恢复。 ``` Copyimport asyncio sem = asyncio.Semaphore(8) class=class="s">"c"># ceiling on concurrency, tune to your plan async def ask(client, body): async with sem: return await client.post(class="s">"/v1/messages", json=body) ``` Claude Code 等智能体工具在设计上会积极并行发起任务。如果在高强度使用智能体时遇到 429 错误,请先降低工具的并行度,再考虑升级套餐。 ## 减轻压力,而非重试 - 将低成本任务路由至 claude-haiku-4-5 ——较小的模型完成得更快,占用并发名额的时间也更短。 - 启用 [提示词缓存](/zh/docs/guides/prompt-caching/):缓存的前缀可减少输入 token,从而减轻每分钟 token 限制的压力。 - 精简对话历史;请参阅 [上下文管理](/zh/docs/guides/context-management/). - 将离线任务集中安排在非高峰时段处理。 [错误状态码参考](/zh/docs/api-reference/errors/)[费用控制降低每项任务的成本](/zh/docs/guides/cost-control/)[套餐固定费率选项](/zh/docs/billing/plans/) [上一页错误](/zh/docs/api-reference/errors/)[下一页工具使用与函数调用](/zh/docs/api-reference/tool-use/)