Client

session()

api.session() → Promise<{ id, storageId } | null>

Which session this client is using. It reads the cache first, and asks the server only when the cache cannot say.

cache firstnever throwsnull before the first exchange
Using Python?

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

Returns

{
  id: "…",          // the session id
  storageId: "…"    // the storage this session is bound to, or null
}
{
    "id": "…",          # the session id
    "storageId": "…",   # the storage this session is bound to, or None
}
idstring

What revokeSession() takes.

storageIdstring|null

Which storage the server recognised this process as. For a machine, this is how it keeps one identity across restarts.

How it answers

State of the cacheWhat happens
A session id is cachedreturned straight away — no network
A token is cached but no idthe active sessions are listed, and the one bound to the same storage is matched
That listing failsnull — the failure is swallowed, not thrown
Nothing is cachednull, and nothing is exchanged to find out

The second row is why this method can be slower than it looks on a client restored from an older cache. The first row is the normal case.

It does not create a session, and it never throws

On a cold client it answers null. Make any ordinary call first — getUser() is the cheapest — and the exchange happens there. Because it swallows its own failure, a null never tells you the network is down; it tells you the method could not name a session.

const fresh = new IaGenify({ apiKey });

await fresh.session();      // null — nothing has been exchanged
await fresh.getUser();      // this is what exchanges
await fresh.session();      // { id, storageId }
fresh = IaGenify(api_key=api_key)

fresh.session()     # None — nothing has been exchanged
fresh.get_user()    # this is what exchanges
fresh.session()     # {"id", "storageId"}

What it is for

  • Showing which session a process is running as — in a dashboard, or in one log line at boot.
  • Passing the id to revokeSession(), including to end this very session from somewhere else.
  • Reading storageId to confirm the server recognised this machine as the one you expected, rather than registering a second.

One line at boot

const [user, session] = await Promise.all([api.getUser(), api.session()]);

console.log(
  `iagenify · ${user?.email} · session ${session?.id ?? "none"} · storage ${session?.storageId ?? "none"}`,
);
user, session = api.get_user(), api.session()

print(
    f"iagenify · {(user or {}).get('email')} · "
    f"session {(session or {}).get('id', 'none')} · storage {(session or {}).get('storageId') or 'none'}"
)

Confirming one machine, not many

A machine keeps the same identity by sending its storageId back on the next exchange. When a deployment loses its session cache on every restart, each boot registers a new one — and that shows up as a pile of near-identical storages.

const before = (await api.session())?.storageId;

// … restart the process, with the same sessionPath …

const after = (await api.session())?.storageId;
// Same value: one machine. A different one: the session cache did not survive.
before = (api.session() or {}).get("storageId")

# … restart the process, with the same session_path …

after = (api.session() or {}).get("storageId")
# Same value: one machine. A different one: the session cache did not survive.
A container with no persistent session path registers once per boot

Mount the session path, or pass a storage you control. Otherwise each restart is a new machine to the server, and the identity you were relying on changes under you.

Where sessions do not persist

In a runtime without durable storage the session lives in memory, for as long as the isolate does — so session() answers for this isolate and nothing more. That is a property of the store, not of this method, and a store you supply changes it.

Ending it

const current = await api.session();

await api.auth.logout();              // this one
await api.auth.revokeSession(id);     // another, by id
current = api.session()

api.auth.logout()                    # this one
api.auth.revoke_session(session_id)  # another, by id

Note the asymmetry: this method gives you your id. Another machine's id is not something the SDK lists — when you want a machine shut out, revoke the key it holds.