> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# HuggingFace

> Use Hugging Face models with Agno agents.

Hugging Face hosts open-source language models and serves them through its Inference API.
Agno's `HuggingFace` model connects to this API using the `huggingface_hub` client library.

See the [Hugging Face Inference API docs](https://huggingface.co/docs/api-inference/index) for supported models.

## Authentication

Set your `HF_TOKEN` environment variable. Get your key [from Hugging Face here](https://huggingface.co/settings/tokens).

```bash Mac theme={null}
export HF_TOKEN=***
```

```bash Windows theme={null}
setx HF_TOKEN ***
```

## Example

Install the `huggingface_hub` package:

```shell theme={null}
uv pip install -U huggingface_hub agno
```

Use `HuggingFace` with your `Agent`:

```python agent.py theme={null}
from agno.agent import Agent
from agno.models.huggingface import HuggingFace

agent = Agent(
    model=HuggingFace(
        id="meta-llama/Meta-Llama-3-8B-Instruct",
        max_tokens=4096,
    ),
    markdown=True
)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story.")
```

> [!NOTE]
>
> View more examples [here](https://agno-v2.mintlify.site/models/providers/gateways/huggingface/usage/basic-stream.md).

## Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `id` | `str` | `"meta-llama/Meta-Llama-3-8B-Instruct"` | The id of the Hugging Face model to use |
| `name` | `str` | `"HuggingFace"` | The name of the model |
| `provider` | `str` | `"HuggingFace"` | The provider of the model |
| `api_key` | `Optional[str]` | `None` | The API key for Hugging Face (defaults to HF\_TOKEN env var) |
| `base_url` | `Optional[Union[str, httpx.URL]]` | `None` | The base URL for the inference endpoint |
| `max_tokens` | `Optional[int]` | `None` | Maximum number of tokens to generate |
| `temperature` | `Optional[float]` | `None` | Controls randomness in the model's output |
| `top_p` | `Optional[float]` | `None` | Controls diversity via nucleus sampling |
| `timeout` | `Optional[float]` | `None` | Request timeout in seconds |

`HuggingFace` is a subclass of the [Model](https://agno-v2.mintlify.site/reference/models/model.md) class and has access to the same params.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.