Working with Hugging Face
CodeScoring.Save implements the HTTP API of the Hugging Face Hub that the huggingface_hub library and the hf CLI work with: the client only needs the Save repository URL in the HF_ENDPOINT variable. One repository type is supported:
- a proxy repository — a caching proxy in front of
huggingface.co. Models, datasets, and spaces are downloaded through Save and stay in its cache.
Hosted and group repositories are not supported for Hugging Face: a model cannot be published to Save with hf upload. For the full list, see Limitations.
Creating a Repository in the Web Interface
-
In the sidebar, choose Projects and open the project.
-
Click Create repository.
-
Fill in the common fields Name, Key, Description, and Color — the same way as for other formats (see Repository management).
-
In the Format field, choose Hugging Face.
-
The Type field offers only Proxy — it is selected automatically.
-
Fill in the proxy repository fields:
-
Proxy URL — the Hub URL:
https://huggingface.co. Save accepts only URLs from the list of allowed hosts. By default, these arehuggingface.coandhf.co; to connect a Hub mirror, the administrator adds its host to a backend environment variable, listing every allowed host:HF_PROXY_ALLOWED_UPSTREAM_HOSTS=huggingface.co,hf.co,hf-mirror.example.com. Save rejects a URL outside the list with the Failed to create a repository notification. -
Cache TTL, seconds — how many seconds Save treats the Hub's answer about a branch or a tag (for example, which commit
mainpoints to) as current before checking it again. The default is3600(one hour). The value does not affect files: a file of a specific commit never changes and stays in the cache until it is deleted. -
Authentication — how Save authenticates to the Hub:
In the Token field, enter a Hugging Face access token (
hf_...); read permission is enough. Once saved, the token is never shown in the UI or returned by the API: on the edit form, a stored value appears as********— leave it as is to keep it. For details, see Upstream access for proxy repositories.
-
-
Optionally attach Cleanup policy and click Create repository.
If the name you enter in the Name field contains the word huggingface (for example, huggingface proxy), the link under the field fills in Format, Type, and Proxy URL for you.
On the page of the created repository, the chain-link icon button opens Useful snippets — ready-made commands for this particular repository: Configure the client, Download a model, Whole repository / dataset, and From Python.
The same can be done with an API request. Set format to huggingface and pass the Hugging Face token in the auth block:
For public Hub repositories, the auth block is not needed. A request with "repository_type": "hosted" returns 400.
- A file is cached on the first download: Save serves it to the client while fetching it from upstream, and stores it after the client has received the last byte. A large file therefore appears in the repository tree some time after the download finishes.
- The client gets every response from Save. There are no redirects to the Hugging Face CDN: Save downloads large (LFS) files from the CDN itself. Save therefore needs outbound access not only to
huggingface.cobut also to the CDN hosts the Hub redirects to (for example,cdn-lfs.huggingface.coandcas-bridge.xethub.hf.co; the list is defined by Hugging Face). - The Save token the client came with is not passed to upstream. Only the token from the repository's Token field goes to the Hub.
- Save verifies a downloaded file against the checksum declared by the Hub. A mismatch is treated as an upstream error (
upstream_checksum_mismatch). - Identical content is stored once: if a file did not change between commits, or lives in a Hub repository under two names, a single copy takes up storage space.
- The Xet protocol is not supported. A client with
hf_xetinstalled automatically falls back to a regular HTTP download — the file content is the same.
URL Scheme
All paths below are relative to the repository URL https://save.example.com/cs-save/hf/<project>/<repository> — this is the value of HF_ENDPOINT:
Here <repo_id> is the Hub repository identifier (google-bert/bert-base-uncased), <type> is models, datasets, or spaces, and <revision> is a branch, a tag, or a commit hash. If a revision name contains / (for example, refs/pr/1), it is encoded as %2F in the URL; the client does this itself.
Save answers a file request itself, without a redirect: 200 or 206, and the X-Repo-Commit, ETag, and Content-Length headers are always present. Resuming a download is supported: a single range in the Range header (bytes=N-, bytes=N-M, or bytes=-N). HEAD returns the same headers and does not start a download from upstream.
Any other Hub operation (file uploads, commits, Xet tokens, search) returns 404 with the X-Error-Code: EntryNotFound header.
Connecting the Client
The repository URL has the form https://save.example.com/cs-save/hf/<project>/<repository>. Set it in the HF_ENDPOINT variable without a trailing slash, and put a Save token in HF_TOKEN:
HF_TOKEN is a Save token, not a Hugging Face one. The client sends it in the Authorization: Bearer header. The following work:
- a robot account API key — for CI/CD and long downloads;
- a user's session access token — returned by
POST /api/v1/auth/login; by default, it is valid for 15 minutes.
The account needs the artifacts.download permission on the repository. To check that the client is connected and the token is accepted, run hf auth whoami: it shows the name of the Save account.
The huggingface_hub library and the tools built on it (for example, transformers) read the same variables. The variables are read when the library is imported, so set them before starting Python.
Create a robot account with the artifacts.download permission and pass its API key in HF_TOKEN — without the login and the sa$ prefix:
For details on robot accounts, see Authentication.
If anonymous read is enabled, HF_TOKEN can be omitted. Keep in mind: without HF_TOKEN, the client sends Save the Hugging Face token if one is stored on the machine by hf auth login. With anonymous read enabled, Save serves such a request as anonymous; with it disabled, Save responds with 401. The HF_TOKEN value takes precedence over the stored token.
Use an up-to-date version of huggingface_hub: pip install -U huggingface_hub. In version 0.28.0, the client dropped the path from HF_ENDPOINT and sent requests to the host root — the bug is fixed in 0.28.1. Older versions use the huggingface-cli command instead of hf.
Downloading Models, Datasets, and Spaces
From then on, the client works as usual:
The same from Python:
Branches and tags on the Hub can be rewritten, while a commit is immutable. To make a build always get the same files, specify the commit hash:
Gated and Private Hub Repositories
Hugging Face grants access to gated models to a specific account after the terms on the model page are accepted. To download such models through Save:
- Get access to the model on
huggingface.coand create an access token for that account. - Open the repository in Save and click the pencil button (Edit repository) in the header.
- In the Authentication field, choose
bearer, enter the token in the Token field, and click Save.
Without a token, or with the token of an account that has not been granted access, the client reports that the repository is gated. Save returns the Hub's response unchanged: the 401 or 403 status, the X-Error-Code: GatedRepo header, and a message marked upstream:. Private Hub repositories are connected the same way.
Save accesses the Hub on behalf of a single account — the one whose token is set in the repository. Everything available to that account can be downloaded by every Save user with the artifacts.download permission on the repository. If access to gated models must be restricted, create a separate proxy repository for them and grant permissions on it alone.
Browsing and Cleaning Up the Cache
Downloaded files are visible in the tree on the repository page. Every file is a separate artifact tied to the Hub repository and the commit it was downloaded from: the same file from two commits is two artifacts. Search, sorting, details, and actions on artifacts work the same way as for other formats (see Repository management).
A file can be deleted from the cache. There are two ways:
- tick the checkbox to the left of the artifact in the repository tree and click Delete in the panel that appears above the tree. This way you can delete several files at once;
- click the artifact in the repository tree and, in the right pane, choose Delete artifact in the three-dot menu (next to Download).
On the next request, Save downloads the deleted file from upstream again.
Models take up tens of gigabytes, so it is worth attaching a cleanup policy to the repository. The artifact version is the commit: the keep-latest-versions policy with the value 1 keeps, for every Hub repository, the files of the commit that was downloaded through Save last. A model, a dataset, and a space with the same name are counted separately.
Working When Upstream Is Unavailable
If huggingface.co is unavailable, Save keeps serving what is already in the cache:
- files and whole models that were downloaded through this repository before — including to clients with an empty local cache;
- information about a branch or a tag — from the cache during Cache TTL, and after it expires, the last known answer until upstream is back;
- the "no such file" answer: if the Hub has already reported that a commit does not have the requested file, Save returns
404withX-Error-Code: EntryNotFound. Clients request the optional files of a model on every load, and such probes do not turn into errors.
A file that has not been requested through Save yet cannot be downloaded: Save responds with 502 or 504. For offline environments, download the required models and revisions through Save in advance.
Limitations
- Proxy repositories only. Publishing (
hf upload, commits, creating Hub repositories) is not supported: such requests return404. - Group repositories are not available for the format.
- The Xet protocol is not supported; the client uses HTTP.
- The git protocol is not supported:
git clonewith the Save repository URL does not work. - Hub search, organization lists, and commit history are not available through Save.
Repository URL Migration
Use case: migrating a Hugging Face proxy from Nexus / Artifactory to CodeScoring.Save.
In HF_TOKEN, replace the former token with a Save token. If the credentials were passed in the URL itself (https://<user>:<password>@nexus.host.ru/...), remove them from HF_ENDPOINT. The HF_HUB_DISABLE_XET=1 variable, if it was set, is not required for Save.
Troubleshooting
Which Requests the Client Makes
Run the client with the HF_DEBUG variable — it prints every request as a curl command:
All requests must go to the Save URL. If the client accesses huggingface.co, check that HF_ENDPOINT is set in the same environment the client runs in and that the huggingface_hub version is not 0.28.0. If there are no requests at all, check whether offline mode HF_HUB_OFFLINE=1 is enabled.
Checking Access and File Metadata
The response to the second request must contain the X-Repo-Commit, ETag, and Content-Length headers.
Response Codes
The cause of an error is given in the X-Error-Code and X-Error-Message headers — these are what the client shows — and in the error field of the response body. A message marked upstream: means the refusal came from the Hub, not from Save.
A File Is Downloaded but Missing from the Repository Tree
- The client does not download a file again if it is already in its local cache (
~/.cache/huggingface): only what the client actually downloaded through Save gets into it. Repeat the download with an empty cache by setting another directory inHF_HOME. - A large file appears in the tree after Save finishes storing it. Refresh the page later.
