> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/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).

<CodeGroup>
  ```bash Mac theme={null}
  export HF_TOKEN=***
  ```

  ```bash Windows theme={null}
  setx HF_TOKEN ***
  ```
</CodeGroup>

## Example

Install the `huggingface_hub` package:

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

Use `HuggingFace` with your `Agent`:

<CodeGroup>
  ```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.")
  ```
</CodeGroup>

<Note> View more examples [here](/models/providers/gateways/huggingface/usage/basic-stream). </Note>

## 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](/reference/models/model) class and has access to the same params.
