Hugging Face API keys

25 community-sourced Hugging Face keys, re-checked against the API. Copy a key below, export it as HF_TOKEN, and send requests to https://api-inference.huggingface.co.

Keys

Using your Hugging Face key

Export the key as HF_TOKEN, then call the API at https://api-inference.huggingface.co.

export HF_TOKEN="your-key-here"

curl

curl https://api-inference.huggingface.co/chat/completions \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "meta-llama/Llama-4-Scout-17B-16E-Instruct",
    "messages": [{"role": "user", "content": "Say hello"}]
  }'

Python (OpenAI SDK)

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.environ["HF_TOKEN"],
    base_url="https://api-inference.huggingface.co",
)

resp = client.chat.completions.create(
    model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
    messages=[{"role": "user", "content": "Say hello"}],
)
print(resp.choices[0].message.content)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.HF_TOKEN,
  baseURL: "https://api-inference.huggingface.co",
});

const resp = await client.chat.completions.create({
  model: "meta-llama/Llama-4-Scout-17B-16E-Instruct",
  messages: [{ role: "user", content: "Say hello" }],
});
console.log(resp.choices[0].message.content);