Space management API for HuggingFace Spaces.
Provides runtime control, secrets, variables, and hardware configuration.
Hardware Options
:cpu_basic- Free CPU:cpu_upgrade- Upgraded CPU:t4_small- T4 GPU (small):t4_medium- T4 GPU (medium):a10g_small- A10G GPU (small):a10g_large- A10G GPU (large):a100_large- A100 GPU:zero_a10g- ZeroGPU A10G
Storage Options
:small- Small persistent storage:medium- Medium persistent storage:large- Large persistent storage
Examples
# Get runtime info
{:ok, runtime} = HfHub.Spaces.get_runtime("user/my-space")
# Request GPU hardware
{:ok, runtime} = HfHub.Spaces.request_hardware("user/my-space", :t4_small)
# Add a secret
:ok = HfHub.Spaces.add_secret("user/my-space", "API_KEY", "secret_value")
# Pause and restart
{:ok, _} = HfHub.Spaces.pause("user/my-space")
{:ok, _} = HfHub.Spaces.restart("user/my-space")
Summary
Functions
Adds or updates a secret.
Adds or updates a variable.
Deletes a secret.
Deletes persistent storage.
Deletes a variable.
Duplicates a Space to a new repository.
Gets runtime information for a Space.
Gets all variables for a Space.
Pauses a running Space.
Requests hardware upgrade or downgrade.
Requests persistent storage.
Restarts a Space.
Sets the auto-sleep timeout.
Types
Functions
Adds or updates a secret.
Secrets are encrypted and not visible after creation.
Arguments
repo_id- Repository IDkey- Secret namevalue- Secret valueopts- Request options
Options
:token- Authentication token:description- Optional description
Examples
:ok = HfHub.Spaces.add_secret("user/my-space", "API_KEY", "secret_value")
:ok = HfHub.Spaces.add_secret("user/my-space", "API_KEY", "value",
description: "API key for external service")
@spec add_variable(String.t(), String.t(), String.t(), keyword()) :: {:ok, HfHub.Spaces.SpaceVariable.t()} | {:error, term()}
Adds or updates a variable.
Variables are visible in the Space settings.
Arguments
repo_id- Repository IDkey- Variable namevalue- Variable valueopts- Request options
Options
:token- Authentication token:description- Optional description
Examples
{:ok, var} = HfHub.Spaces.add_variable("user/my-space", "DEBUG", "true")
Deletes a secret.
Arguments
repo_id- Repository IDkey- Secret name to deleteopts- Request options
Options
:token- Authentication token
Examples
:ok = HfHub.Spaces.delete_secret("user/my-space", "API_KEY")
@spec delete_storage( String.t(), keyword() ) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Deletes persistent storage.
Warning: This is destructive and cannot be undone.
Arguments
repo_id- Repository IDopts- Request options
Options
:token- Authentication token
Examples
{:ok, runtime} = HfHub.Spaces.delete_storage("user/my-space")
Deletes a variable.
Arguments
repo_id- Repository IDkey- Variable name to deleteopts- Request options
Options
:token- Authentication token
Examples
:ok = HfHub.Spaces.delete_variable("user/my-space", "DEBUG")
@spec duplicate( String.t(), keyword() ) :: {:ok, HfHub.Repo.RepoUrl.t()} | {:error, term()}
Duplicates a Space to a new repository.
Arguments
from_id- Source Space repository IDopts- Request options
Options
:token- Authentication token:to_id- Target repository ID (default: same name in user namespace):private- Make duplicate private (default: false):hardware- Hardware for duplicate:storage- Storage for duplicate:secrets- List of secrets to copy (maps with "key" and "value"):variables- List of variables to copy (maps with "key" and "value")
Examples
{:ok, repo_url} = HfHub.Spaces.duplicate("gradio/hello_world")
{:ok, repo_url} = HfHub.Spaces.duplicate("gradio/hello_world",
to_id: "user/my-copy", private: true)
@spec get_runtime( String.t(), keyword() ) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Gets runtime information for a Space.
Arguments
repo_id- Repository ID (e.g., "user/my-space")opts- Request options
Options
:token- Authentication token
Examples
{:ok, runtime} = HfHub.Spaces.get_runtime("user/my-space")
runtime.stage # => :running
runtime.hardware # => "cpu-basic"
@spec get_variables( String.t(), keyword() ) :: {:ok, %{required(String.t()) => HfHub.Spaces.SpaceVariable.t()}} | {:error, term()}
Gets all variables for a Space.
Arguments
repo_id- Repository IDopts- Request options
Options
:token- Authentication token
Examples
{:ok, vars} = HfHub.Spaces.get_variables("user/my-space")
vars["MY_VAR"].value # => "some_value"
@spec pause( String.t(), keyword() ) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Pauses a running Space.
A paused Space stops using resources but retains its configuration.
Arguments
repo_id- Repository IDopts- Request options
Options
:token- Authentication token
Examples
{:ok, runtime} = HfHub.Spaces.pause("user/my-space")
@spec request_hardware(String.t(), hardware(), keyword()) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Requests hardware upgrade or downgrade.
Arguments
repo_id- Repository IDhardware- Hardware type (see module docs)opts- Request options
Options
:token- Authentication token:sleep_time- Auto-sleep timeout in seconds
Examples
{:ok, runtime} = HfHub.Spaces.request_hardware("user/my-space", :t4_small)
{:ok, runtime} = HfHub.Spaces.request_hardware("user/my-space", :cpu_basic,
sleep_time: 300)
@spec request_storage(String.t(), storage(), keyword()) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Requests persistent storage.
Arguments
repo_id- Repository IDstorage- Storage tier (:small,:medium, or:large)opts- Request options
Options
:token- Authentication token
Examples
{:ok, runtime} = HfHub.Spaces.request_storage("user/my-space", :small)
@spec restart( String.t(), keyword() ) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Restarts a Space.
Arguments
repo_id- Repository IDopts- Request options
Options
:token- Authentication token:factory_reboot- Full factory reset (default: false)
Examples
{:ok, runtime} = HfHub.Spaces.restart("user/my-space")
{:ok, runtime} = HfHub.Spaces.restart("user/my-space", factory_reboot: true)
@spec set_sleep_time(String.t(), integer(), keyword()) :: {:ok, HfHub.Spaces.SpaceRuntime.t()} | {:error, term()}
Sets the auto-sleep timeout.
Arguments
repo_id- Repository IDseconds- Timeout in seconds, or -1 to disable (requires paid hardware)opts- Request options
Options
:token- Authentication token
Examples
{:ok, runtime} = HfHub.Spaces.set_sleep_time("user/my-space", 300)
{:ok, runtime} = HfHub.Spaces.set_sleep_time("user/my-space", -1) # Never sleep