Hugging Face api
★★★★★ 4.7 CE

Hugging Face API: Access, Rate Limits & SDKs 2026

Hugging Face's Inference Providers API is OpenAI-compatible with one HF token, routing across many open models and providers. Non-chat tasks use the native clients.

Hugging Face API verdict

Verified today·4 sources checked

Hugging Face's Inference Providers API authenticates with one fine-grained HF token.

Carrying the 'Make calls to Inference Providers' permission, and is OpenAI-compatible at https://router.huggingface.co/v1. You can reuse the OpenAI SDK by swapping the base URL, or use the native huggingface_hub Python and @huggingface/inference JS clients that cover all tasks.

How to build on it

Build on Inference Providers when you want one API and one token over many open models and providers. Keep your OpenAI SDK, point base_url at https://router.huggingface.co/v1 with an HF token, and call POST /v1/chat/completions with a model like openai/gpt-oss-120b:fastest to let HF pick the provider. For image, embeddings or speech, switch to the huggingface_hub or @huggingface/inference clients, which expose those tasks on the same token. Use :cheapest to optimize cost, pin a provider for consistency, and GET /v1/models to discover what is available and at what price. For teams, attribute spend with X-HF-Bill-To and set limits. The trade-off is that the OpenAI-compatible path is chat-only and quality is the underlying open model's. This is the right call when provider flexibility and open-model breadth matter more than a single vendor's proprietary frontier model.

Honest limits
  • The OpenAI-compatible endpoint handles chat completions only. For text-to-image, embeddings or speech, use the huggingface_hub or huggingface.js clients.
  • This is an access and routing layer, so model quality is the open model you choose, like gpt-oss, DeepSeek or Llama, not a Hugging Face proprietary model.
  • Per-token rates are the provider's, since HF adds no markup, and they vary by model and provider, so check GET /v1/models for live pricing rather than a single number.
  • Free monthly credits are small, from $0.10 to $2 a seat. Production workloads move to pay-as-you-go and should set org spend limits.
Auth
Bearer HF token (fine-grained)
Base URL
router.huggingface.co/v1
Compat
OpenAI SDK drop-in (chat)
Clients
huggingface_hub, huggingface.js
Models
200+ across 19 providers
View sources

Build with the Hugging Face API

Your first Hugging Face API request

POST /v1/chat/completions (OpenAI-compatible router)bash
curl https://router.huggingface.co/v1/chat/completions \
  -H "Authorization: Bearer $HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-oss-120b:fastest",
    "messages": [{"role": "user", "content": "How many G in huggingface?"}],
    "stream": false
  }'

How to authenticate with the Hugging Face API

AspectDetailNotes
AuthBearer HF token (fine-grained)Needs 'Make calls to Inference Providers' permission
Base URLhttps://router.huggingface.co/v1OpenAI-compatible chat completions endpoint
Python SDKhuggingface_hub (InferenceClient)pip install huggingface_hub; all tasks
JS/TS SDK@huggingface/inference (InferenceClient)npm install @huggingface/inference; TypeScript support
OpenAI compatOpenAI SDK with base_url swapChat completions only; minimal change
Provider selectionprovider="auto" (default) + :fastest/:cheapest/:preferredAppend suffix or pin model:provider
Models200+ open models, e.g. openai/gpt-oss-120b, DeepSeek-V3, FLUX19 partner providers

Core endpoints and tasks

CapabilityHowPurpose
Chat completionsPOST /v1/chat/completionsText generation, OpenAI-compatible (router or clients)
Model listingGET /v1/modelsModels across providers with pricing, context, latency, throughput
Text-to-imageclient.text_to_image(...)Diffusion image generation (e.g. FLUX.1) via clients
Feature extractionclient.feature_extraction(...)Embeddings for semantic search, RAG, recommendations
Text-to-video / speechclient text_to_video, speech tasksVideo generation and speech-to-text across capable providers
Function callingtools[] (guide)Tool use with the chat completion surface
Structured outputsJSON schema (guide)Schema-conforming JSON from LLMs
Responses APIResponses API (beta)OpenAI Responses-style surface, in beta

