> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptguard.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Hugging Face

> Scan Hugging Face Inference Providers traffic through the PromptGuard proxy with any OpenAI client

## Proxy

> [!NOTE]
>
> **Proxy Base URL:** `https://api.promptguard.co/api/v1`
>
> Point your LLM SDK's `base_url` / `baseURL` to this endpoint. Your existing provider API key goes in the `Authorization` header as usual; add your PromptGuard key via `X-API-Key`.

Hub model ids starting `microsoft/phi`, `deepseek-ai/`, `mistralai/`, `tiiuae/`, `bigscience/`, `google/gemma`, `huggingfaceh4/` or `hf/` go to Hugging Face's Inference Providers router. Ids starting `meta-llama/` or `qwen/` do not: [Groq](https://docs.promptguard.co/integrations/providers/groq.md) is checked first and claims them.

Hugging Face speaks OpenAI's wire format, so PromptGuard forwards your request to `router.huggingface.co/v1` as you sent it and returns Hugging Face's reply unchanged. Any OpenAI client works.

```python Python theme={"system"}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.promptguard.co/api/v1",
    api_key=os.environ["HF_TOKEN"],  # forwarded to Hugging Face
    default_headers={"X-API-Key": os.environ["PROMPTGUARD_API_KEY"]},
)

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-R1",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
```

```typescript Node.js theme={"system"}
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.promptguard.co/api/v1',
  apiKey: process.env.HF_TOKEN, // forwarded to Hugging Face
  defaultHeaders: { 'X-API-Key': process.env.PROMPTGUARD_API_KEY },
});

const response = await client.chat.completions.create({
  model: 'deepseek-ai/DeepSeek-R1',
  messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);
```

```bash cURL theme={"system"}
curl https://api.promptguard.co/api/v1/chat/completions \
  -H "X-API-Key: $PROMPTGUARD_API_KEY" \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek-ai/DeepSeek-R1", "messages": [{"role": "user", "content": "Hello!"}]}'
```

To keep the Hugging Face key out of your application, [store it as a provider key](https://docs.promptguard.co/gateway/provider-keys.md) under `huggingface`. PromptGuard then sends the stored key and ignores the `Authorization` header you send.

## Auto-instrumentation

The SDKs do not patch `huggingface_hub`. Use the proxy.

## Next steps

> [card] [Provider keys](https://docs.promptguard.co/gateway/provider-keys.md)
>
> Store your provider credentials once, forwarded server-side

> [card] [Routing rules](https://docs.promptguard.co/gateway/routing-rules.md)
>
> Rewrite the upstream provider or model per request

> [card] [Integrations overview](https://docs.promptguard.co/integrations/overview.md)
>
> Every provider and framework, and how to connect each


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