# Retry (/examples/models/huggingface/retry)



<Warning>
  The current Hugging Face adapter wraps provider errors without retaining HTTP status codes. Agno's terminal-status filter cannot distinguish 400/404 errors on this path, so configured retries can repeat them. Invalid model IDs can also fail before a provider request and are unsuitable for testing recovery.
</Warning>

```python title="retry.py"
"""Example demonstrating how to set up retries with Hugging Face."""

from agno.agent import Agent
from agno.models.huggingface import HuggingFace

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "huggingface-wrong-id"

agent = Agent(
    model=HuggingFace(
        id=wrong_model_id,
        retries=3,  # Number of times to retry the request.
        delay_between_retries=1,  # Delay between retries in seconds.
        exponential_backoff=True,  # If True, the delay between retries is doubled each time.
    ),
)

agent.print_response("What is the capital of France?")

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass
```

## Current Alternative [#current-alternative]

Configure `retries`, `delay_between_retries`, and `exponential_backoff` as shown in [Retry Model Requests](/models/overview#retry-model-requests). Test the retry path with a controlled transient 429, connection failure, or 5xx response.

Full source: [cookbook/90\_models/huggingface/retry.py](https://github.com/agno-agi/agno/blob/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/90_models/huggingface/retry.py)
