> ## Documentation Index
> Fetch the complete documentation index at: https://developers.uqpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 限流

> UQPAY API 对身份验证接口做了限流，以防止滥用导致所有用户的 API 性能无法稳定维持。

API 按分钟进行限流，不同资源按客户账户维度设定不同的速率限制。以某个资源的速率限制为每分钟 10 次请求为例，同一分钟内（例如 16:20:00 至 16:21:00 之间）超过 10 次的请求都会返回错误。限流器允许突发流量，因此如果前 50 秒内没有任何请求，但接下来的 10 秒内收到 10 次请求，这些请求都会成功。

你必须在 API 客户端中对 HTTP 429 响应码实现合适的错误处理。推荐使用带随机抖动的指数退避策略来处理 HTTP 429 响应码。

不同资源根据 API 客户端是否发起已认证请求而适用不同的速率限制，如下表所示。

| 请求类型      | 请求路径                  | 速率限制（Sandbox） | 速率限制（Production） |
| :-------- | :-------------------- | :------------ | :--------------- |
| 身份验证      | /api/v1/connect/token | 每分钟 60 次请求    | 每分钟 100 次请求      |
| 其他所有已认证请求 | /api/v1/\*            | 每分钟 500 次请求   | 每分钟 300 次请求      |
| 其他所有未认证请求 | /api/v1/\*            | 每分钟 200 次请求   | 每分钟 100 次请求      |

<h2 id="exceeding-the-rate-limit">超出限流</h2>

当超出速率限制时，API 将返回 HTTP 状态码 `429 -- "Too Many Requests"`，响应体为 JSON 格式，示例如下：

```http theme={null}
HTTP/1.1 429 Too Many Requests
Date: Mon, 25 Jan 2021 13:16:59 GMT
Content-Type: application/json; charset=UTF-8
{
  "code": "too_many_requests",
  "message": "Too many requests have been made to the api. Please refer to the Developer Center for more information",
}
```
