429 huggingface network_error ai_generated true

HTTPError: 429 客户端错误:请求过多,URL:https://huggingface.co/api/models/gpt2

HTTPError: 429 Client Error: Too Many Requests for url: https://huggingface.co/api/models/gpt2

ID: huggingface/hub-rate-limit-exceeded

其他格式: JSON · Markdown 中文 · English
90%修复率
88%置信度
1证据数
2023-09-01首次发现

版本兼容性

版本状态引入弃用备注
huggingface-hub 0.22.0 active
requests 2.31.0 active
Python 3.11 active

根因分析

由于短时间内请求过多(未认证用户通常每分钟100个请求),Hugging Face Hub API速率限制已超出。

English

The Hugging Face Hub API rate limit has been exceeded due to too many requests in a short time period (typically 100 requests per minute for unauthenticated users).

generic

官方文档

https://huggingface.co/docs/hub/en/rate-limits

解决方案

  1. 在请求之间添加延迟,使用 `time.sleep()` 或使用 `huggingface_hub` 库的内置重试逻辑。例如:
    
    from huggingface_hub import HfApi
    import time
    api = HfApi()
    models = ['gpt2', 'bert-base-uncased', 'roberta-base']
    for model_id in models:
        model_info = api.model_info(model_id)
        time.sleep(1)  # 每次请求等待1秒
  2. 使用Hugging Face令牌进行身份验证以获得更高的速率限制(例如每分钟1000个请求)。通过 `huggingface-cli login` 或 `HfApi(token='hf_...')` 设置令牌。

无效尝试

常见但无效的做法:

  1. 95% 失败

    Rate limits are enforced per IP/token; more parallel requests will hit the limit faster and trigger the error sooner.

  2. 90% 失败

    Without caching, every request counts against the rate limit, making the problem worse.