Command Palette

Search for a command to run...

HuggingFace Compatibility

Foundry is compatible with the HuggingFace Hub API, allowing you to leverage existing ML workflows with minimal changes. By changing a single environment variable, the huggingface_hub library, Transformers, and Datasets libraries will use Foundry as their endpoint.

Quick Switch

import os
os.environ["HF_ENDPOINT"] = "https://your-foundry-instance.example.com"

# All subsequent code works with Foundry without modification
from huggingface_hub import hf_hub_download, login
from transformers import AutoModel, AutoTokenizer
from datasets import load_dataset

# Login (using your Foundry access token)
login(token="your_foundry_access_token")

# Download a file
model_path = hf_hub_download(repo_id="org/model-name", filename="model.safetensors")

# Load a model
model = AutoModel.from_pretrained("org/model-name")
tokenizer = AutoTokenizer.from_pretrained("org/model-name")

# Load a dataset
dataset = load_dataset("org/dataset-name")

Compatible API Endpoints

File Download (resolve)

GET /datasets/{owner}/{repo}/resolve/{ref}/{path}
GET /spaces/{owner}/{repo}/resolve/{ref}/{path}
GET /api/models/{owner}/{repo}/resolve/{ref}/{path}
  • Range requests and the HEAD method are supported
  • LFS files are redirected via Presigned URLs

Git LFS Batch API

POST /datasets/{owner}/{repo}.git/info/lfs/objects/batch
POST /spaces/{owner}/{repo}.git/info/lfs/objects/batch

Git LFS batch API for upload/download negotiation.

User Information

GET /api/whoami-v2

Returns HF-compatible user information (including organization list, in camelCase format).

Repository Metadata

HF-compatible repository metadata is provided through the Repository API:

EndpointDescription
/api/{type}/{owner}/{repo}/refsList branches and tags
/api/{type}/{owner}/{repo}/tree/{ref}Retrieve file tree
/api/{type}/{owner}/{repo}/commit/{revision}Commit information

Response format uses the same camelCase as HF Hub (lastModified, modelId, createdAt, etc.).

HF Import API

API for importing repositories from HuggingFace Hub into Foundry.

HF Access Token Management

Store Token:

PUT /api/auth/huggingface
Content-Type: application/json

{"token": "hf_xxxxxxxxxxxxxxxxxxxxxxxx"}

Retrieve Token:

GET /api/auth/huggingface

Response:

{
  "success": true,
  "data": {
    "has_token": true,
    "preview": "hf_xxx...xxxx"
  }
}

The raw token is never returned; the preview is formatted as the first 6 characters + ... + the last 4 characters.

Delete Token:

DELETE /api/auth/huggingface
GET /api/huggingface/search?q={query}&type={type}&limit={limit}
ParameterTypeRequiredDescription
qstringSearch query
typestringOne of model, dataset, space
limitnumber-Maximum number of results (default 10, max 50)

Example response:

{
  "success": true,
  "data": {
    "items": [
      {
        "id": "meta-llama/Llama-2-7b",
        "type": "model",
        "author": "meta-llama",
        "name": "Llama-2-7b",
        "downloads": 123456,
        "likes": 789,
        "tags": ["pytorch", "transformers", "text-generation"],
        "private": false
      }
    ],
    "total": 1
  }
}

HF Repository Validation

GET /api/huggingface/validate?repo_id={repo_id}&type={type}

Returns whether the repository can be imported, along with metadata such as the file list and total size.

Create Repository via Import

POST /api/repos/create
Content-Type: application/json

{
  "repo_id": "myuser/my-imported-model",
  "repo_type": "model",
  "private": false,
  "from_huggingface": {
    "repo_id": "meta-llama/Llama-2-7b"
  }
}

Response (201 Created):

{
  "success": true,
  "data": {
    "repo_id": "myuser/my-imported-model",
    "type": "model",
    "import_status": "pending",
    "import_job_id": "550e8400-e29b-41d4-a716-446655440000"
  }
}

Import Status Values:

StatusDescription
pendingQueued
in_progressDownload/upload in progress
completedImport complete
failedImport failed

Error Codes

HF Token Errors

CodeDescription
INVALID_TOKEN_FORMATInvalid HF token format (must start with hf_)
TOKEN_TOO_SHORTToken too short (minimum 20 characters)

HF Search/Validation Errors

CodeDescription
INVALID_REPO_TYPEType other than model/dataset/space
INVALID_REPO_IDNot in author/name format
HF_REPO_NOT_FOUNDRepository not found on HF
HF_ACCESS_DENIEDPrivate or gated repository
HF_RATE_LIMITHF API rate limit exceeded
HF_TOKEN_INVALIDHF token expired or invalid

Import Errors

CodeDescription
IMPORT_ALREADY_IN_PROGRESSImport already in progress
HF_TOKEN_REQUIREDHF token required for private repository

Response Format Differences

Foundry API uses two response formats:

API TypeField FormatExample
Foundry native APIsnake_casecreated_at, is_pinned
HF-compatible APIcamelCaselastModified, modelId

HF-compatible responses may include extension fields prefixed with _foundry_*. The huggingface_hub library ignores these fields; only Foundry-specific clients make use of them.

Limitations

  • One-time Import: After import, the repository is not synchronized with the original HF repository
  • Space Runtime: Import only copies files; to run apps, use the Foundry Spaces Deploy feature
  • Gated Repositories: You must accept the license on the HuggingFace website before importing