API Directory › 🤖 AI & Machine Learning › Hugging Face Inference
API KeyHTTPSCORS

Hugging Face Inference API

Run thousands of open-source ML models (text, image, audio) via a hosted API.

Auth
API Key
HTTPS
Yes
CORS
Yes
Open Hugging Face Inference docs ↗

What it does

Hugging Face lets you call thousands of open models over HTTP without hosting them yourself — text generation, embeddings, image generation, speech-to-text, classification and more. The serverless Inference API runs smaller models on shared infrastructure; Inference Providers route larger models to partner GPUs through one OpenAI-compatible endpoint.

Base URL

https://api-inference.huggingface.co/models/{model_id}

Authentication

Create a free account and a read token (hf_…) under Settings → Access Tokens. Send it as Authorization: Bearer hf_…. The free tier includes a small monthly inference credit; a PRO plan and pay-as-you-go raise it.

Code examples

curl
curl https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2 \
  -H "Authorization: Bearer $HF_TOKEN" \
  -d '{"inputs":"Larz OS free API directory"}'
Python
import requests

API = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
r = requests.post(API,
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={"inputs": long_article, "parameters": {"max_length": 130}},
    timeout=60)
print(r.json()[0]["summary_text"])

Rate limits & quotas

The free tier is metered in monthly credits rather than a fixed request rate; heavy or large-model use exhausts it quickly and then returns HTTP 402. Cold models return HTTP 503 with an estimated_time field while they load — retry after that many seconds, or send x-wait-for-model: true to block until ready.

Key response fields

[0].generated_textOutput for text-generation models
[0].summary_textOutput for summarisation models
[0].label / [0].scoreTop class and confidence for classifiers
(raw bytes)Image and audio models return the media directly, not JSON
estimated_timeSeconds until a cold model is ready (on 503)

Common errors

401Missing or invalid token.
402Monthly free inference credit exhausted — upgrade or wait for reset.
503Model is loading; wait estimated_time seconds and retry.
400Input shape does not match the model’s expected payload.

When to use it (and alternatives)

Best when you want open-weight models, many task types, or a specific community model. For a polished single-vendor chat/embeddings/image stack use the OpenAI API; for running heavier open models billed by the second try Replicate.

FAQ

Is the Hugging Face Inference API free?

There is a free monthly inference allowance that is fine for prototyping and light use. Sustained or large-model traffic needs PRO or pay-as-you-go billing.

Why does my first request take 20+ seconds?

Serverless models are loaded on demand. The first call after a period of inactivity pays a cold-start; subsequent calls are fast until it scales back down.

How do I call a large chat model?

Use Inference Providers via the OpenAI-compatible router endpoint (https://router.huggingface.co/v1) with the same token — it works with the OpenAI SDK by just changing the base URL.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

Prompt ImproverLearn Prompt Engineering

Related AI & Machine Learning APIs

← Back

More AI & Machine Learning APIs · All 196 APIs