---
title: "Rust SDK"
description: "One client, with a namespace for each product (Cube, Sandbox, Browser, Drive, Database) and the platform's own calls on the client itself. Blocking calls that return Result, chained options, four dependencies and no async runtime."
---

> Documentation Index
> Fetch the complete documentation index at: https://glac.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust SDK

## Install

Calls block and return `Result`; options are chained `…Options`; durations are `Duration` and times `SystemTime`; the API's `null` is `Option`. Four dependencies (`serde_json`, `rustls` with `ring`, `webpki-roots`, `libc`) and no async runtime. The crate is `glac` on crates.io:

```toml
[dependencies]
glac = "0.1"
```

## The client and its products

```rust
use glac::{AppOptions, DriveOptions};

let client = glac::Client::new()?; // GLAC_API_KEY and GLAC_API_URL; another address or key: Client::builder()

let app = client.cube().deploy("ghcr.io/acme/api:1.4", &AppOptions::new().name("api").port(8080))?; // Cube: waits until it serves
println!("{:?}", app.url());

let sbx = client.sandboxes().create()?; // Sandbox
println!("{}", sbx.run("python3 -c 'print(6*7)'")?.stdout);

let drive = client.drives().create_with(&DriveOptions::new().size_bytes(1 << 30))?; // Drive

println!("{}", glac::run("echo hello")?.stdout); // the shorthand: a sandbox for one command, on the client the environment describes
```

Each product is a namespace of the client's, a light handle that borrows it:

