api.auth

logout()

api.auth.logout() → Promise<{ ok: true }>

Ends the session this client is using. The key is untouched, so the very next call starts a new one.

POST /api/auth/logoutfreethis session only
Using Python?

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

Returns

{ ok: true }
{"ok": True}

There is nothing to pass: the session is identified from the token you are already sending. Its refresh token stops being renewable at the same moment — this is not a token that expires later, it is a session that is over.

What happens on the next call

The cached token is no longer accepted, the refresh fails, and the key is exchanged. Your code keeps working, under a new session. That is rarely what someone calling logout() has in mind, so be deliberate about which of the three you want.

await api.auth.logout();

await api.getUser();   // works — a different session now
api.auth.logout()

api.get_user()   # works — a different session now
What you wantCall
This process to stop being this sessionapi.auth.logout()
This key to stop working anywhereapi.keys.revoke(id)
Another device to be signed outapi.auth.revokeSession(id)

Calling it twice

The second call is made under the session the first one caused, so it answers { ok: true } again — and ends that one too. It is not an error, and it is not a no-op: each call ends whatever session is current.

When it is the right call

  • A short-lived job that has finished, and you would rather not leave a session alive behind it.
  • A page that signs a visitor out, where the session is the visitor's and not your server's.
  • A machine being decommissioned — together with revoking the key it holds.

And when it is not: as cleanup in a long-running server. There, the session is the thing making your calls cheap — ending it on every shutdown just means exchanging the key again on the next boot.

Ending a job's session cleanly

try {
  await doTheWork(api);
} finally {
  // Best effort: the work is done either way, and a failed logout
  // must not become the error the caller sees.
  await api.auth.logout().catch(() => {});
}
from iagenify import IaGenifyError

try:
    do_the_work(api)
finally:
    # Best effort: the work is done either way, and a failed logout
    # must not become the error the caller sees.
    try:
        api.auth.logout()
    except IaGenifyError:
        pass
In a browser, clear what is cached too

The session was kept in the page's own store. Ending it server-side leaves a dead entry there, which the next call will try before exchanging. Replace the client, or clear the store.

await api.auth.logout();

// The page keeps its own copy. Clear it, or the next call tries a dead token first.
await myStore.clear();
api.auth.logout()

# A custom store keeps its own copy. Clear it, or the next call tries a dead token first.
my_store.clear()