Skip to content

replace hf_xxxxxxxxxxxx by process.env.HF_TOKEN in examples #1764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/inference-providers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ curl https://router.huggingface.co/novita/v3/openai/chat/completions \
In Python, you can use the `requests` library to make raw requests to the API:

```python
import os
import requests

API_URL = "https://router.huggingface.co/novita/v3/openai/chat/completions"
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"}
payload = {
"messages": [
{
Expand All @@ -116,11 +117,12 @@ print(response.json()["choices"][0]["message"])
For convenience, the Python library `huggingface_hub` provides an [`InferenceClient`](https://huggingface.co/docs/huggingface_hub/guides/inference) that handles inference for you. Make sure to install it with `pip install huggingface_hub`.

```python
import os
from huggingface_hub import InferenceClient

client = InferenceClient(
provider="novita",
api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxx",
api_key=os.environ["HF_TOKEN"],
)

completion = client.chat.completions.create(
Expand Down Expand Up @@ -149,7 +151,7 @@ const response = await fetch(
{
method: "POST",
headers: {
Authorization: `Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`,
Authorization: `Bearer ${process.env.HF_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
Expand All @@ -173,7 +175,7 @@ For convenience, the JS library `@huggingface/inference` provides an [`Inference
```js
import { InferenceClient } from "@huggingface/inference";

const client = new InferenceClient("hf_xxxxxxxxxxxxxxxxxxxxxxxx");
const client = new InferenceClient(process.env.HF_TOKEN);

const chatCompletion = await client.chatCompletion({
provider: "novita",
Expand Down