Skip to content

限流

默认配额

维度配额
每个 (AppID, 客户端 IP) 每分钟600 次请求
窗口60 秒(滚动)
超出返回HTTP 429

实际配额可能根据账号等级调整,请以你账号实际值为准。

429 响应

json
{
  "code": 429,
  "message": "请求过于频繁,请稍后再试",
  "data": null
}

部分情况下还会附带 Retry-After 响应头,单位秒。

客户端建议

1. 退避重试(针对 429 / 5xx)

python
import time, random

def call_with_retry(fn, *args, max_attempts=4):
    for attempt in range(max_attempts):
        try:
            resp = fn(*args)
            if resp.get('code') == 429:
                wait = (2 ** attempt) + random.random()
                time.sleep(min(wait, 30))
                continue
            return resp
        except Exception:
            if attempt == max_attempts - 1:
                raise
            time.sleep(2 ** attempt)

不要无限重试

对 4xx(除 429)不要重试 —— 是请求本身的问题,重试只会重复失败。

2. 控制并发

如果你的业务侧需要批量开卡,建议:

  • 单 worker 顺序请求(< 10 QPS)
  • 多 worker 时通过队列控制总并发,留出余量给其他业务

3. 不要触发限流来"测试"

每次 429 都计入限流计数,可能让你后续真实请求被拒。用小流量手工验证即可。

与幂等键的配合

如果你因 429 重试,请保持同一个 Idempotency-Key(针对写接口)。这样即使有一次请求实际到达后端但响应丢失,重试也不会重复开卡。

采用 MIT 等价条款发布