Hugging Face Visual Guide

Four end-to-end paths from the official HF docs — securing your account, building a Space, building & running models with auth and CLI, and network security — each in five steps.

1 Secure
2 Spaces
3 Models + CLI
4 Network / VPC
Heads-up before you start: the legacy huggingface-cli command has been removed (deprecated in v0.34, deleted in huggingface_hub v1.0). Everything below uses the new hf CLI. Install the latest client: pip install -U huggingface_hub.
🔐

1 · How to Secure your account & repos

Docs: hub/security · security-tokens · security-2fa · organizations-security
1

Know the three token types

Go to huggingface.co/settings/tokens. Choose fine-grained (scoped to specific repos/orgs — recommended for production), read (read-only on all private content), or write (read + write everywhere — use sparingly).

fine-grained → scoped repos onlyread → all private content, no writeswrite → everything
2

Create one scoped token per use

One token per app or machine, so a leak only invalidates one usage. Never paste raw tokens into commands (shell history); pass them via an environment variable. For CI/CD, prefer Trusted Publishers — OIDC identity, no stored secret.

# pass the token, never type it into history
export HF_TOKEN=hf_xxx   # then use --token $HF_TOKEN
3

Turn on two-factor authentication

Settings → hf.co/settings/authentication → "Add Two-Factor Authentication" with any TOTP app. You'll be prompted at login and every 30 days — download the recovery codes and store them safely.

4

Use private repos & org roles

Toggle repos private in their Settings tab (others get a 404; not searchable or clonable). Spaces get a third protected mode: code private, app public. In orgs, assign least-privilege roles.

no_access — nothingread — viewcontributor — own repos onlywrite — all reposadmin — everything
5

Have a leak plan

Revoke compromised tokens immediately at settings/tokens. Manage multiple credentials with the CLI, and rely on the Hub's automatic malware / pickle / hard-coded-secret scanning on every repo.

hf auth ls                 # list stored credentials
hf auth switch --token-name prod   # switch active token
hf auth logout --token-name old    # remove one
🚀

2 · How to Build a Space, end to end

Docs: hub/spaces-overview · spaces-config-reference · spaces-sdks-gradio · spaces-sdks-docker
1

Create the Space and pick an SDK

At huggingface.co/new-space choose a name, license, visibility and SDK: Gradio, Docker, static (or Streamlit via YAML). Or create from the CLI.

hf repos create my-demo --repo-type space --template gradio
On free personal accounts, Gradio/Docker Spaces on CPU Basic require PRO or a Team/Enterprise org — free accounts get up to 2 ZeroGPU Gradio Spaces. Static Spaces are free.
2

Write the README front matter (required)

The build is driven by YAML at the top of README.md. Required keys:

---
title:     My Demo
emoji:     🚀
colorFrom: blue        # red|yellow|green|blue|indigo|purple|pink|gray
colorTo:   purple
sdk:       gradio      # gradio | docker | static | streamlit
sdk_version: 5.0.0     # for gradio / streamlit
app_file:  app.py      # entry point (static: dist/index.html)
license:   mit
---
# Docker only:  app_port: 7860   (default 7860)
# Optional:     suggested_hardware, python_version, models, datasets
3

Write the app — use Secrets, not hard-coded keys

Add requirements.txt for Python SDKs (Spaces installs it). In Space Settings, Variables are public and copied on duplication; Secrets are write-only, never readable again. Both arrive as environment variables.

import os, gradio as gr
model_id = os.getenv("MODEL_REPO_ID")   # from Variables/Secrets
gr.Interface(fn=predict, inputs="text", outputs="text").launch()
hf spaces secrets add my-demo API_KEY "sk-..."   # set a secret via CLI
4

Choose hardware

Default is CPU Basic (2 vCPU / 16 GB). Upgrade in Settings → Hardware, or from Python — and downgrade back when done so you don't pay for idle GPUs.

