Hugging Face Hub
Download models and datasets through the proxy’s Hub upstream. The examples use
the upstream name huggingface; replace it with the name your operator gave
the upstream (what you need).
| Upstream type | huggingface |
| Package source | https://proxy.example.com/v1/huggingface |
| Clients | huggingface_hub (and what builds on it: transformers, datasets, the hf CLI) |
| Tested | huggingface_hub 2.4: in CI on every push and in the client lab. |
Configure
One environment variable replaces huggingface.co for every library built on
huggingface_hub:
export HF_ENDPOINT=https://proxy.example.com/v1/huggingface
hf download hf-internal-testing/tiny-random-bert vocab.txt --revision f171d7baecaf37b5da5a3616d8833b9969753535
Authenticate
Only when the proxy has access control switched on. The client’s own token variable carries your proxy token — not a Hub token. The proxy holds the Hub token (for gated and private repositories) itself and never forwards yours.
export HF_TOKEN="<token>"
Trust a private CA
export SSL_CERT_FILE=/etc/ssl/corp-ca.pem REQUESTS_CA_BUNDLE=/etc/ssl/corp-ca.pem
Current releases read SSL_CERT_FILE; releases built on the requests library
read REQUESTS_CA_BUNDLE.
Check that it works
The hf download command above prints the path of the downloaded file in the
local cache (HF_HOME).
Good to know
- Pin a commit. A download at a 40-character commit hash (
--revision,revision=) is immutable: the proxy caches it and serves it without asking the Hub again. At a branch or tag (main), configuration and tokenizer files are looked up at the Hub every time — but weight files are cached under the branch name (.safetensors,.bin,.pt,.gguf,.onnxand the like; every weight download goes through the proxy’s content checks, which run on what it caches). A push to the branch is therefore not seen for a weight file the proxy already holds. Pin the commit to know what you get. - Pickle weights are inspected.
.bin,.pt,.pkl,.ckptfiles pass the proxy’s weight scan before they are served, and a file that would execute code on load is a403. Prefersafetensors. - Large files are streamed and verified against the SHA-256 the Hub declares; the proxy follows the Hub’s CDN redirects itself.
-
The
hfcommand checks pypi.org for a newer release of itself — not a request the Hub upstream sees, and the one host besides the proxy the lab saw it look up. The library does not. To switch the check off:export HF_HUB_DISABLE_UPDATE_CHECK=1 - Uploading does not go through the proxy (
hf upload,push_to_hub).
On the proxy
upstreams:
huggingface:
type: huggingface
url: https://huggingface.co
Commit-pinned files are cached immutably and verified against the Hub’s
X-Linked-Etag SHA-256; the headers the client needs to identify a file are
stored with it and replayed on a cache hit. Details:
backends: huggingface.