api.storage

device()

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.

POST /api/storage/devicefreesame deviceId, same storage
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

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

deviceIdstringrequired

A random identifier the page keeps. Missing → the SDK throws.

namestring

The display name. Derived from the user agent when absent.

userAgentstring

The phone's user agent, used for that name.

The same deviceId is the same storage

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.

// 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;
}
# 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
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

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

Its files are not on the account

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.

appName separates two apps on one phone

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.

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

Errors

CodeStatusWhen
— (thrown locally)—No deviceId passed.
unauthorized401No valid session or key — the call is your server's, not the phone's.