# device()

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

`api.storage.device({ deviceId, name, userAgent }) → Promise<ConnectedStorage>`

Registers a phone or a tablet as a storage. Called from your server, because the phone never holds the key.

Status: POST /api/storage/device · free · same deviceId, same storage

A computer registers itself: the SDK runs there, exchanges the key, and the machine becomes a storage. A phone cannot — the SDK is not on it and must not be, because the key would be. So the page sends an identifier to your server, and your server calls this.

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `deviceId` | string | required | A random identifier the page keeps. Missing → the SDK throws. |
| `name` | string |  | The display name. Derived from the user agent when absent. |
| `userAgent` | string |  | The phone's user agent, used for that name. |

## The same deviceId is the same storage {#idempotent}

Calling it again with an identifier already seen returns the existing storage rather than making another. So the page can call it on every load without piling up registrations — and two simultaneous calls still produce one.

```javascript
// In the page: an identifier that survives reloads
let deviceId = localStorage.getItem("device");
if (!deviceId) {
  deviceId = `dev_${crypto.randomUUID()}`;
  localStorage.setItem("device", deviceId);
}

// On your server, where the key is
export async function registerPhone(deviceId, userAgent) {
  const phone = await api.storage.device({ deviceId, userAgent });
  return phone.id;
}
```

> **Generate the identifier, never derive it**
>
> A value built from the user agent, the screen or an account is the same for many people — and whoever sends it gets that storage. Random, kept in the browser, is what makes it one device.

## Returns {#returns}

```javascript
phone.id;
phone.type;       // "phone"
phone.provider;   // "browser"
phone.deviceId;   // the identifier you passed
```

## Its files are not on the account {#files}

> **A phone keeps its own files, in its own browser**
>
> Saving to it through the server is refused with storage_is_local. Reading and writing them happens in the page, which is where they are — your server relays the request and the page answers.

That is also what makes a phone a sensible place for an agent to work: nothing is uploaded to be read. See [the files bridge](/sdk/agent/bridges/files).

## appName separates two apps on one phone {#appname}

A storage is identified by the account, the device and the `appName` the client was built with. Two apps on one phone are two storages — which is usually what you want, since their files have nothing to do with each other.

```javascript
const api = new IaGenify({ apiKey, appName: "field-notes" });
await api.storage.device({ deviceId });   // this app's storage on this phone
```

## Errors {#errors}

| Code | Status | When |
| --- | --- | --- |
| — (thrown locally) | — | No deviceId passed. |
| unauthorized | 401 | No valid session or key — the call is your server's, not the phone's. |

- [Phone](/sdk/ref/providers/phone): What a phone storage can and cannot do.
- [The files bridge](/sdk/agent/bridges/files): Letting an agent work on files it cannot reach directly.

```python
# In the page (JavaScript): an identifier that survives reloads
#   localStorage.getItem("device") || `dev_${crypto.randomUUID()}`

# On your Python server, where the key is
def register_phone(device_id, user_agent):
    phone = api.storage.device(device_id=device_id, user_agent=user_agent)
    return phone.id
```

```python
phone.id
phone.type       # "phone"
phone.provider   # "browser"
```

```python
api = IaGenify(api_key=api_key, app_name="field-notes")
api.storage.device(device_id=device_id)   # this app's storage on this phone
```
