Machine Learning

How to Use Hugging Face: Hub, APIs, and Free GPU Apps

The short answer (August 2026): Hugging Face is the central platform for open AI, hosting over 2 million model checkpoints, 500,000+ datasets, and 1 million+ interactive demo apps called Spaces. You can test any public model in your browser with no setup, call models programmatically through a single token that routes to 18 inference compute partners, or download and run models locally using the transformers Python library. A free account covers most experimentation including five minutes of daily GPU time through ZeroGPU; the PRO plan is $9/month; Team and Enterprise organization plans start at $20 and $50 per user per month respectively, with compute metered separately on top of all plans.

Last verified: August 31, 2026, against official docs and pricing pages.

What Hugging Face Is

Hugging Face is a platform, a community, and a library ecosystem. The central piece is the Hub at huggingface.co: a Git-based repository host designed for AI artifacts. Every model, dataset, and Space is a version-controlled repo with commit history, branches, pull requests, and discussion threads. Repositories use Xet, a large-file storage layer that deduplicates chunks across uploads and speeds transfers.

The platform is model-family-neutral. You will find checkpoints from Meta, Google, Microsoft, Mistral, DeepSeek, EleutherAI, and thousands of independent contributors. Licenses vary: many popular models are Apache 2.0 and usable commercially; others restrict commercial use or require you to submit an access request and agree to terms before downloading.

Three interconnected systems make up the platform:

  • The Hub: version-controlled repositories for models, datasets, and Spaces, each with browser viewers and live inference widgets
  • Inference Providers: a serverless API router that sends your request to one of 18 compute partners (Groq, Together AI, Cerebras, Replicate, fal.ai, and others) using a single Hugging Face token
  • The transformers library: a Python library with 164,000-plus GitHub stars for loading any Hub model and running it on your own hardware

Set Up Your Account and Get a Token

Create a free account at huggingface.co. No credit card is required. Once logged in, go to Settings > Access Tokens to create an API token.

For Inference Providers (the serverless API), generate a fine-grained token with the "Make calls to Inference Providers" permission enabled. For uploading models or reading private repositories, a standard read/write token works.

To authenticate from your terminal, install the CLI and log in:

macOS / Linux standalone installer (recommended)

curl -LsSf https://hf.co/cli/install.sh | bash

or via pip

pip install huggingface_hub
hf auth login

hf auth login prompts for your token and stores it at ~/.cache/huggingface/token. After that, all HF libraries read from this cache automatically. For CI/CD and Docker environments, set the HF_TOKEN environment variable directly instead of using the login command.

Find and Test Models Without Writing Code

The model browser at huggingface.co/models lets you filter by task, library, language, dataset, and license. Common task filters:

  • text-generation for large language models
  • automatic-speech-recognition for transcription (Whisper and its variants)
  • text-to-image for diffusion models
  • feature-extraction for embedding models used in search and RAG

Every model page includes a Model Card covering intended use, known limitations, training data, and evaluation results. Below the card is a live inference widget backed by Inference Providers: type a prompt and get a response directly on the page with no code.

For comparing chat models side-by-side, the Inference Playground at huggingface.co/playground lets you run the same prompt through multiple models simultaneously.

Gated models (Llama, Gemma, and others) show an access-request button at the top of the model page. You must submit a request and agree to the license terms before downloading weights or calling the model via API. Approval is typically automated and near-instant for most Llama variants.

Call Any Model from Your Code

Inference Providers gives you a single API that routes to 18 compute partners with no markup on provider rates. The base URL https://router.huggingface.co/v1 is OpenAI-compatible for chat completions, so you can use the OpenAI Python or JavaScript SDK by changing one line.

Install the Hugging Face Hub client:

pip install huggingface_hub

Call a language model using the native client:

from huggingface_hub import InferenceClient
import os

client = InferenceClient(token=os.environ["HF_TOKEN"])

