The order of preference
Before each call the client picks the cheapest thing that will work.
| State | What happens |
|---|---|
| A cached JWT that has not expired | used as-is — no network |
| Expired, but a refresh token is cached | renewed, then used |
| Refresh fails, or nothing is cached | the key is exchanged |
| No key and no cached session | the constructor refused long before this |
Expiry is read from the token itself, not guessed from a timer, so a process that was asleep for a day behaves the same as one that was busy.
What is cached
{ jwt, refreshToken, sessionId, storageId }# Stored in ~/.iagenify/session (or your session_path / storage)
{"jwt": ..., "refresh_token": ..., "session_id": ..., "storage_id": ...}storageId is how a machine keeps the same identity across restarts: it is sent back on the next exchange so the same machine is recognised rather than registered twice.
await api.session();
// { id, storageId } — or null when nothing has been exchanged yetapi.session()
# {"id", "storageId"} — or None when nothing has been exchanged yetConcurrent first calls
Fire ten calls at once on a cold client and there is one exchange, not ten. The deduplication is keyed by the key and the appName, and it holds across client instances in the same process — which is what makes a double render harmless.
// One exchange, ten calls
await Promise.all([
api.getUser(),
api.catalogue(),
api.storage.list(),
api.keys.list(),
/* … */
]);# One exchange, ten calls: the first call exchanges the key, the others reuse it
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor() as pool:
user, prices, storages, keys = pool.map(lambda call: call(), [
api.get_user,
api.catalogue,
api.storage.list,
api.keys.list,
])Ending a session
await api.auth.logout(); // this session
await api.auth.revokeSession(id); // another one, by idapi.auth.logout() # this session
api.auth.revoke_session(session_id) # another one, by idA session ends; the key still works and the next call exchanges it again. To stop a key entirely, revoke the key.