Skip to the content.

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

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.