# Tokens · expiry and refresh

Access tokens last an hour. Refresh tokens rotate on every use, and a connection nobody uses lapses after 60 days. Reusing an old refresh token ends the whole connection.

Checked 2026-12-02 · https://xale.app/docs/ai/tokens-expiry-and-refresh

## The token answer

`POST /api/oauth/token` answers:

```json
{
  "access_token": "…",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "…",
  "scope": "read write:memories write:intentions write:changes"
}
```

| Token | Starts with | Lasts |
| --- | --- | --- |
| Access token | `xale_at_` | 1 hour |
| Refresh token | `xale_rt_` | Until used; unused, 60 days |

Both are opaque random strings; Xale stores only their SHA-256. Send the access token as `Authorization: Bearer …` on every `/api/mcp` call; Xale reads it from that header only.

## Refreshing

`POST /api/oauth/token`, form-encoded: `grant_type=refresh_token`, `refresh_token`, `client_id`, and optionally `scope`.

- Every refresh returns a new access token and a new refresh token. Keep the new refresh token: the old one is spent.
- A connection lapses when its refresh token goes 60 days unused.
- `scope` can keep or narrow what the connection holds. Leave it out (or send only identity scopes) to keep everything. Asking for a scope the connection doesn't hold is `invalid_scope`.

## Reuse

| What happens | Result |
| --- | --- |
| Two refreshes with the same token within 10 seconds | The second fails with `invalid_grant`; the connection stays. Retry with the newer refresh token. |
| A spent refresh token used later than that | Treated as stolen: the whole connection ends, and every token of it stops working |
| An authorization code used twice | The whole connection ends |

## Errors

All are `400` JSON with `error` and `error_description`.

| `error` | `error_description` | Do |
| --- | --- | --- |
| `invalid_grant` | “The connection lapsed. Connect the app to Xale again.” | Ask the person to connect again |
| `invalid_grant` | “The refresh token was already used.” | Use the newest refresh token; if you have none, connect again |
| `invalid_grant` | “The refresh token is not valid.” | Connect again |
| `invalid_grant` | “This connection was removed. Connect the app to Xale again.” | The person disconnected it, or it was replaced; connect again |
| `invalid_grant` | “This Xale account can't be used right now.” | Stop; the account is suspended or gone |
| `invalid_grant` | “The authorization code expired. Connect again.” | Codes last 5 minutes; start the sign-in again |
| `invalid_grant` | “The PKCE code_verifier does not match.” | Send the verifier that made the `code_challenge` |
| `invalid_scope` | “The requested scope was not granted.” | Ask for fewer scopes, or none |
| `invalid_client` | “client_id is required.” or “Unknown client.” | Register again |
| `unsupported_grant_type` | “Use authorization_code or refresh_token.” | Fix `grant_type` |

## On the MCP server

An expired, revoked or unknown access token gets `401` with `error="invalid_token"` in `WWW-Authenticate`. Refresh, then retry the call.

## Related

- For people: [How do I reconnect Claude to Xale?](https://xale.app/help/reconnect-your-ai-after-changes)
- Read next: [Disconnect · and revoke access](https://xale.app/docs/ai/disconnect-and-revoke-access)
- Read next: [Error codes · what they mean](https://xale.app/docs/ai/error-codes-what-they-mean)