completion = client.chat.completions.create(
model="openai/gpt-oss-120b", # append :fastest, :cheapest, or :preferred
messages=[{"role": "user", "content": "Explain backpropagation in two sentences."}],
)
print(completion.choices[0].message.content)

If you already use the OpenAI Python client, swap the base URL:

from openai import OpenAI
import os

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

Provider selection is controlled by a suffix on the model ID. :fastest (default) picks the provider with the highest throughput for that model. :cheapest minimizes cost per output token. You can pin a specific provider by name, for example "openai/gpt-oss-120b:groq".

The OpenAI-compatible endpoint covers chat completions only. For image generation, embeddings, and speech recognition, use InferenceClient method names directly:

image = client.text_to_image(
prompt="A mountain lake at dawn, photorealistic",
model="black-forest-labs/FLUX.1-dev"
)
image.save("output.png")

Run Models Locally with the Transformers Library

For offline use, fine-tuning, or when you need full control over the inference stack, download and run models locally with transformers.

Install the core libraries:

pip install -U transformers datasets evaluate accelerate timm

The pipeline() function is the fastest path to local inference. It downloads and caches model weights from the Hub on first call:

from transformers import pipeline
from accelerate import Accelerator

device = Accelerator().device # auto-selects CUDA, Apple MPS, or CPU

Text generation

gen = pipeline("text-generation", model="meta-llama/Llama-2-7b-hf", device=device)
print(gen("The transistor was invented in", max_length=60))

Automatic speech recognition

asr = pipeline("automatic-speech-recognition", model="openai/whisper-large-v3", device=device)
print(asr("interview.flac"))

For finer control, use AutoModel and AutoTokenizer directly:

from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-2-7b-hf",
dtype="auto", # loads in the checkpoint's stored precision
device_map="auto", # allocates layers to the fastest device first
)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")

dtype="auto" matters: without it, PyTorch defaults to float32, doubling the VRAM needed for a model stored in bfloat16. device_map="auto" handles multi-GPU setups and GPU-to-CPU weight offloading automatically.

Cached model weights live at ~/.cache/huggingface/hub by default. Set the HF_HOME environment variable to move the cache to a different disk.

For teams building on top of transformers, see the AI Weekly guide to AI coding assistants for context on how these libraries fit into wider development workflows.

Build and Host a Demo App with Spaces

Spaces are the Hub's hosted web-app layer. You push a Gradio or Streamlit app to a Space repository, and Hugging Face serves it over HTTPS with a public URL. Free accounts get a shared CPU (2 vCPU / 16 GB RAM) at no cost.

ZeroGPU is the free-tier GPU option. It dynamically allocates NVIDIA RTX Pro 6000 Blackwell GPUs only while a user is actively running inference, then releases the GPU immediately. You pay nothing for idle time.

ZeroGPU comes in two sizes: large (half the GPU, 48 GB VRAM) and xlarge (full GPU, 96 GB VRAM). The xlarge size consumes 2x your daily quota.

To use ZeroGPU in a Gradio Space:

import spaces
import gradio as gr
from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev")
pipe.to("cuda") # placed on CUDA at startup; GPU is obtained per request only

@spaces.GPU
def generate(prompt):
return pipe(prompt).images[0]

gr.Interface(fn=generate, inputs=gr.Text(), outputs=gr.Image()).launch()

The @spaces.GPU decorator requests a GPU when the function is called and releases it on return. Load models onto CUDA at the module level (outside the decorated function): lazy-loading inside the decorator is significantly slower because CUDA transfers optimized at startup are bypassed.

ZeroGPU works with Gradio Spaces only. Docker and Streamlit Spaces require a rented hardware tier. Free accounts can host up to 2 ZeroGPU Spaces; PRO accounts up to 10; organization accounts (Team or Enterprise) up to 50.

When your daily ZeroGPU quota runs out, additional GPU time costs $1 per 10 minutes, billed from a pre-funded credit balance you can add in billing settings.

