# getStorage()

Canonical URL: https://developers.iagenify.com/sdk/ref/iagenify/get-storage/
Language: en

`api.getStorage() → Promise<Storage | null>`

The account's default storage, as four plain fields. Where a save with no target goes.

Status: GET /api/storage/default · free · a plain object

## Returns {#returns}

```javascript
{
  id: "…",
  label: "Object Storage",
  type: "object",
  tier: "free"
}
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | What you pass as `storageId` to anything that writes. |
| `label` | string |  | The display name. Yours to change, not to match on. |
| `type` | string |  | What kind of storage it is — see [below](#types). This is the field to branch on. |
| `tier` | string |  | The storage's tier. |

Every account is created with its own object storage, and that is the one carrying the default flag — so this call normally answers with somewhere you can actually write.

## type, and why it decides everything {#types}

| type | What it is | Files live |
| --- | --- | --- |
| object | An object storage: bytes under keys. | On the account |
| database | A connected database, read and written through run(). | On the account |
| filesystem | A computer. Its files are on that machine. | On the machine, under ~/.iagenify/files |
| phone | A registered phone. Its files are in its own browser. | In that browser |
| browser | A browser store. | In that browser |

> **A computer and a phone keep no bytes on the account**
>
> Saving to one through the server is refused with storage_is_local — not because it failed, but because those files only exist on the device. Read and write them from the device, through the SDK running there or through a bridge.

## The three things you may actually want {#versus}

```javascript
await api.getStorage();                      // the default, as plain fields

const target = await api.storage.get();      // the default, with run() and files on it
const one = await api.storage.get({ id });   // a particular storage
const all = await api.storage.list();        // every storage on the account
```

> **This is not a ConnectedStorage**
>
> Four fields, no methods. Use this call to display which storage is the default; use api.storage.get() when you intend to do something with it.

`api.storage.get()` reads the same route and hands back a [ConnectedStorage](/sdk/ref/connected-storage) — the object that carries `run()`, and `files` when the storage is a machine.

## What the default flag actually decides {#default}

- A save with no `storageId` goes there.
- It is a property of the account, not of your client: changing machines does not change it.
- Exactly one active storage carries it. Delete that storage and the flag is handed to another — it is never left nowhere.
- It does **not** decide where an agent works. An agent works on the device it was given, and that is a separate choice.

## When it is null {#null}

`null` means no active storage carries the flag. Since deleting the holder hands the flag on, a `null` is unusual enough to look at rather than retry.

```javascript
const target = await api.getStorage();

if (!target) {
  const all = await api.storage.list();
  throw new Error(`no default storage; ${all.length} storage(s) on the account`);
}

if (target.type === "filesystem" || target.type === "phone") {
  // Saving here through the server will be refused: this device keeps its own files.
}
```

## Writing to a named storage instead {#pattern}

Relying on the default is fine for one storage and fragile for several: the flag can move. When a process must always write to the same place, resolve it by label once and keep the id.

```javascript
const all = await api.storage.list();
const archive = all.find((s) => s.label === "Archive" && s.type === "object");
if (!archive) throw new Error("the Archive storage is not connected");

// Keep archive.id in configuration, and pass it explicitly from then on.
```

- [Machines are storages](/sdk/concepts/machines-are-storages): Why the computer you are on is one of them.
- [api.storage](/sdk/ref/storage): Connecting one, creating one, registering a device.

```python
{
    "id": "…",
    "label": "Object Storage",
    "type": "object",
    "tier": "free",
}
```

```python
api.get_storage()                      # the default, as plain fields

target = api.storage.get()             # the default, with run() and files on it
one = api.storage.get(id=storage_id)   # a particular storage
every = api.storage.list()             # every storage on the account
```

```python
target = api.get_storage()

if target is None:
    every = api.storage.list()
    raise RuntimeError(f"no default storage; {len(every)} storage(s) on the account")

if target["type"] in ("filesystem", "phone"):
    pass  # Saving here through the server will be refused: this device keeps its own files.
```

```python
archive = next((s for s in api.storage.list() if s.label == "Archive" and s.type == "object"), None)
if archive is None:
    raise RuntimeError("the Archive storage is not connected")

# Keep archive.id in configuration, and pass it explicitly from then on.
```
