Parameters
idstringrequiredThe session id. Yours comes from api.session().
Returns
{ ok: true }{"ok": True}Errors
| Code | Status | When |
|---|---|---|
| session_not_found | 404 | No active session of this account carries that id. |
A session belonging to another account answers the same 404. The lookup is scoped to the caller, so one account cannot discover — or end — another's sessions, and the refusal says nothing about whether that id exists elsewhere.
Revoking twice
The second call answers 404, not { ok: true }: only an active session matches. When all you wanted was for the session to be gone, that 404 is success.
import { IaGenifyError } from "iagenify";
async function ensureRevoked(api, id) {
try {
await api.auth.revokeSession(id);
return "revoked";
} catch (err) {
if (err instanceof IaGenifyError && err.status === 404) return "already gone";
throw err;
}
}from iagenify import IaGenifyError
def ensure_revoked(api, session_id):
try:
api.auth.revoke_session(session_id)
return "revoked"
except IaGenifyError as error:
if error.status == 404:
return "already gone"
raiseRevoking your own session
Nothing stops you: pass the id api.session() gave you and this client's session ends. The effect is logout()'s, reached from the other direction — and the same thing follows, namely that the next call exchanges the key and carries on.
const mine = await api.session();
await api.auth.revokeSession(mine.id); // same effect as api.auth.logout()mine = api.session()
api.auth.revoke_session(mine["id"]) # same effect as api.auth.logout()Where another session's id comes from
Not from the SDK. This resource ends a session by id; it does not enumerate them. In practice that leaves two honest patterns.
- Record it where the session is made. A process that knows its own id at boot can publish it somewhere your operator tooling reads.
- Revoke the key instead. When you cannot name the session, name the key — and the machine cannot come back either, which is usually the actual goal.
// At boot, each worker records who it is
const me = await api.session();
await registry.set(`worker:${process.env.HOSTNAME}`, me.id);
// Later, from your operator tool
const id = await registry.get(`worker:${host}`);
if (id) await api.auth.revokeSession(id);import os
# At boot, each worker records who it is
me = api.session()
registry.set(f"worker:{os.environ['HOSTNAME']}", me["id"])
# Later, from your operator tool
session_id = registry.get(f"worker:{host}")
if session_id:
api.auth.revoke_session(session_id)A process still holding the key exchanges it again and comes back, under a new session. When a machine should not return, revoke the key it holds — and revoke the key first.
The order, when you do both
// Key first: it closes the door.
await api.keys.revoke(keyId);
// Session second: it removes whoever is already inside.
await api.auth.revokeSession(sessionId);# Key first: it closes the door.
api.keys.revoke(key_id)
# Session second: it removes whoever is already inside.
api.auth.revoke_session(session_id)Reversed, there is a window in which the still-valid key exchanges a fresh session and the machine is back before you have finished.