Credits, billing and rules

AspectDetailNotes
Free credits$0.10 free, $2.00 PRO, $2.00/seat Team/EnterpriseMonthly; subject to change
Pay-as-you-goProvider rates, no HF markupPurchase credits after free tier
Billing modesRouted by HF vs Custom Provider KeyCredits apply only to routed requests
Org billingX-HF-Bill-To: org-name or resource-group-idCentralize and attribute spend
Failoverprovider="auto" reroutes if a provider is downBuilt-in reliability
Chat-only compatOpenAI-compatible endpoint = chat completionsOther tasks via clients
hf-inference scopeMostly CPU / smaller models since July 2025Compute-time billing (time x hardware price)

SDKs, snippets and developer fit

AspectDetailNotes
SDKshuggingface_hub (Python), @huggingface/inference (JS/TS), OpenAI SDKPlus raw requests/fetch
Python tiershuggingface_hub, openai, or requestsHigh-level convenience to low-level control
Code snippetsView Code Snippets on any model pageGenerated Python / TypeScript
Playgroundhuggingface.co/playgroundTest models and providers before code
Token setupexport HF_TOKEN=...; hf auth loginRead token from env var
Free experimentationGenerous free tier + extra PRO/Team creditsGet started without paid setup
Org consolidationShared org credits + usage breakdownPer-model/provider usage in settings

Hugging Face API FAQ

How do I authenticate with the Hugging Face Inference Providers API?

Create a fine-grained Hugging Face token with the 'Make calls to Inference Providers' permission in your token settings, then send it as a bearer token, as export HF_TOKEN=.... The simplest path is the huggingface_hub InferenceClient in Python or @huggingface/inference in JS, which read the token automatically. Because the API is OpenAI-compatible at https://router.huggingface.co/v1, you can also use the OpenAI SDK by swapping its base URL and key.

Is the Hugging Face API OpenAI-compatible?

Yes, for chat completions. There is a drop-in OpenAI-compatible endpoint at https://router.huggingface.co/v1, so existing OpenAI chat code works by changing the base URL to the router and the key to your HF token. It handles provider selection on the server side, defaulting to :fastest. For non-chat tasks like text-to-image, embeddings or speech, you use the Hugging Face inference clients rather than the OpenAI-compatible endpoint.

What can the API do beyond chat completions?

Through the inference clients it covers text-to-image, such as FLUX.1, feature extraction for embeddings in search and RAG, text-to-video and speech-to-text, plus function calling, structured JSON outputs and a beta Responses API. GET /v1/models lists every available model across providers with per-provider pricing, context length, latency and throughput, so you can discover and compare options programmatically.

How do I control which provider serves my request?

By default provider='auto' selects the fastest available provider and fails over if one is unavailable. Append a policy suffix to the model id to change it: :cheapest for lowest output price or :preferred for your settings order. You can also pin a provider explicitly by appending its name, as in openai/gpt-oss-120b:sambanova. The official clients format the request for whichever provider is chosen, so your code stays the same.

How much does the API cost?

Hugging Face passes through the provider's rate with no markup, after small monthly credits, $0.10 free, $2 PRO or $2 a seat for Team and Enterprise. Past the free tier you purchase credits and pay as you go, and the built-in hf-inference provider bills by compute time, seconds times hardware price. Because per-token rates vary by model and provider, check GET /v1/models for live pricing, and use X-HF-Bill-To plus spend limits to control team costs.

Sources & verification

Verified by ComparEdgeMethod: Vendor docs, official pages, and selected independent sources
SourceWhat was checkedLast checked
Hugging Face OfficialOfficial product pageJuly 10, 2026
Hugging FaceInference ProvidersJuly 10, 2026
Hugging FacePricing and plansJuly 10, 2026
Hugging FaceInference Providers First API CallJuly 10, 2026

Every fact on this Hugging Face page is tied to a named source and a verification date. Freshness-sensitive figures trace to the sources above; verify against the vendor before relying on them.