处理 API 速率限制#
¥Handling API rate limits
API 速率限制是对请求频率的限制。例如,API 可能会限制你每分钟或每天可以发出的请求数量。
¥API rate limits are restrictions on request frequency. For example, an API may limit the number of requests you can make per minute, or per day.
API 还可以限制你在单个请求中发送的数据量,或 API 在单个响应中发送的数据量。
¥APIs can also limits how much data you can send in one request, or how much data the API sends in a single response.
识别速率限制问题#
¥Identify rate limit issues
当 n8n 节点达到速率限制时,将报错。n8n 在节点输出面板中显示错误消息。这包括来自服务的错误消息。
¥When an n8n node hits a rate limit, it errors. n8n displays the error message in the node output panel. This includes the error message from the service.
如果 n8n 从服务收到错误 429(请求过多),则错误消息为“服务收到的请求过多”。
¥If n8n received error 429 (too many requests) from the service, the error message is The service is receiving too many requests from you.
要检查你正在使用的服务的速率限制,请参阅该服务的 API 文档。
¥To check the rate limits for the service you're using, refer to the API documentation for the service.
处理集成速率限制#
¥Handle rate limits for integrations
在 n8n 集成中处理速率限制有两种方法:使用“失败时重试”设置,或结合使用 循环处理项目 和 等待 节点。
¥There are two ways to handle rate limits in n8n's integrations: using the Retry On Fail setting, or using a combination of the Loop Over Items and Wait nodes:
- 失败重试:在 API 请求尝试之间添加暂停。
¥Retry On Fail adds a pause between API request attempts.
- 使用循环遍历项目和等待功能,你可以将请求数据拆分成更小的块,并在请求之间暂停。
¥With Loop Over Items and Wait you can break you request data into smaller chunks, as well as pausing between requests.
启用失败重试#
¥Enable Retry On Fail
启用“失败时重试”后,如果第一次请求失败,节点会自动重试。
¥When you enable Retry On Fail, the node automatically tries the request again if it fails the first time.
- 打开节点。
¥Open the node. 2. 选择“设置”。
¥Select Settings. 3. 启用“失败时重试”开关。
¥Enable the Retry On Fail toggle.
4. 配置重试设置:如果使用此功能来规避速率限制,请将“尝试间隔 (毫秒)”设置为大于速率限制的值。例如,如果你使用的 API 允许每秒发送一个请求,请将“尝试间隔 (毫秒)”设置为 1000,以允许 1 秒的等待时间。
¥Configure the retry settings: if using this to work around rate limits, set Wait Between Tries (ms) to more than the rate limit. For example, if the API you're using allows one request per second, set Wait Between Tries (ms) to 1000 to allow a 1 second wait.
使用循环遍历项目并等待#
¥Use Loop Over Items and Wait
使用“循环处理项目”节点批量处理输入项目,并使用“等待”节点在每个请求之间添加暂停。
¥Use the Loop Over Items node to batch the input items, and the Wait node to introduce a pause between each request.
- 在调用 API 的节点之前添加循环遍历项目节点。请参阅 循环处理项目 以了解如何配置节点。
¥Add the Loop Over Items node before the node that calls the API. Refer to Loop Over Items for information on how to configure the node. 2. 在调用 API 的节点之后添加等待节点,并将其连接回循环遍历项目节点。请参阅 等待 以了解如何配置节点。
¥Add the Wait node after the node that calls the API, and connect it back to the Loop Over Items node. Refer to Wait for information on how to configure the node.
例如,要处理使用 OpenAI 时的速率限制:
¥For example, to handle rate limits when using OpenAI:
处理 HTTP 请求节点中的速率限制#
¥Handle rate limits in the HTTP Request node
HTTP 请求节点内置了用于处理速率限制和大量数据的设置。
¥The HTTP Request node has built-in settings for handling rate limits and large amounts of data.
批处理请求#
¥Batch requests
使用批处理选项发送多个请求,从而减小请求大小,并在请求之间引入暂停。这相当于使用“循环遍历项目”和“等待”功能。
¥Use the Batching option to send more than one request, reducing the request size, and introducing a pause between requests. This is the equivalent of using Loop Over Items and Wait.
- 在“HTTP 请求”节点中,选择“添加选项”>“批处理”。
¥In the HTTP Request node, select Add Option > Batching. 2. 设置每批次项目数:这是每个请求中包含的输入项数量。
¥Set Items per Batch: this is the number of input items to include in each request.
3. 设置“批处理间隔(毫秒)”以在请求之间引入延迟。例如,如果你使用的 API 允许每秒发送一个请求,请将“尝试间隔 (毫秒)”设置为 1000,以允许 1 秒的等待时间。
¥Set Batch Interval (ms) to introduce a delay between requests. For example, if the API you're using allows one request per second, set Wait Between Tries (ms) to 1000 to allow a 1 second wait.
结果分页#
¥Paginate results
当 API 需要发送的数据量超过其单次响应的处理能力时,它会对结果进行分页处理。有关 HTTP 请求节点中分页的更多信息,请参阅 HTTP 请求节点 |分页。
¥APIs paginate their results when they need to send more data than they can handle in a single response. For more information on pagination in the HTTP Request node, refer to HTTP Request node | Pagination.
