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
}idstringWhat revokeSession() takes.
storageIdstring|nullWhich 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 cache | What happens |
|---|---|
| A session id is cached | returned straight away — no network |
| A token is cached but no id | the active sessions are listed, and the one bound to the same storage is matched |
| That listing fails | null — the failure is swallowed, not thrown |
| Nothing is cached | null, 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.
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
storageIdto 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.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 idcurrent = api.session()
api.auth.logout() # this one
api.auth.revoke_session(session_id) # another, by idNote 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.