Revocation and token lifetime
When a Connect token stops working, and how your app should recover.
Each Connect login receives its own access token. Tokens currently have no expiry timer, but they are not permanent credentials.
What invalidates a token#
- The user disconnects your app. From Settings → Connected apps the user can revoke the connection; every token for that app and user dies immediately.
- That token expires under a scope policy. No current scope has a timer, but the API may add one in the future.
- The account is closed or suspended. All tokens for the unavailable account stop working.
Connecting again does not invalidate an older active token. Device A remains connected when device B completes the flow. If you want to remove every login, disconnect the app from Settings → Connected apps.
Any of these surfaces as 401 on your next call.
Handling 401#
Treat 401 as reconnect required, not as a retryable error. Retrying the same
token will never succeed.
async function callPortModels(user, body) {
const res = await fetch('https://api.portmodels.com/openai/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${user.pmTokenFor(user.loginId)}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
if (res.status === 401) {
await clearConnection(user.id, user.loginId);
throw new ReconnectRequired(); // prompt the user through Connect again
}
if (res.status === 403) {
throw new MissingScope(await res.json());
}
return res.json();
}In your UI, a ReconnectRequired should render as a "Reconnect your PortModels
account" button, not as an error page. The affected token may have been
revoked, expired, or tied to an unavailable account; another device's token can
still be working.
Handling multiple logins#
If a user runs the connect flow twice — from two browsers, or after reinstalling your desktop app — both tokens can remain active. Store each token keyed by your own user id plus the session or device installation that owns it. Do not overwrite a different active device's token unless that is an explicit choice in your app's session model.
Revoking from your side#
If your app no longer needs access, stop using the token and delete your stored copy. Tell the user they can also remove the connection from Settings → Connected apps, which is the record they see.
Don't cache failure#
A revoked token is a normal state, not an outage. Don't retry a dead token on a
schedule — it produces 401s in your own logs and nothing else.