# usage

Canonical URL: https://developers.iagenify.com/sdk/ref/connected-storage/run/usage/
Language: en

`storage.run({ action: "usage" })`

How much space this storage is taking. The number to read before a write fails for lack of room.

Status: any storage · free · a reading

```javascript
await storage.run({ action: "usage" });
```

## Why ask before writing {#why}

A write past the plan's space is refused with `quota_exceeded`. Reads and deletes keep working — that asymmetry is deliberate, so you can always get data out and make room — but a write that fails halfway through a batch leaves you to work out what landed.

```javascript
const before = await storage.run({ action: "usage" });

// Write in batches, and stop on the first refusal rather than pushing through
for (const batch of batches) {
  try {
    await storage.run({ action: "insert", collection, documents: JSON.stringify(batch) });
  } catch (err) {
    if (err.code === "quota_exceeded") break;
    throw err;
  }
}
```

## This storage, or the account {#account}

| Question | Ask |
| --- | --- |
| How full is this one? | run({ action: "usage" }) |
| What does the plan give, across services? | api.cloud.usage() |
| Which files are taking the space? | api.files.list(), and sort by size |

The account-level view is the one that tells you whether buying space would help, because that is where the plan's allowance lives.

- [api.cloud.usage()](/sdk/ref/cloud/usage): L'espace du compte, service par service.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
storage.run(action="usage")
```

```python
import json
from iagenify import IaGenifyError

before = storage.run(action="usage")

# Write in batches, and stop on the first refusal rather than pushing through
for batch in batches:
    try:
        storage.run(action="insert", collection=collection, documents=json.dumps(batch))
    except IaGenifyError as error:
        if error.code == "quota_exceeded":
            break
        raise
```
