---
title: "Exchange a GoTrue refresh token for a mnemom_session cookie"
method: POST
path: "/auth/token-exchange"
tags: ["Auth"]
---

# Exchange a GoTrue refresh token for a mnemom_session cookie

`POST /auth/token-exchange`

## Request

- Base URL: `https://api.mnemom.ai/v1`
- URL: `https://api.mnemom.ai/v1/auth/token-exchange`
- Auth: none required

Mirror of `/auth/cli-exchange` in the opposite direction. Called by the SPA after landing on a Supabase implicit-flow redirect (magic-link login), whose session tokens arrive in the URL fragment. The endpoint performs the GoTrue refresh grant server-side — proving possession and consuming the single-use refresh token — then registers a session and sets the HttpOnly `mnemom_session` cookie. JSON-only; no redirect parameter. A refresh token belonging to an email whose domain enforces SSO is refused with 403 `sso_required` and no session is minted (SSO logins establish their own session and never use this route); if that check cannot be completed the response is 503 `sso_check_unavailable`. Rate-limited like sibling auth endpoints.

## Request body

- object
  - `refresh_token` string, required: GoTrue refresh token from the implicit-flow fragment.

## Response `200`

Session established. Sets `mnemom_session`.

- object
  - `user` object, required
    - `id` string, uuid, required
    - `email` string, email, nullable
  - `aal` 'aal1' | 'aal2', required

## Other responses

- `400`: Bad request
- `401`: Authentication required
- `403`: Forbidden
- `415`: Body is not declared `application/json` (`unsupported_media_type`). Login-CSRF guard: a cross-site `<form enctype="text/plain">` cannot deliver a parseable body.
- `429`: Rate-limit exceeded. The global per-IP limiter (100 requests/minute, applied to every `/v1/*` route) rejected this request. Back off until the window resets — `Retry-After` carries the cooldown in seconds and `X-RateLimit-Reset` the absolute reset time.
- `500`: Server error — request was well-formed but the server failed to fulfill it. Typically a downstream dependency (DB / RPC / external API) returned an unexpected error.
- `503`: An upstream dependency is currently unavailable. The request was not processed; retry after the cooldown window.

---

[API](https://skmtc.dev/mnemom/apis/mnemom-api.md) · [All operations](https://skmtc.dev/mnemom/apis/mnemom-api/llms.txt) · [OpenAPI document](https://skmtc.dev/mnemom/apis/mnemom-api/revisions/274b7a6ea182?raw)
