---
title: "Hugging Face (gateway)"
description: "Set up Hugging Face with the Respan gateway."
---

Route Hugging Face model calls through the Respan gateway after the Hugging Face model you want is available in your Respan model list. Your application uses the OpenAI-compatible Respan endpoint and only sends `RESPAN_API_KEY`; provider credentials are managed in Respan.

## Setup

<Steps>
<Step title="Install packages">

```bash
pip install openai
```

</Step>

<Step title="Set environment variables">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

Configure the provider credentials required by your model in Respan. Once they are stored, no `HUGGINGFACE_API_KEY` is needed in application code. Check the exact model's billing label in the [model catalog](https://platform.respan.ai/platform/models); hosting a model on Hugging Face does not by itself make it available through Respan credits.

</Step>

<Step title="Point an OpenAI-compatible client to the Respan gateway">

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url="https://api.respan.ai/api",
)

response = client.chat.completions.create(
    model="YOUR_HUGGINGFACE_MODEL_ID",
    messages=[{"role": "user", "content": "Say hello in three languages."}],
)
print(response.choices[0].message.content)
```

</Step>

<Step title="View your request">

Open the [Spans page](https://platform.respan.ai/platform/requests) to inspect the gateway request, model, latency, token usage, cost, and response content.

</Step>
</Steps>

## Switch models

Change the `model` parameter to use 1000+ models from different providers through the same gateway.

```python
response = client.chat.completions.create(model="YOUR_HUGGINGFACE_MODEL_ID", messages=messages)
response = client.chat.completions.create(model="openai/gpt-6-sol", messages=messages)
response = client.chat.completions.create(model="anthropic/claude-opus-5-5", messages=messages)
```

See the [full model list](https://platform.respan.ai/platform/models).