For continuously running, private GPU endpoints (production APIs, dedicated model servers), Inference Endpoints deploy any Hub model on reserved managed hardware billed by the hour.

What Things Actually Cost

The seat plan and the compute bill are separate. The monthly subscription buys features and usage quotas; actual inference and GPU time are metered on top.

Plan Price ZeroGPU daily quota ZeroGPU Spaces (hosted) Best for
Free $0 5 minutes 2 Learning and experimentation
PRO $9/month 40 minutes (extensible) 10 Individual practitioners and power users
Team $20/user/month 40 minutes (extensible) 50 org-wide Teams needing SSO, audit logs, and access controls
Enterprise $50/user/month 60 minutes (extensible) 50 org-wide Organizations needing compliance, SCIM provisioning, and dedicated support

Compute costs are billed on top of any subscription plan. Key rates from the official pricing page:

  • ZeroGPU overage: $1 per 10 minutes after daily quota is exhausted
  • Dedicated Spaces GPU hardware: T4 small at $0.40/hour, A100 (80 GB) at $2.50/hour
  • Inference Endpoints (dedicated model servers): T4 at $0.50/hour, H100 at $4.50/hour, H200 (141 GB) at $5.00/hour, B200 (179 GB) at $9.25/hour
  • Hub storage: $12/TB/month for public repos, $18/TB/month for private repos at base volume; bulk discounts apply above 50 TB and 200 TB

For short experiments and irregular traffic, Inference Providers (serverless) is nearly always cheaper than a dedicated endpoint. Dedicated endpoints make sense when you need guaranteed latency, need to run a private or fine-tuned model, or have traffic consistent enough that per-hour billing beats per-request rates.

FAQ

Do I need a GPU to use Hugging Face?
For browser-based testing and Inference Providers API calls, no: the compute runs on partner infrastructure. For local inference with transformers, a CPU works for small models, but generation will be slow. A CUDA GPU is recommended for any model above a few billion parameters. Apple Silicon (M-series) is supported via the MPS backend and runs mid-size models at reasonable speed.

What is the difference between Inference Providers and Inference Endpoints?
Inference Providers is serverless and shared: you call a model through the router, requests are load-balanced across available compute, and you pay per request (or draw from free-tier credits). Inference Endpoints deploys a dedicated, always-on container running your chosen model on reserved hardware, billed by the hour. Providers suits experimentation and variable workloads; Endpoints suits production use cases where you need guaranteed latency, consistent throughput, or a private/fine-tuned model that you cannot expose through the shared router.

Can I use Hugging Face models in commercial products?
It depends on the individual model license, not on your Hugging Face plan. Check the Model Card's license field before shipping anything. Apache 2.0 models are generally usable commercially with attribution. Models under the Llama 3 Community License or Gemma Terms of Use have commercial restrictions tied to user counts or use-case categories. Research-only models prohibit commercial use entirely. The Hub's license filter at huggingface.co/models lets you search by specific license type.

How do I download a model to run it offline?
Use the CLI: hf download meta-llama/Llama-2-7b-hf downloads the checkpoint to your local cache. In Python, calling from_pretrained() triggers the same download automatically. After downloading, set HF_HUB_OFFLINE=1 as an environment variable to prevent any network calls during inference. Cached files live at ~/.cache/huggingface/hub unless you have set HF_HOME.

What is a Model Card and why does it matter before deploying?
A Model Card is the documentation file that ships with every Hub model. It covers intended use, out-of-scope uses, known biases, training dataset details, and evaluation benchmarks. For any team with responsible AI requirements or regulatory obligations, the Model Card is the primary artifact for auditing a third-party model before putting it in production. Models without complete cards should be treated as under-documented, regardless of their benchmark scores.

Stay current on what is shipping across the AI stack. Get AI Weekly free, 3 issues a week, read by 40,000+ practitioners.