- `client.cube()`: Cube, images that run as services, which the API calls apps. The types keep the API's names: `App`, `AppOptions`, `Version`, `Instance`. `client.workers()` is another name for it, marked deprecated.
- `client.sandboxes()`: sandboxes, with their snapshots (`.snapshots()`) and the SSH keys that open them (`.ssh_keys()`).
- `client.drives()`: Drives, disks of the project's that outlive their sandboxes, each mounted read-write by one sandbox at a time (`Drive`, `DriveOptions`, `DriveMount`), and their snapshots (`DriveSnapshot`, `DriveSnapshotOptions`, `DriveForkOptions`); `client.volumes()`, the volumes underneath them (`Volume`, `VolumeOptions`, `VolumeMount`); `client.backups()`, the backups of volumes (`Backup`, `BackupOptions`), a control plane's.
- `client.domains()`: the project's own domains (`Domain`, `DomainOptions`), names for an app or a port of a sandbox; a control plane's.
- `client.webhooks()` and `client.keys()`: where the project's events are sent (`Webhook`, `WebhookOptions`), and its API keys (`ProjectKey`, `KeyOptions`); a control plane's.
- `client.destinations()`: where the logs, metrics and traces of the project's apps are exported (`Destination`, `DestinationOptions`); a control plane's.
- `client.secrets()` and `client.variables()`: the project's secrets and shared variables.
- `client.deploys()`: the project's deploys (`/v1/deploys`, a control plane's): several of its services deployed together, in the order of what each waits for, and switched together ([a project's deploy](/docs/cube/services/#deploying-a-project)). `create([("api", DeployOptions::new().image("ghcr.io/acme/api:2")), ("web", DeployOptions::new())])` gives each service what a deploy of it alone takes and waits for the deploy, following one that took its place; one that fails is an error of kind `deploy_failed` with the deploy's code (`job_failed`, `job_timed_out`, `job_lost`, …) and the service as `param()` (`services.<name>`). `create_with(…, &ProjectDeployOptions::new().no_wait())`, `get(id)`, `list()`.
- What is no product's is the client's own: the account, usage, the plan and the bill, the project and its events.

The key is read from `GLAC_API_KEY` and the address from `GLAC_API_URL`. For another address, key or timeout, build a client:

```rust
let client = Client::builder().api_key(key).base_url(address).build()?;
let named = client.sandboxes().create_with(&CreateOptions::new().name(&name).env("STAGE", "dev").never_sleep())?;
```

**The shorthand.** The one-liners of the sandbox SDKs stay, as `client.sandboxes()` on the client the environment describes (`Client::shared()`, made on first use): `glac::run`, `glac::run_with`, `Sandbox::create`, `Sandbox::get`, `Sandbox::get_or_create`, `Sandbox::list`, and their `_with` and `_page` forms. Everything else takes a client.

Each call with options has two forms: `create()` and `create_with(&options)`, `run(cmd)` and `run_with(cmd, options)`. An API the SDK does not wrap: `client.request("GET", "/v1/webhooks", &[], None)`. Three names of the API are Rust keywords and are renamed: an error's `type` is `kind()`, a file's `type` is `FileEntry::kind`, and `files/move` is `rename`.

## Cube

Below, `cube` is `client.cube()`.

| Call | What it does |
|---|---|
| `cube.deploy(image, &AppOptions::new().name("api").port(8080))` | Deploys an image, as `glac deploy` does: a new version of the app of that name, or a new app. Waits until the version has the traffic, and returns the app as it is then (`url()`, `current_version()`). |
| `cube.create_with(&AppOptions)`, `cube.get(id_or_name)`, `cube.get_or_create_with(name, &AppOptions)`, `cube.list()` | Makes an app (given an image, its first version is deployed and waited for); finds one; finds or makes one; lists them. `drives([DriveMount…])` are the Drives its one instance mounts read-write (an app of many instances or of keys is refused, 409 `drive_single_writer`; a version mounts a Drive read-write only, and read-only snapshot mounts are a sandbox's); `key_drives([KeyDrive…])` give each key's instance of a keyed app Drives of its own, made with its first instance and deleted with the key. |
| `app.deploy_with(&DeployOptions)`, `app.update(&AppChanges)`, `app.rollback(Some("1"), true)`, `app.versions()`, `app.delete()` | A new version; a change; the traffic back to a version; the versions; delete. |
| `.runtime(json!({"ulimits": {"nofile": 65535}}))` of `AppOptions` and `DeployOptions` | The version's [runtime settings](/docs/cube/versions/#runtime-settings), as the API takes them: `ulimits`, `sysctls`, `tmpfs`, `dns`, `shm_size_bytes`; replaced whole. |
| `app.logs()`, `cube.logs_with(name, &LogsOptions)`, `app.log_usage(…)`, `app.info().logs_state`, `app.instance(key, None)` | Its log, an iterator of lines, also by the app's name; what the log counted; whether each machine that keeps it keeps what is printed there now for the long term ([logs](/docs/platform/logs/#what-is-kept-and-for-how-long)); keyed instances. |
| `instance.upgrade(Some("3"))`, `app.upgrade_instance(key, version)`; `up.wait()`, `up.wait_for(limit)`; `instance.upgrades()`, `app.instance_upgrades(key)`, `app.instance_upgrade(key, id)` | Moves a key's instance to another version of the app, [in place](/docs/cube/keyed-instances/#a-new-version-for-one-instance): `None` is the app's current version, else its id or its number (one that is ready, an older one too). It keeps its id, its node, its key, its address, its tokens and its own Drives; its disk, its machine and its processes become the new version's, and its requests are held at the edges while it is switched. `Some(Upgrade)` under way (its `info()`: `status` `preparing`, `switching`, `done` or `failed`, `from_version`, `to_version`, `timings`, `error`, `put_back`, `kind` (`upgrade`, or `revert`), `when`, `keep_days`, `rollback` (what a revert of it needs, kept for `keep_days`), `reverts`, `batch`; an upgrade asked through the API to wait for its instance to sleep is `waiting` until then, and `cancelled` where it was cancelled (the API's `DELETE`, or its batch stopped): one that was cancelled is over, and its wait raises as one that failed does, with the code `cancelled`), or `None` where it is on that version already; `wait()` is an error of kind `upgrade_failed` (its code `upgrade_failed` or `upgrade_not_here`) where the new version did not come up, the instance on the version it was on. `instance.refresh()` reads the instance again (`version_id`). |
| `app.upgrade_instance_with(key, &UpgradeOptions::new().version("4").when_asleep().keep_days(14))`, `instance.upgrade_with(&…)` | The same with `when_asleep` (it waits, `waiting`, until the instance sleeps and begins then, so that none of its requests is held) and `keep_days` (0 to 365, 7 unless given: how long what a revert needs is kept once it is done, billed as snapshots are). A version whose services mount other Drives or volumes than the instance's is no upgrade in place: it ends `failed` with `upgrade_not_here`. |
| `up.cancel()`, `app.cancel_instance_upgrade(key, id)`; `up.revert(keep_days)`, `app.revert_instance_upgrade(key, id, keep_days)` | An upgrade that waits (for its instance to sleep, or for its turn in a batch) cancelled: `cancelled`, the instance on its version (one that has begun is 409 `upgrade_started`). A [revert](/docs/cube/keyed-instances/#a-new-version-for-one-instance): the instance back to what an upgrade kept, its disk, its Drives as they were before it (a snapshot of what they hold now made first) and the version it came from; a new `Upgrade` of kind `revert`, which goes and is waited for as an upgrade is. Refused 409 `rollback_gone` where what it goes back to is not kept any more. |
| `app.upgrade_instances(&UpgradeBatchOptions::new().version("4").from_versions(["3"]).keys(["k"]).when_now().keep_days(1).concurrency(8).max_failures(1))`; `app.upgrade_batches()`, `app.upgrade_batch(id)`, `app.stop_upgrade_batch(id)`; `batch.wait()`, `batch.wait_for(limit)`, `batch.refresh()`, `batch.stop()` | A batch of upgrades of the app's keys to one version (the app's current one unless given): each once its instance sleeps (or as its turn comes, `when_now`), 4 at once unless given (two on one node), stopped `failed` after 5 failures unless given. An `UpgradeBatch` whose `info()` is an `UpgradeBatchInfo`: `status` (`running`, `done`, `failed`, `stopped`), `stop_reason`, `counts`, `upgrades` (each member's key, upgrade, status and error), `skipped`, `origin`. `wait()` is Ok however it ended; a member whose instance never sleeps keeps it running, so `wait_for` ends with `wait_timeout`. `stop()` cancels the members that wait. |
| `app.open_instance_port(key, "tcp", port, &["2001:db8::/32"])`, `app.instance_ports(key, "tcp")`, `app.close_instance_port(key, "tcp", port)` | The ports open at the own public IPv6 address of a key's instance, wherever it is: its sandbox's `open_port`, `ports` and `close_port`, by the app and the key (`"udp"` for UDP; [keyed instances](/docs/cube/keyed-instances/#its-own-ipv6-address)). An instance with no address of its own is refused (409 `no_ipv6`). |
| `AppOptions::checkpoint(n)`, `AppChanges::checkpoint(n)`, `AppChanges::no_checkpoint()` | [Checkpoints](/docs/cube/keyed-instances/#checkpoints) of the app's keyed instances while they are awake (1 to 600; 0 is the default, 10), and none again; `AppInfo::checkpoint` says it. An instance's `SandboxInfo::checkpoint` (an `Option<SandboxCheckpoint>`: `every_seconds`, `last_at`, `behind_seconds`, `bytes_per_second`, `stored_bytes`, `error`) says how its checkpoints go. |
| `app.metrics(from, to, step)` | What the machines that serve the app counted of it, a step a minute (`Some("hour")`: an hour): requests by the class of their status, how long they took, its instances and what they used ([metrics](/docs/platform/logs/#metrics)). The API's object. |
| `.trace_sample_rate(0.1)`, `.trust_incoming_trace(true)` of `AppOptions` and `AppChanges`; `app.info().traces` | A span of the platform's for a share of the app's requests, which the instance's own spans are children of (none unless given), sent to the project's destinations that take `"traces"` ([traces](/docs/platform/logs/#traces)); what the app has (an `AppTraceSettings`). |
| `app.create_key_secret()`, `app.key_secrets()`, `app.key_secret(id)`, `app.delete_key_secret(id)`, `glac::sign_key(secret, app_id, key, expires)` | The secrets an app's keys are signed with (a `KeySecret`, whose `secret` only the one just made has), and a key signed with one, as a request through the edge carries it ([signed keys](/docs/cube/keyed-instances/#signed-keys)); `glac::path_segment` writes it as a path segment. |

`deploy` to an app that is there changes what of the options is the app's own first (regions, scale, keys, egress rules, metadata, logs, traces, `public`, `depends_on`, network: `PATCH /v1/apps/{id}`, only when any of it is given), then makes a version of the image and the rest (`POST /v1/apps/{id}/versions`), what is not given of it being what the app has: the same requests as `app.update(…)` and then `app.deploy_with(…)`. With no app of that name (404 `app_not_found`), or no name, it makes one with everything (`POST /v1/apps`); a 409 `name_taken` there means somebody made it in between, and it deploys to theirs. `no_wait()` returns as soon as the version is made. A version that does not come up is an error whose `kind()` is `deploy_failed`, with the version's own code and words. Apps are a control plane's: a node that stands alone answers each of these calls with 404 `no_such_route`.

## Sandbox

Below, `sandboxes` is `client.sandboxes()`.

```rust
let mut sbx = client.sandboxes().create()?; // stays until deleted, also when the value is dropped
let res = sbx.run("python3 -c 'print(6*7)'")?; // res.stdout, res.stderr, res.exit_code
println!("{} {}", res.stdout, sbx.url(3000)?);
```

A command given as a string runs with `sh -c`; as an array of strings it is a program and its arguments.

```rust
let cmd = sbx.exec("node server.js")?; // do not wait
for piece in cmd.output() {
    print!("{}", String::from_utf8_lossy(&piece?.data));
}
```

| Call | What it does |
|---|---|
| `sandboxes.create_with(&CreateOptions::new().image(…).name(…).env(k, v).drive(DriveMount::new("/data", id)).sleep_after(d).never_sleep().sleep_notice(d).sleep_hold_max(d).egress(…))` | Makes a sandbox; every option may be left out. A service started when it boots: `.start(true)` (the image's own start command), `.start_line(…)` or `.start_argv(…)`, with `.ready_tcp(port)`, `.ready_http(port, path)` or `.ready_command(…)`; `.hostname(…)`, `.stop_signal(…)` and `.stop_grace(d)`; `.project_network()` puts it on the project's private network from the start (`info().project_address`); `VolumeMount::new("/data", vol).copy()` gives a new volume what the image has at its path ([making a sandbox](/docs/sandbox/commands/#making-a-sandbox)). |
| `sbx.info().app_id`, `version_id`, `key`, `image_digest` | A sandbox made through the control plane is an instance of an app: the project's default sandbox app (`sbx-sandbox`) when it was made with no image, else the app of its image (the app's `instances()` lists that app's sandboxes, each under its key); the version of that app it is of, the image it was made of (a tag that was moved since is a new version of the app, which the sandboxes made after it are of); its key there, its name or its id; and its image by digest. Said by its create's answer and by every read of it, and kept; `None` for one made from a template or a snapshot, and for a fork. |
| `CreateOptions::init("systemd")`; `SandboxInfo::init` | A whole system: the image's own systemd is the sandbox's PID 1 (without an image, the platform's Ubuntu with systemd and OpenSSH), so packages, services started with `systemctl`, cron and the journal work as on a machine, and it has a machine ID of its own, kept through sleeps, wakes and moves. Not with a start command or a ready check (400 `invalid_start`), nor from a snapshot. `init` is `Some("systemd")` for one and `None` for the platform's init. |
| `sandboxes.get`, `sandboxes.get_or_create`, `sandboxes.list_with(&ListOptions)`, `sandboxes.list_page(&ListOptions)` | Finds; finds or makes; lists; one page. |
| `.suspend_after(d)`, `.wake_daily_at("03:30")` of `CreateOptions` and `UpdateOptions` (`.default_suspend_after()`, `.no_daily_wake()` take them back); `SandboxInfo::suspend_after`, `wake_daily_at` | How long it stays paused, once idle has stopped it, before its memory is saved and it sleeps for real (a second to a day; its node holds it to ten minutes at the most), and a time of day in UTC at which it is woken every day while it rests, for work of its own that waits for a wake. |
| `.on_expiry("sleep")`, `.held_asleep(true)` of `CreateOptions` and `UpdateOptions`; `SandboxInfo::on_expiry`, `held_asleep` | What `expires_at` does when it comes: `delete` the sandbox (the default), `sleep` (put it to sleep and keep it, a request waking it as ever) or `hold` (the same, held asleep); and whether a request to one of its ports wakes it while it sleeps: held asleep, its preview address answers 502 `sandbox_paused`, and a call of the API wakes it. |
| `sandboxes.run(cmd)`, `sandboxes.run_with(cmd, RunOptions, &CreateOptions)` | A sandbox for one command: made, used, deleted. |
| `sbx.run_with(cmd, RunOptions::new().cwd(…).timeout(d).on_stdout(f))` | Runs and waits. `CommandResult` has `stdout`, `stderr`, `exit_code`, `duration`, `usage`, `wake`. |
| `sbx.exec`, `sbx.terminal()` | Starts a command (`wait()`, `output()`, `write()`, `kill()`); a terminal. |
| `sbx.files()` | `read`, `read_text`, `write`, `list`, `stat`, `exists`, `mkdir`, `rename`, `remove`, and `set_attributes(path, mode, size_bytes, modified_at)`: a file's mode, its length, its time of last modification; `.as_user("node")`. |
| `sbx.url(port)`, `sbx.token_with(scopes, expires_in)` | A link to a port (signed locally); a token for this sandbox. |
| `sbx.info().ipv6`, `sbx.open_port("tcp", port, &[…])`, `sbx.ports("tcp")`, `sbx.close_port("tcp", port)`, `.inbound(InboundPort::tcp(port, […]))` | Its own public IPv6 address, where it has one (`None` otherwise); a port opened at it to the sources listed (IPv6 prefixes or addresses, `"::/0"` for everybody), with where it is reached; the ports open; one closed (it says whether it was open); the list, of `CreateOptions` and `UpdateOptions`. Inbound is closed by default; what is open stays open while it sleeps and when it moves. See [networking](/docs/platform/networking/#a-sandboxs-own-ipv6-address). |
| `sbx.revoke_token(token)` | That token alone is refused from then on, and every other works as before: the token itself (`Token::token`) or its id (`Token::id`, `tok_…`). A sandbox keeps 1,000 such revocations that have not run out (409 `too_many_revoked_tokens` past them: `revoke_tokens()` then). Returns a `TokenRevocation` with its `token_id` and `expires_at`. |
| `sbx.revoke_tokens()` | Every token handed out for this sandbox so far stops working (401 `invalid_token`), those in preview links and cookies and those SSH sessions hold too; tokens made after it work. Needs the API key. Returns a `TokenRevocation`: `sandbox_id`, `generation`, `revoked_at`. |
| `sbx.update`, `sbx.sleep()`, `sbx.restart()`, `sbx.delete()`, `sbx.snapshot()`, `sbx.fork(n)`, `sbx.restore(…)` | Change it; sleep; boot from disk; delete; snapshot; fork; restore. |
| `CreateOptions::new().checkpoint(10)`, `UpdateOptions::new().checkpoint(10)`, `.no_checkpoint()`; `info().checkpoint` | [Checkpoints](/docs/sandbox/sleep/#checkpoints) while it is awake (1 to 600 seconds apart; 0: ten), so that it goes on with its processes when its machine is lost, and none again; how they go. 409 `checkpoints_unavailable` where no machine takes them. |
| `info().disk_writes` | What its disk has written today (a UTC day), against the day's share at full speed (an `Option<SandboxDiskWrites>`): `today_bytes`, of which `checkpoint_copy_bytes` its checkpoints' copies wrote to the host's disk; `full_speed_until_bytes`, the share (100 GiB unless its node is told otherwise; None: its node slows nothing, and counts all the same); `limited` and `limited_until`: past the share its disk takes writes at 2 MiB a second until the day ends, and no write fails. None on a node that does not copy its disks to an object store, which counts nothing. What it writes to its Drives is not counted here: a Drive's writes are billed by the gigabyte. |
| `sandboxes.snapshots()`: `get`, `list`, `list_with(&ListOptions::new().sandbox(id))` | The snapshots, found again; `snap.rename(Some(name))` (`None`: no name), `snap.expire_at(Some(t))` (`None`: never), `snap.delete()`. |
| `sandboxes.ssh_keys()`: `create(public_key)`, `create_with(public_key, &SshKeyOptions)`, `get`, `list`, `list_with` | The SSH keys that open sandboxes through the gateway (`ssh <sandbox>@<gateway>`); a private key is refused before anything is sent. |

## Drive

A Drive is a disk of the project's that outlives its sandboxes: mounted read-write by one sandbox at a time, when the sandbox is made or while it runs, and kept, with what it holds, when the sandbox goes, for the next sandbox to mount: of its region, or of another whose machines read its home's object store (below). It is copied into its region's object store as it is written, so a sandbox on another node mounts it too: it is brought there first. Only what is written is billed (`used_bytes`). A snapshot of a Drive is a version of it in the object store, nothing copied: a fork is a new Drive made of one, a restore makes a snapshot's content the Drive's again, and any number of sandboxes mount one read-only at once. Drives are a control plane's (`/v1/drives`): against a node that stands alone every call is the node's 404 `no_such_route`, and its disks are volumes (below).

```rust
use glac::DriveMount;

let drive = client.drives().create_with(&DriveOptions::new().size_bytes(1 << 30))?; // Drive
let sbx = client.sandboxes().create_with(&CreateOptions::new().drive(DriveMount::new("/data", drive.id())))?;
sbx.run("echo kept > /data/note")?;
client.drives().detach(sbx.id(), drive.id())?;
let other = client.sandboxes().create()?;
client.drives().attach(other.id(), &DriveMount::new("/data", drive.id()))?;
println!("{}", other.run("cat /data/note")?.stdout); // kept
```

| Call | What it does |
|---|---|
| `drives.create_with(&DriveOptions::new().name(…).size_bytes(…).region(…).durability(…))`, `drives.get(id_or_name)`, `drives.list()`, `drives.list_page(&ListOptions)` | Makes a Drive, empty but for its file system; every option may be left out (`size_bytes`: a whole number of 4 KiB blocks, at least 16 MiB; 64 GiB unless given, or 5 GiB on Free; `region`: `na`, `eu` or `ap`; `durability`: `standard`, or `strict`, whose guest's fsync returns once the object store has every write before it). Finds one; lists them, newest first; one page. |
| `drives.rename(id_or_name, Some(name))`, `drives.delete(id_or_name)` | Renames it (`None`: no name); deletes it, with what it holds. Its snapshots stay. |
| `drives.attach(sandbox, &DriveMount::new(path, drive))`, `drives.detach(sandbox, drive)`, `drives.force_detach(sandbox, drive)` | Mounts it in a sandbox that exists, read-write, at once (a sandbox that sleeps is woken); unmounts it (`force_detach` while a process uses it). Each returns the Drive. A mount with a snapshot (`DriveMount::snapshot`) is `attach_snapshot`'s, and `attach` refuses it before anything is sent; `mode("snapshot")` without a snapshot is refused by the API (400 `missing_field`). |
| `drive.attach(sandbox, path)`, `drive.detach(sandbox)`, `drive.rename(name)`, `drive.refresh()`, `drive.delete()` | The same, on a `Drive`, whose `info()` is a `DriveInfo`: `id` (a `vol-…`: a Drive is a volume), `name`, `size_bytes`, `used_bytes`, `attached_to` (`DriveAttachment`: the sandbox, the path, the mode), `region`, `home`, `status`, `lease` (`DriveLease`: the node of its one writer, the epoch, until when), `app_id` and `key` (a keyed instance's), `parent_drive_id` and `root_drive_id` (the Drive it was forked from, which may be deleted since, and the first of its line of forks; `None` for a Drive that is no fork), `managed_by` (a `ManagedBy`, the `id` of the database whose Drive it is; `None` for one that is none's), `created_at`. A database's Drive is mounted read-write by the database's instance alone, and renamed, restored and deleted through the database: those calls here are refused (409 `managed_by_database`); its snapshots and forks are the project's to take. An app a database is made of says so the same way (`app.info().managed_by`), and its update, deploy, rollback and delete are refused alike. |
| `drives.snapshot(drive)`, `drives.snapshot_with(drive, &DriveSnapshotOptions::new().name(…).fs_consistent())` | Takes a snapshot, a `DriveSnapshot`: a version of the Drive in the object store, made by its node, nothing copied. A Drive a running sandbox has is snapshotted with its writes held for a moment: its machine paused (`consistency` `paused`, the Drive as at a power cut), or with `fs_consistent()` its file system frozen by the sandbox's agent (`frozen`, mounted without replaying a journal; 409 `not_frozen` where the agent cannot). Ten seconds at the most, then 503 `unavailable` (retryable) and the guest goes on. One no running sandbox has is taken as it is (`at_rest`). A name is 1 to 63 lower-case letters, digits and hyphens (400 `invalid_name`). |
| `drives.snapshots(drive)`, `drives.all_snapshots(drive_deleted)`, `drives.get_snapshot(drive, snapshot)`, `drives.delete_snapshot(drive, snapshot)` | A Drive's snapshots, newest first; the project's of every Drive (`Some(true)`: those of Drives deleted since alone); one by its id (404 `snapshot_not_found`); deletes one, billed up to then: the forks made of it keep what they need, and a sandbox that has it mounted read-only keeps the mount until it is taken away. |
| `drives.fork(drive)`, `drives.fork_with(drive, &DriveForkOptions::new().name(…).from_snapshot(…))` | A new Drive whose first version is the snapshot's, or the Drive's as it is now: nothing copied, mounted at once, the Drive's size, with `parent_drive_id` and `root_drive_id`. Held to the plan's Drives as a create is (403 `drive_limit_reached`); a name another Drive or volume has is 409 `name_taken`. |
| `drives.restore(drive, snapshot)` | A new version after the Drive's newest whose content is the snapshot's. The versions in between stay where a snapshot or a fork keeps them, so restoring to an older snapshot and then to a newer one works. Refused while a sandbox has the Drive read-write (409 `drive_attached`: detach it first). Returns the Drive. |
| `DriveOptions::new().history_seconds(n)`, `drives.set_history(drive, Some(n))`, `drives.versions(drive)`, `drives.version_at(drive, t)`, `DriveForkOptions::new().at(t)`, `drives.restore_to(drive, t)`; `drive.set_history`, `drive.versions()`, `drive.restore_to(t)` | A Drive's window of versions (slice DB8): how far back it can be restored, or forked, by a time, 3600 to 86400 seconds (none unless given; turned off, what it kept goes). Every 30 seconds in which it was written the window gets a version, the Drive at one moment; what they keep alone is billed as a snapshot's is. A restore or a fork to a time takes the newest version at or before it, which the versions call with that time names. `versions` gives `DriveWindowVersion`s, the newest first; `set_history(drive, None)` turns the window off; `DriveInfo::history_seconds`, `history`. |
| `drives.attach_snapshot(sandbox, &DriveMount::new(path, drive).snapshot(id))`, `drives.detach_snapshot(sandbox, snapshot)`, `drives.force_detach_snapshot(sandbox, snapshot)` | Mounts a snapshot read-only in a sandbox that exists, at once (a mount without a snapshot is refused before anything is sent); takes it away by the snapshot's id, the Drive and the snapshot deleted since or not (`force_…` while a process uses it). Each returns the `DriveSnapshot`. When a sandbox is made: `CreateOptions::new().drive(DriveMount::new("/data", drive.id()).snapshot(snap.id()))`. |
| `drive.snapshot()`, `drive.snapshot_with(…)`, `drive.snapshots()`, `drive.fork()`, `drive.fork_with(…)`, `drive.restore(snapshot)`; `snap.refresh()`, `snap.delete()`, `snap.fork(Some(name))`, `snap.restore()`, `snap.attach(sandbox, path)`, `snap.detach(sandbox)`, `snap.force_detach(sandbox)` | The same, on a `Drive` and on a `DriveSnapshot`, whose `info()` is a `DriveSnapshotInfo`: `id` (a `dsnap-…`), `drive_id` (which may be deleted since), `name`, `consistency`, `used_bytes` (what the Drive held when it was taken), `exclusive_bytes` (what it keeps alone, which it is billed for; 0 until the store's collector works it out) and `exclusive_at`, `version` (a `DriveVersion`: `number`, `epoch`), `created_at`. |

- A Drive is one sandbox's at a time: one that another sandbox has is refused (409 `drive_attached`), and so is deleting one that is attached. A keyed instance's Drive goes with its key (409 `key_drive`).
- One that another node holds is brought to the sandbox's node first; while the object store does not hold it as it is yet (503 `copy_behind`), or it could not be brought (503 `drive_not_brought`), the call is `retryable`: the client tries again as its `retries` say, then returns the error, for you to ask again a moment later.
- **Across regions** (slice D9). A Drive's home (`home`) is the region whose object store holds its copy: the region it was made in. A sandbox of another region mounts it too, where that region's machines read its home's store (409 `not_on_one_machine` where they do not): the Drive is let go as a version and taken over there, read from its home's store as its guest reads it, and what its guest writes goes to the store of the region it is in now (`region`). Its home follows it once it has been there for an hour, or at once with `drives.move_home(drive)` (`drive.move_home()`): its machine copies what is left in its home's store into its own, and `home` is the new region once nothing is left there; `DriveInfo::home_move` says how far the move is (`asked_at`, `asked_by`, `copied_objects`, `copied_bytes`, `objects_left`, `error`). Its old home's copy goes once no version kept needs it (a day after). A Drive's home moves once in six hours at the most (409 `home_moved_recently`); one whose home is the region it is in is 409 `home_here`.
- The plan's limits: 3 Drives of at most 5 GiB, 15 GiB together, on Free; 500 of at most 1 TiB on a paid plan (403 `drive_limit_reached`).
- A snapshot outlives its Drive: after the Drive is deleted it is listed, read, forked and mounted read-only by the Drive's id. It is billed for what it keeps alone (`exclusive_bytes`), by the hour, at the Drives' data price ($0.02 a GB-month).
- **A fork is billed by its `used_bytes`, its full logical contents, like any Drive: a fork of a 10 GB snapshot is billed as a 10 GB Drive.**
- A read-only mount of a snapshot: any number of sandboxes, on any machine of the Drive's region, at once, whatever has the Drive and after it is deleted. Its blocks come from the object store as the guest reads them: those cold reads cost nothing, and show under that sandbox in usage (`UsageOptions::sandbox(id)`, `drive_cold_read_bytes`); reads of what that sandbox's machine already holds cost nothing. The guest cannot write it, and a sandbox that has one cannot move to another machine. An app's version mounts a Drive read-write only: read-only snapshot mounts are a sandbox's.
- Where the node copies nothing to an object store, a Drive has no snapshots, forks or restores (409 `not_copied`).
- `UsageOptions::drive(id)`, `kind("drive")` and `group_by(&["drive"])` report what Drives kept, were written and read cold. The events `drive.created`, `drive.deleted`, `drive.attached` and `drive.detached` carry an `EventDrive` or an `EventDriveAttached`.

`client.volumes()` is the API's `/v1/volumes`, the disks underneath Drives, kept for the transition: what only it has is a node that stands alone, whose disks are volumes, and shared volumes, file systems several sandboxes mount at once. A control plane makes no plain volume for a project's key.

| Call | What it does |
|---|---|
| `client.volumes().create_with(&VolumeOptions::new().name("team").shared())`, `volumes.get(id_or_name)`, `volumes.list()`, `vol.delete()` | Makes a volume, finds one, lists them, deletes one. A sandbox mounts one with `CreateOptions::new().volume(VolumeMount::new("/team", vol.id()))`; one that a sandbox has cannot be deleted (409 `volume_in_use`). |

**Backups of volumes.** A backup is a copy of a volume (a Drive is one) at one instant, in the object store, kept until it expires: taken by a call, every day by the volume's rule, or before a service's new version replaces its instance. Unlike a snapshot of a Drive it is a copy of its own, a volume is made from it alone, and it outlives its volume; a volume's backups keep only what changed since the one before, and a block several of them need is billed once, on the earliest. It is `making` until the store has all of it, then `ready`, and billed from then by what the store holds of it (`stored_bytes`) at the price of what sleeping sandboxes keep ([backups](/docs/drive/volumes/#backups)). Backups are a control plane's.

| Call | What it does |
|---|---|
| `client.volumes().backup(id_or_name)`, `backup_with(id_or_name, &BackupOptions::new().expires_in_days(7))`, `vol.backup()`, `client.volumes().backups(id_or_name)` | Takes one now, a `Backup`, kept so many days (1 to 365) or as the volume's rule says (30 days unless it was set); a volume's backups, newest first (a deleted volume's by its id). A node that copies nothing to an object store has none (409 `not_copied`). |
| `client.backups().list()`, `list_of(volume_id)`, `get(id)`, `delete(id)`, `restore(id, Some("data-back"))` | The project's backups, newest first, those of deleted volumes among them; one volume's; one; deletes one (nothing more is billed for it; a volume made from it stays); a new volume made from a ready one, the same as `client.volumes().create_with(&VolumeOptions::new().from_backup(id))` (409 `backup_not_ready` while it is being made, 409 `backup_unusable` once it failed). |
| `b.refresh()`, `b.restore(name)`, `b.delete()` | The same, on a `Backup`, whose `info()` is a `BackupInfo`: `id` (`bak-…`), `volume_id`, `volume_name` (the volume's name then), `status` (`making`, `ready`, `failed`), `reason` (`manual`, `daily`, `before_version`), `consistency` (`frozen`, `crash`), `frozen_ms` (how long the volume's writers waited for the copy; `None` where it was not frozen), `size_bytes` (what the volume held), `volume_size_bytes` (the most it held: what a volume made from it holds), `stored_bytes` (what it is billed for), `own_bytes` (what deleting it would save), `shared_bytes`, `shared`, `region`, `failure`, `created_at`, `ready_at` (from when it is billed), `expires_at`. |

- A volume made from a backup has the size and kind of the volume it was taken of, in the backup's region. Its `status` is `restoring` until it holds the backup whole, then `ready`, and nothing attaches it before; `from_backup` names the backup. Where the machine it was placed on cannot bring it back, the control plane makes it once more on another machine of the region: `restore_attempt` is `Some(2)` then, and `first_failure` says why the first try failed. If that fails too, it is `failed` (`failure`), and can only be deleted.
- `UsageOptions::new().backup(id)`, `kind("backup")` and `group_by(&["backup"])` report what backups kept, on the meter of state (`state_gb_hours`); `meters.state.backups_gb_hours` of `client.billing()` says how much of that meter was backups.

## Domains

A domain of the project's is a name that leads to an app, as its default address does, or to a port of a sandbox. Domains are a control plane's.

| Call | What it does |
|---|---|
| `client.domains().create(domain, &DomainOptions::new().app(…))` or `.sandbox(…).port(…)`, with `.proxied(…)`; `get`, `list()`, `list_of("app_id", app)`, `delete`; `domain.update(&DomainOptions…)`, `domain.refresh()`, `domain.delete()` | A name for an app or a sandbox's port, `pending_verification` until DNS shows a record of `info().verification` ([your own domain](/docs/cube/addresses/#your-own-domain)); 409 `domain_exists` when the project has it. |

## Browser

**Not open yet.** Browser is not open to accounts yet: what follows is the SDK as it stands, ahead of its opening.

A session is a hosted Chromium that a client of the Chrome DevTools Protocol (CDP) drives from outside, at its `cdp_url`: what Playwright's `connectOverCDP` and Puppeteer's `browserURL` take. It is awake while a client is connected and falls asleep, its pages kept, a few seconds after the last one leaves. The addresses carry their credential, so `{:?}` leaves them out.

| Call | What it does |
|---|---|
| `client.browsers().create()`, `create_with(&BrowserOptions::new().name("agent-42"))` | A new session, awake; `BrowserOptions` has `kind` (`chromium-headless`, the default, `chromium`, on a screen, or [`lightpanda`](/docs/browser/#lightpanda), a browser without a layout engine), `name`, `region`, `sleep_after_seconds`, `connection_idle_seconds`, `delete_after_idle_seconds`, `metadata`, `profile(name, save)` and `profile_version(name, version, save)` (a profile of the project's loaded before the session is answered, saved again when it is deleted where `save`), `proxy(url)` (your own HTTP proxy, which takes `CONNECT`, on a paid plan: the session's connections to ports 80 and 443 go out through it by a relay beside the browser, the credentials kept by the platform; 403 `proxy_not_on_plan` on the free plan). The name of one there is answers that one, woken, with its pages. One whose sandbox fails before it runs is no session: its create is refused, 503 `session_failed`. |
| `client.browsers().get(id_or_name)`, `delete(id_or_name)`, `delete_without_saving_profile(id_or_name)` | Finds one; ends it (one made with a profile to save saves it first, unless it is ended without). A `BrowserSession` has `id`, `kind`, `status`, `cdp_url`, `live_url`, `profile` (`name`, `save`, `version`), `proxy` (its own proxy's `url` and `username`, never the password), its times, `awake_seconds`, and `proxy_bytes`, what went through its proxy both ways (`proxy_sent_bytes`, `proxy_received_bytes`). |
| `session.status`, `session.error` | `awake`, `asleep`, `unavailable` (its node cannot be reached) or `failed` (its sandbox failed after its create was answered: its browser stopped and did not come back, say); `error` says why, a `BrowserError` (`code`, `message`, as its node says it), and is `None` unless it failed. The event `browser.failed` says so too: `EventBrowserFailed::of(&event)` reads its data. |

A session is billed by the Cube resources it uses, as any instance is: its CPU while it computes, its memory while it is awake and its traffic out ([pricing and plans](/docs/platform/pricing/)). `session.awake_seconds` is how long it has been awake.

Listing, changing, putting to sleep and new addresses are the Python and TypeScript SDKs' and `glac browsers`'. Sessions are a control plane's.

## Databases

A database is a managed Postgres: a PostgreSQL of its own on a Drive, asleep when nothing asks anything of it and woken by a connection, its sessions kept. The owner's password is in the answer of `create` and of `reset_password` alone, and kept nowhere: `connection_string()` of the `Database` one of those returned has it.

| Call | What it does |
|---|---|
| `client.databases().create("shop")`, `create_with("shop", &DatabaseOptions::new().version("18"))` | Makes one and waits for its first start (`status` `ready`, or `creating`: `get` it until it is ready); `DatabaseOptions` has `version`, `region`, `database_name`, `size(vcpus, memory_bytes)`, `storage(size_bytes, durability)`, `sleep_after_seconds`, `suspend_after_seconds` (paused, a connection answered in a millisecond or two, before its memory is saved and it sleeps for real: 1 to 86400, 300 by default), `wake_daily_at("03:30")` (woken every day then while it rests), `metadata`. The name of one there is answers that one, without its password. `databases.set_suspend_after(db, Some(n))` and `set_wake_daily_at(db, Some("04:00"))` change these two, every branch's at once; `None` takes either back (to 300, and to none). On a Free plan a database's rest is fixed, as Neon's Free scales to zero: paused a second after its last query (`sleep_after_seconds` 1) and asleep five minutes later (`suspend_after_seconds` 300); another value is refused 400 `invalid_field`, on a create and on a change. |
| `client.databases().get(id_or_name)`, `list()`, `list_named(name)`, `delete(id_or_name, final_snapshot)` | Finds one; lists them; deletes one with its branches (a snapshot of its Drive kept seven days unless `final_snapshot` is false). |
| `client.databases().branches(db)`, `branch(db, "main")`, `sleep(db, "main")`, `wake(db, "main")`, `reset_password(db, None)` | Its branches (`main` first, then its own), one of them, a branch put to sleep or woken now, and a new password for its owner, in that answer alone. |
| `client.databases().create_branch(db, "preview", &DatabaseBranchOptions::new().parent("main").expires_at(t))`, `delete_branch(db, branch)` | A branch of its own: its parent (`main` unless given) as it is now, nothing copied, with a PostgreSQL, an endpoint and a Drive of its own, at `<database>-<name>` on the project's network, deleted by itself at its expiry where one is given; its roles and passwords are its parent's (`branch.connection_string(Some(owner_password))`). A delete stops its PostgreSQL and deletes its Drive; not `main` (409 `root_branch`), nor a branch others were made of (409 `has_branches`). |
| `DatabaseOptions::new().history_seconds(n)`, `databases.set_history(db, n)`, `databases.restore(db, t)`, `databases.restore_exactly(db, t)`, `DatabaseBranchOptions::new().at(t)`, `at_exactly(t)` | Its history (slices DB8 and DB5): how far back its root branch can be restored, or branched from, by a time: a day unless given; 0 (none) to 30 days on a paid plan, a day on Free. A restore takes the root branch back in place: to a whole minute or a version's own moment, the newest version of its Drive's window at or before it (one every 30 seconds in which it was written, a day of it at the most); further back, to the second, or `exactly`, the moment itself, to the millisecond, by its WAL archive (its WAL replayed to it: seconds to minutes, the call waits). Its endpoint, its connection strings and its owner's password stay what they were, its connections drop, and its state before is kept as a branch of its own, `main_old_<the restore's moment>`; one whose new version does not serve within five minutes is undone (503 `database_restore_failed`). A branch of a time is made of that moment instead (`from: {at, exact}`). A time its history does not have is 400 `invalid_history`, its message saying from when the window and the archive reach. A time to the second (or `exact`) is the archive's or refused, never the window's version before it: 400 `invalid_history` where the archive does not reach it (a database that keeps none, or a time before its oldest base), 503 `database_archive_unavailable` (retryable) while the archive's store refuses its segments; each refusal names the window's version at or before the time, whose own moment can be asked for instead. One whose blocks the store does not give is refused 503 `drive_unreadable` (retryable), nothing made. An outage of the object store long enough that more of its WAL waited than its Drive keeps for the log gives that WAL up, so that the database stays up: a gap of its archive, in `history.gaps` (`DatabaseHistoryGap`: `from`, `to`, `from_lsn`, `to_lsn`): when the WAL given up began, until when the archive restores no time (the end of the first base taken after it; null until there is one), and where in the log it begins and ends. A time in a gap is restored only from its Drive's window (a whole minute, or a version's own moment); to the second, or exact, it is 400 `invalid_history`. The gap is said as events too: `database.history_gap` when it is first found (once a gap, while the database is awake), and `database.history_resumed` when the archive restores again after it; `EventDatabaseGap::of(&event)` reads their data (None for an event of another type): the database, the gap's `from`, `to` (None of the first), `from_lsn` and `to_lsn`, `segments` (how many segments of 16 MB were given up) and, of the first, `error` (what the object store's last refusal said). `Database::history_seconds`, `history`. |
| `DatabaseOptions::new().tiering(true)`, `databases.set_tiering(db, on)` | Its tiered storage on or off (slice DB18: a paid plan, where the object gateway serves; off is refused while a branch has partitions tiered, 409 `tiered_data_exists`; each branch's PostgreSQL restarts once for it). `Database::tiering` says whether it is on and what it bills by now (`tiered_bytes`). |
| `client.databases().roles(db)`, `reset_role_password(db, role)` | The roles of its root branch that log in, read from PostgreSQL itself (`DatabaseRole`: `name`, `owner`): its owner and the roles you made (`CREATE ROLE … LOGIN`), the platform's not among them; and a new password for any of them, in that answer alone: a `DatabaseRoleSecret` with the role's `password` and the root branch's connection strings of that role (`connection_string()`); the owner's is made of the database the API answers. A branch of its own keeps the password it was made with. |
| `db.connection_string()`, `branch.connection_string(Some(password))` | What tokio-postgres, sqlx and psql take: the public one where the API gives one, else the one on the project's network, with the owner's password (percent-encoded). `db.default_branch` has `connection_uri`, `pooled_uri`, `private_uri`, `endpoint` and `state`. |

A database is reached on the project's network, from its sandboxes (made with `project_network`) and its services, at its name: that is its `private_uri`. Where an edge serves PostgreSQL it is reached from anywhere at its public address too (`connection_uri`, port 5432, TLS alone; the pooler's: `pooled_uri`); they are None where none does, or where the database has no region to be named under, and the connection string takes them where they are given. `{:?}` of a database or a branch shows neither the password nor a connection string with it. Databases are a control plane's.

## Managed Applications

An application of the catalogue ([Rivet](/docs/managed-applications/rivet/), say) is installed in the project as its own Cube resources: its apps, Volumes, secrets and buckets, labelled with the installation, changed through it alone, and billed as they are ([Managed Applications](/docs/managed-applications/)). An install's answer has every output, the secret ones too (an admin token, an endpoint with it in), and a read shows those to a key with the `admin` scope alone: an installation object keeps each output an earlier answer gave that a later one hides.

```rust
let rivet = client.catalogue().get("rivet", None)?;       // its parameters, and a month of it in Cube's meters
println!("{:?}", rivet.month);
let engine = client.installations().create("rivet", &InstallationOptions::new().parameters(json!({"disk_gib": 20})))?;
println!("{}", engine.info().outputs["endpoint"]);        // RIVET_ENDPOINT, its token in it
```

| Call | What it does |
|---|---|
| `client.catalogue().list()`, `client.catalogue().get(app, version)` | The catalogue's applications, each a `CatalogueApp` (`app`, `version`, `title`, `summary`, `verified`, `licence`, `versions`, `parameters`: a JSON Schema, `outputs`, `month`, and the entry whole in `raw`); one, at its newest version or the one named, with its definition in `raw`. |
| `client.installations().create(app, &InstallationOptions::new().name(..).version(..).region(..).parameters(..).requires(name, installation).no_wait())` | Installs it, and waits until it is ready (`no_wait`: at once). One that failed is an error of kind and code `installation_failed`, with its words. |
| `client.installations().list(app)`, `client.installations().get(id_or_name)` | The project's installations, the newest first (`None`: all); one. |
| `installation.update(&InstallationUpdate::new().version(..).parameters(..))`, `delete()`, `refresh()`, `wait()`, `wait_for(limit)` | Another version, or its parameters as a merge patch (null takes one back to its default); deleted with everything it is made of (`status()`: `deleted`, or `deleting`); `wait_for` ends with `wait_timeout` and the installation goes on. |
| `installation.id()`, `name()`, `status()`, `info()` | As the API says them: `info()` has its `outputs`, `secret_outputs`, `parameters`, `apps`, `volumes`, `buckets`, `requires`, `failure`. |

Managed Applications are a control plane's.

## Secrets and variables

| Call | What it does |
|---|---|
| `client.secrets()`: `put_with("DB_URL", &url, Some(&["db.example.com"]))`, `put`, `update(name, hosts)`, `list`, `delete` | Values the API keeps under names and never gives back, and the hosts each may be sent to: an app's environment, an image pull secret, a sandbox's egress rules. |
| `client.variables()`: `put(name, value)`, `list`, `delete` | The project's shared variables, which a service's `env` refers to (`"${{ shared.REGION }}"`). A control plane's. |

## The project, the account and the bill

| Call | What it does |
|---|---|
| `client.account()`, `client.update_account(&AccountOptions)` | The account: its month of traffic to the internet, and where that traffic stops; where its notices go (`email`, which `AccountOptions::new().email(…)` sets; `email_verified`, and `email_undeliverable`, an `EmailUndeliverable`, while mail to it bounces: see [where notices go](/docs/platform/projects/#where-notices-go)); the language of its notices (`language`, an `AccountLanguage`: `code` "en", "de" or "fr", and its `source`; `AccountOptions::new().language("de")`, or `no_language()` to follow the billing address again), its billing address and tax id; and behind a control plane `keeps` (an `Option<AccountKeeps>`): what the key's project keeps of Drives and volumes, by the numbers a create is held to, each with what it has (`volumes`, `volume_bytes`, `volumes_bytes`, whose `limit` is `None` for no limit, and `unsized_bytes`: see [raising limits](/docs/platform/raising-limits/)). |
| `client.usage_report(&UsageOptions)`, `client.usage(&ListOptions)` | What was used, by the hour's books, in groups; what each sandbox used. |
| `client.billing()`, `client.update_billing(&BillingOptions)`, `client.balance()`, `client.update_balance(&BalanceOptions)`, `client.top_up(usd)`, `client.top_up_with(usd, &TopUpOptions)`, `client.charges()`, `client.ledger()` | The plan and the bill, the balance, auto reload and top-ups, the charges and the ledger. A control plane's. |
| `client.project()`, `client.events_page(&EventsOptions)` | The project of the key, and a page of its events. A control plane's. |

**The data of an event.** Every type of event the control plane has has a type of its data in this crate, named after the description's schema of it, whose `of(&event)` reads an event of its types and is None of another's (`glac::EventDatabase::of(&e)`). A database's: `EventDatabase` (`database.created`, with its `region` and PostgreSQL `version`; `database.deleted`, with `final_snapshot_id`, the snapshot of its Drive kept seven days), `EventDatabaseBranch` (`database.branch_created`, with its `parent`; `database.branch_deleted`, with its `reason`), `EventDatabaseRestored` (`database.restored`: the moment `at`, and `old_branch_id`, the branch the state before is kept as), `EventDatabaseArchive` (`database.archive_failing`: `since`, how many segments in a row `failures`, `archived_until`, how far a restore reaches meanwhile, and the object store's `error`; `database.archive_recovered`: `recovered_at`) and `EventDatabaseGap`. The others likewise: a sandbox's (`EventSandboxSlept`, `EventSandboxWoke`, `EventSandboxMoved`, `EventSandboxDeleted`, …), an app's and its keys' (`EventApp`, `EventAppFailed`, `EventKeyCreated`, …), the project's deploys and key, backups, domains, destinations and Drives' snapshots (`EventProjectDeployed`, `EventBackup`, `EventDomain`, `EventDestination`, `EventDriveSnapshot`, …), and the account's plan, top-ups, refunds, withdrawals, balance, Credits, storage, egress cap, spend limits, hold and debts (`EventSubscriptionPeriod`, `EventTopupCollected`, `EventWithdrawalReceived`, `EventBalance`, `EventInDebt`, …). A field that not every event of a type has, or that is null, is an `Option`.


**Webhooks, API keys, spend limits, the project.** `client.webhooks().create_with(url, &WebhookOptions::new().events(&[…]).enabled(true))` sends the project's events to an address of yours (the `secret` that signs each delivery is in that answer alone); `get`, `list`, `update`, `delete`. `client.keys().create_with(&KeyOptions::new().name(…).scopes(&[…]))` makes an API key (the key itself, `key`, is in that answer alone); `get`, `list`, `delete`. `client.limits()` and `client.update_limits(Some(50.0))` are the project's spend limit and what was spent this month (`None` takes the limit away), and `sbx.limits()`, `sbx.update_limits(…)` a sandbox's own. `client.request_limit(limit, wanted, why)` asks for one of the account's [limits raised on request](/docs/platform/raising-limits/) (a cap by its name, `"volumes"` or `"volume_bytes"`; bytes of the two in bytes; 409 `limit_request_pending` while one of the same limit waits), and `client.limit_requests(limit, cursor)` and `client.limit_request(id)` read them with the operator's answers (`LimitRequest`: `status` `pending`, `granted` or `refused`, `granted`, `answer`). `EventInstanceRestarted::of(&event)`, `EventInstanceUpgrade::of` (`instance.upgraded`, `.reverted`, `.upgrade_failed`) and `EventLimitRequest::of` read those events' data; `instance.start_command()` (a sandbox's `info().start_command`) says how its start command runs, how often it was started again in its machine, and how it last ended. `client.update_project(Some(30))` sets after how many days asleep its sandboxes are deleted (`None`: never). A control plane's. Webhooks and API keys need a key with the `admin` scope, and so do setting the project's limit and `update_project`; setting a sandbox's limit needs `write`.

**Log destinations, the audit log, the billing documents.** `client.destinations()` is where the logs (and the metrics and the requests' traces: `.signals(&["logs", "traces"])`) of the project's apps are exported (OpenTelemetry endpoints): `create(name, &DestinationOptions::new().endpoint(u).header(name, value))`, which tries it at once with one record (`status.connected`), `get`, `list`, `update`, `delete`, `test` (one record now); a header's value is a credential, sent when a destination is made or changed and in no answer (what is returned has the headers' names alone). `client.audit_page(&ListOptions::new().limit(n))` is a page of the project's audit log, the newest first (who, what method, what path, what status): every call that was no reading, a refused one too, and every reading of an app's log by an operator. `client.statement(Some("2026-09"))` is a month's statement (`None` is this month's) with each database's own line in it (`databases`: what it used in the month, its history and its tiered data apart, and what that comes to at the list prices), `client.invoices()` the invoices at Stripe (with the PDF's link), `client.notices()` the mail the account was sent, `client.withdrawals(&ListOptions::new())` what it may withdraw from now and the withdrawals it made (a consumer in the EEA or the UK may withdraw from a purchase within 14 days), and `client.withdraw(charge_id, name, Some(email))` the buyer's own statement of withdrawal, received at once. A control plane's. Making, changing, testing and deleting a destination, reading the audit log and withdrawing need a key with the `admin` scope; the rest, one that may read.

**Buying at once (`start_now`).** A consumer in the European Economic Area or the United Kingdom (an account with no tax id that is verified or being verified) may withdraw from a purchase within 14 days, and what it buys is provided at once only at its own express request. `start_now()` carries that request: `client.top_up_with(20.0, &TopUpOptions::new().start_now())`, `BillingOptions::new().plan("p20").start_now()` (a plan that is bought: from Free, or a move up) and `BalanceOptions::new().auto_reload(true).start_now()` (for every auto reload while auto reload stays on), in the words the console shows beside its box (and `GET /v1/billing/withdrawals` has, `right.start_now`):

> I ask for this purchase to be provided at once, within the 14 days in which I may withdraw from it. If I withdraw, I pay for what was provided until then. I understand that once all the Credits of a top-up are used, it has been provided in full and I can no longer withdraw from it.

The service starts now; within the 14 days the buyer may still withdraw, and pays for what was provided until then; once it is fully provided (a top-up whose Credits are all used), the right to withdraw is lost. Give it only when the person buying asks for that: the SDK never sends it unless it is given. Without it, such an account is refused: an `Error` of status 400, code `start_now_required`, `param()` `start_now`, in words that name its country and quote the request, and nothing is bought. An account whose auto reload is on without the request reloads nothing, and is told once a month (the event `auto_reload.no_request`, read with `EventAutoReloadNoRequest::of`; an account with no card on record, `auto_reload.no_card` and `EventAutoReloadNoCard`).

## Errors

A non-zero exit code is a result: read `res.exit_code`. An error of the API is a `glac::Error` with `status()`, `kind()`, `code()`, `param()`, `retryable()`, `request_id()` and `message()`, and `docs_url()`, which leads to the code on the [errors](/docs/errors/) page. No connection or a timeout is one too, with `status()` `None`; `is_timeout()` tells a timeout. Errors about money (402 `account_in_debt`, 403 `trust_limit_exceeded`, 409 `no_card`, 400 `start_now_required`, …) carry the control plane's own message, which says what lifts them.

## Behaviour worth knowing

- **Sleeping sandboxes.** No call fails because a sandbox sleeps or is starting: it waits and goes on. `res.wake` says how long `run` waited for a wake; `on_response` on the client sees it for every call.
- **Retries.** No answer, or a `retryable` error, is retried twice (`retries`), from 0.2 s doubling. Every `POST` carries an `Idempotency-Key`; `idempotency_key(key)` lets a program that restarts get back what it made.
- **Timeouts.** `timeout` (15 minutes unless you say) is how long to wait for the API; `RunOptions::timeout` is the command's own limit.
- **Threads.** A `Client` may be shared between threads, and its products' handles use its connections; read-only calls on a `Sandbox` take `&self`. In tokio, use `tokio::task::spawn_blocking(move || sbx.run("make")).await??` until there is an async version.
- **HTTPS** uses the Mozilla root certificates built in; `SSL_CERT_FILE` adds your own. It has so far run against plain-HTTP development machines only.

Source: https://glac.ai/docs/sdks/rust/index.mdx
