# `HuggingfaceClient.Hub.Spaces`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/hub/spaces/spaces.ex#L1)

Manage Hugging Face Spaces — hosted ML applications.

Covers secrets, environment variables, hardware management, Space lifecycle
(pause, restart, duplicate), and dev mode for iterative development.

See: https://huggingface.co/docs/hub/spaces-overview

## Example

    # Get Space runtime info
    {:ok, runtime} = HuggingfaceClient.get_space_runtime("my-org/my-space",
      access_token: "hf_..."
    )

    # Set a secret
    :ok = HuggingfaceClient.add_space_secret("my-org/my-space",
      key: "API_KEY",
      value: "my-api-key",
      access_token: "hf_..."
    )

    # Upgrade hardware
    {:ok, runtime} = HuggingfaceClient.request_space_hardware("my-org/my-space",
      hardware: "t4-medium",
      access_token: "hf_..."
    )

# `add_secret`

```elixir
@spec add_secret(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Adds or updates a secret environment variable in a Space.

Secrets are not exposed in the Space's environment to other users.

## Example

    :ok = HuggingfaceClient.add_space_secret("my-org/my-space",
      key: "OPENAI_API_KEY",
      value: "sk-...",
      description: "OpenAI API key for GPT-4",
      access_token: "hf_..."
    )

# `add_variable`

```elixir
@spec add_variable(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Adds or updates a public environment variable in a Space.

Unlike secrets, variables are visible in the Space settings.

## Example

    :ok = HuggingfaceClient.add_space_variable("my-org/my-space",
      key: "MODEL_ID",
      value: "gpt2",
      access_token: "hf_..."
    )

# `delete_secret`

```elixir
@spec delete_secret(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Deletes a secret from a Space.

## Example

    :ok = HuggingfaceClient.delete_space_secret("my-org/my-space",
      key: "OLD_API_KEY",
      access_token: "hf_..."
    )

# `delete_variable`

```elixir
@spec delete_variable(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}
```

Deletes an environment variable from a Space.

# `dev_mode`

```elixir
@spec dev_mode(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Enables or disables dev mode on a Space for interactive development.

In dev mode, you can push changes directly and restart the Space without
a full Docker rebuild.

## Example

    {:ok, info} = HuggingfaceClient.space_dev_mode("my-org/my-space",
      enable: true,
      access_token: "hf_..."
    )

# `duplicate`

```elixir
@spec duplicate(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Duplicates a Space to the authenticated user's account.

## Options

- `:private` — whether the duplicated Space is private (default: same as source)
- `:exist_ok` — if `true`, don't raise if destination already exists
- `:access_token`

## Example

    {:ok, new_space} = HuggingfaceClient.duplicate_space("gradio/hello_world",
      private: true,
      access_token: "hf_..."
    )

# `get_runtime`

```elixir
@spec get_runtime(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Gets the current runtime of a Space (hardware, stage, etc.).

## Example

    {:ok, runtime} = HuggingfaceClient.get_space_runtime("gradio/hello_world",
      access_token: "hf_..."
    )
    IO.puts("Hardware: #{runtime["hardware"]["current"]}")
    IO.puts("Stage: #{runtime["stage"]}")

# `get_variables`

```elixir
@spec get_variables(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Gets all environment variables for a Space.

## Example

    {:ok, vars} = HuggingfaceClient.get_space_variables("my-org/my-space",
      access_token: "hf_..."
    )
    IO.inspect(vars)  # %{"MODEL_ID" => %{"value" => "gpt2", ...}}

# `list_secrets`

```elixir
@spec list_secrets(
  String.t(),
  keyword()
) :: {:ok, [map()]} | {:error, Exception.t()}
```

Lists all secrets for a Space (returns keys but NOT values).

## Example

    {:ok, secrets} = HuggingfaceClient.list_space_secrets("my-org/my-space",
      access_token: "hf_..."
    )
    Enum.each(secrets, fn s -> IO.puts(s["key"]) end)

# `pause`

```elixir
@spec pause(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Pauses a Space (stops compute billing; Space enters sleeping state).

## Example

    {:ok, runtime} = HuggingfaceClient.pause_space("my-org/my-space",
      access_token: "hf_..."
    )

# `request_hardware`

```elixir
@spec request_hardware(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Requests a hardware upgrade or downgrade for a Space.

## Hardware options

`"cpu-basic"`, `"cpu-upgrade"`, `"t4-small"`, `"t4-medium"`, `"a10g-small"`,
`"a10g-large"`, `"a10g-largex2"`, `"a100-large"`, `"zero-a10g"`

## Example

    {:ok, runtime} = HuggingfaceClient.request_space_hardware("my-org/my-space",
      hardware: "t4-medium",
      sleep_time: 3600,
      access_token: "hf_..."
    )

# `restart`

```elixir
@spec restart(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Restarts a paused or errored Space.

## Example

    {:ok, runtime} = HuggingfaceClient.restart_space("my-org/my-space",
      factory_reboot: true,
      access_token: "hf_..."
    )

# `set_sleep_time`

```elixir
@spec set_sleep_time(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}
```

Sets the sleep time for a Space (auto-pause after inactivity).

## Example

    {:ok, runtime} = HuggingfaceClient.set_space_sleep_time("my-org/my-space",
      sleep_time: 1800,
      access_token: "hf_..."
    )

---

*Consult [api-reference.md](api-reference.md) for complete listing*
