429 huggingface network_error ai_generated true

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

ID: huggingface/hub-rate-limit-exceeded

Also available as: JSON · Markdown · 中文
90%Fix Rate
88%Confidence
1Evidence
2023-09-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
huggingface-hub 0.22.0 active
requests 2.31.0 active
Python 3.11 active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 90% success Add a delay between requests using `time.sleep()` or use the `huggingface_hub` library's built-in retry logic. For example: 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) # Wait 1 second between requests
    Add a delay between requests using `time.sleep()` or use the `huggingface_hub` library's built-in retry logic. For example:
    
    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)  # Wait 1 second between requests
  2. 85% success Authenticate with a Hugging Face token to get a higher rate limit (e.g., 1000 requests per minute). Set the token via `huggingface-cli login` or `HfApi(token='hf_...')`.
    Authenticate with a Hugging Face token to get a higher rate limit (e.g., 1000 requests per minute). Set the token via `huggingface-cli login` or `HfApi(token='hf_...')`.

中文步骤

  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_...')` 设置令牌。

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 90% fail

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