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

- **ID:** `huggingface/hub-rate-limit-exceeded`
- **Domain:** huggingface
- **Category:** network_error
- **Error Code:** `429`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## 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).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| huggingface-hub 0.22.0 | active | — | — |
| requests 2.31.0 | active | — | — |
| Python 3.11 | active | — | — |

## Workarounds

1. **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** (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
   ```
2. **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_...')`.** (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_...')`.
   ```

## Dead Ends

- **** — Rate limits are enforced per IP/token; more parallel requests will hit the limit faster and trigger the error sooner. (95% fail)
- **** — Without caching, every request counts against the rate limit, making the problem worse. (90% fail)
