Skip to content
C.W.K.
Lesson 04 of 04 · published

Secrets, Hardware Tiers, and Storage Buckets

~24 min · spaces, ops, secrets

Level 0Scout
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Secrets are environment variables

The Space settings page has a "Secrets" panel. Anything you put there is exposed as an environment variable in the running container — available via os.environ['HF_TOKEN'], os.environ['OPENAI_API_KEY'], etc. They're encrypted at rest, masked in logs, and never appear in the repo.

Hardware tiers

TierHardwareUse case
CPU Basic (free)2 vCPU, 16GB RAMDemos, small Transformers, classical ML.
CPU Upgrade8 vCPU, 32GB RAMBigger CPU workloads.
T4 small1 T4 (16GB)1-3B inference, simple Stable Diffusion.
A10G1 A10 (24GB)7B inference, SDXL, Whisper-large.
A100 large1 A100 (80GB)30-70B inference (with quantization), training jobs. H100 tiers were removed in December 2025.

A Space's disk is not persistent

The default disk is wiped when the Space restarts or rebuilds. Data that must last, such as user uploads, fine-tune outputs and runtime caches, goes in a Storage Bucket attached to the Space as a volume; buckets have replaced the old paid Persistent Storage. A bucket mounts at the path you choose (e.g. /data) and outlives the Space.

Code

Use a secret in app code·python
import os
from huggingface_hub import InferenceClient

# 'HF_TOKEN' set in Space settings → Secrets
client = InferenceClient(token=os.environ["HF_TOKEN"])
Suggested hardware in the manifest·yaml
---
title: My Big Demo
sdk: docker
app_port: 7860
suggested_hardware: a10g-small  # a suggestion only; pick the actual hardware in Space settings
---

External links

Exercise

Add a secret to one of your Spaces and verify it works in code. Upgrade a Space to T4 or A10G hardware (briefly — paid). Then create a Storage Bucket, attach it to the Space at /data, and write a small file there standing in for a user upload. Restart the Space and verify the file survives.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign in — Please sign in to comment.

No comments yet — be the first.