from huggingface_hub import HfApi
api = HfApi()
api.request_space_hardware("you/my-demo", hardware="t4-medium")
api.get_space_runtime("you/my-demo").stage   # RUNNING / BUILDING / ...
5

Push code — every commit rebuilds

A Space is a git repo: push a commit and it auto-rebuilds and restarts. Egress is limited to ports 80 / 443 / 8080. Free hardware sleeps when idle; paused Spaces aren't billed.

git clone / edit
→
git push
→
auto build
→
app live on *.hf.space
git clone https://huggingface.co/spaces/you/my-demo
# edit app.py, then:
git add . && git commit -m "update app" && git push
🧠

3 · How to Build models & run them — with auth & the CLI

Docs: hub/models-the-doc · huggingface_hub quickstart · inference-providers
1

Authenticate with the hf CLI

The new CLI logs in via a browser device-code flow, or directly with a token. Verify who you are and what's stored.

hf auth login                    # interactive device-code flow
hf auth login --token $HF_TOKEN --add-to-git-credential  # for git push
hf auth whoami && hf auth ls
2

Create the model repo

hf repos create my-cool-model          # default repo type: model
# or from Python:
api.create_repo(repo_id="you/my-cool-model", private=True)
3

Save the model and push it

save_pretrained writes config.json + safetensors; the CLI uploads them. Upload auto-creates the repo if it doesn't exist.

# Python — save locally
model.save_pretrained("./my-cool-model-dir")
tokenizer.save_pretrained("./my-cool-model-dir")
# CLI — push
hf upload you/my-cool-model ./my-cool-model-dir .
hf upload you/my-cool-model model.safetensors /sub/dir/model.safetensors
4

Download & run with auth

Pass the token explicitly (from the environment, never hard-coded) and the model runs anywhere your token has access to.

import os
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(
    "you/my-cool-model",
    token=os.environ["HF_TOKEN"],
)
# or just download files first:
hf download you/my-cool-model --local-dir ./dir
5

Serve it — Inference Providers

Run hosted inference through the InferenceClient without managing any server. The provider picks the route (auto, hf-inference, together, groq, fal-ai, …).

from huggingface_hub import InferenceClient

client = InferenceClient(provider="auto", api_key=os.environ["HF_TOKEN"])
image  = client.text_to_image("Astronaut riding a horse",
                              model="black-forest-labs/FLUX.1-schnell")
🌐

4 · How to Build a secure network around your deployment

Docs: inference-endpoints security & configuration · private_link · hub/security
1

Start from the encrypted baseline

All Inference Endpoints use TLS in transit; HF stores no customer payloads or tokens; logs are kept 30 days. Hub and Inference Endpoints are SOC 2 Type 2 certified, with a GDPR DPA available via Enterprise.

2

Lock down the endpoint itself

Point endpoints at private model repos and configure endpoint authentication (Hub tokens or custom auth) in the endpoint's configuration page — so only callers you authorize can reach the model.

3

Keep traffic inside your VPC — AWS PrivateLink

In the endpoint configuration → Network, enable AWS PrivateLink and enter the AWS Account ID that owns your VPC. Traffic never crosses the public internet; you see only the ENI in your VPC.

your VPC
⇄
PrivateLink ENI
⇄
Inference Endpoint
public internet — bypassed ✕
api.create_inference_endpoint(
    "my-endpoint", model="meta-llama/Llama-3.1-8B-Instruct", ...,
    private_link_account_id="123456789012",
    private_link_region="us-east-1",
)
4

Match the Spaces to the policy

Private Spaces: code + app visible only to owner/collaborators — others get a 404, no embed URL. Protected: code private, app public at *.hf.space. Pick per app, never all-public by default.

5

Harden the Hub side

Automatic malware / pickle / secret scanning on every repo, GPG-signed commits, SSH-based git auth, org SSO, and Resource Groups for fine-grained repo access control in Team/Enterprise plans.

🔍 auto-scan on push✍️ GPG commit signing🔑 SSH git auth🏢 SSO + Resource Groups