HTTP client for HuggingFace Hub API.
Provides low-level HTTP request functionality with authentication, rate limiting, and error handling.
Summary
Functions
Performs a DELETE request.
Downloads a file from a URL with streaming support.
Makes a GET request to the HuggingFace Hub API.
Makes a paginated GET request and collects all pages.
Makes a HEAD request to fetch headers without body.
Performs a PATCH request with JSON body.
Makes a POST request to the HuggingFace Hub API.
Performs a POST request expecting no response body.
Performs a PUT request with JSON body.
Functions
Performs a DELETE request.
DELETE requests typically don't have a body but may return data.
Downloads a file from a URL with streaming support.
Arguments
url- Full URL to downloaddestination- Local file pathopts- Download options
Options
:token- Authentication token:resume- Resume interrupted download. Defaults tofalse.:progress_callback- Function called with download progress. The callback receives(bytes_downloaded, total_bytes)wheretotal_bytesmay benilif the server doesn't provide Content-Length.
Examples
:ok = HfHub.HTTP.download_file(
"https://huggingface.co/bert-base-uncased/resolve/main/config.json",
"/tmp/config.json"
)
# With progress tracking
:ok = HfHub.HTTP.download_file(
"https://huggingface.co/bert-base-uncased/resolve/main/model.bin",
"/tmp/model.bin",
progress_callback: fn downloaded, total ->
if total, do: IO.puts("#{round(downloaded / total * 100)}%")
end
)
Makes a GET request to the HuggingFace Hub API.
Arguments
path- API path (e.g., "/api/models/bert-base-uncased")opts- Request options
Options
:token- Authentication token:headers- Additional headers:params- Query parameters
Examples
{:ok, response} = HfHub.HTTP.get("/api/models/bert-base-uncased")
Makes a paginated GET request and collects all pages.
Pagination follows the Link header with rel="next".
Options
:token- Authentication token:headers- Additional headers:params- Query parameters
Makes a HEAD request to fetch headers without body.
Used for ETag-based cache validation.
Arguments
url- Full URL to requestopts- Request options
Options
:headers- Request headers:follow_redirects- Whether to follow redirects. Defaults totrue.
Examples
{:ok, response} = HfHub.HTTP.head("https://huggingface.co/model/file")
Performs a PATCH request with JSON body.
Makes a POST request to the HuggingFace Hub API.
Arguments
path- API pathbody- Request body (will be JSON-encoded)opts- Request options
Examples
{:ok, response} = HfHub.HTTP.post("/api/endpoint", %{data: "value"})
Performs a POST request expecting no response body.
Used for actions that return 200/204 with no content.
Performs a PUT request with JSON body.