# Export

> Everything memory holds for one app user, a page at a time - for a person who asks for a copy of theirs.

`POST /v2/memory/export`

- Auth: read key
- Cost: free; never refused

Hands back everything memory holds for one app user, in pages: each item you added, whole; what their
connected apps delivered; the facts memory learned; and, on a key that writes, the earlier versions of
items an edit replaced. Use it when a person asks for a copy of what you keep about them. To show a list in
your app, use [`items`](/api/items) or [`facts`](/api/facts) instead: they are shorter, and an item there is
cut at 2,000 characters, where the export keeps it whole.

Call it with no `cursor`, then again with each page's `next` until `next` is `null`. Every entry comes back
exactly once. Items and what connected apps delivered (`event` entries) come first, by when they happened; then items still
`queued`; then facts, by when they were said; then versions. Something added while you page through is on a
later page if it sorts after where you are.

What was [forgotten](/api/forget) or has expired is not in it. For an app user nothing was written for, it
answers `200` with no entries, never `404`.

## Headers

- `Authorization` (string, required): `Bearer ax_…`. A read key exports everything but the versions an edit replaced, and says so in
  `withheld`; a key that writes exports those too. See [Versions and edits](/concepts/versions).
- `X-Alexein-User` (string, required): The app user whose memory to export. See [App users](/concepts/app-users).
- `X-Request-Id` (string): Your id for this request, echoed on the response.

## Body

- `limit` (integer): How many entries a page holds, 1 to 500. Default 200.
- `cursor` (string): The `next` the previous page answered with, for the page after it. Leave it out for the first page.

## Response

- `user` (string): The app user, as `X-Alexein-User` named them.
- `exported_at` (string): When this page was read, ISO 8601.
- `entries` (object[]): Each has a `type`:

  - `item`: an item as [`add`](/api/add) was given it (`id`, `kind`, `text`, `title`, `at`, `author`,
    `session`, `about`, `metadata`, `expires`, each where set), with `role`, `status` (`stored` or `queued`)
    and `added_at`, when memory took it.
  - `event`: what a connected app delivered: `provider`, `source`, `kind`, `place`, `title`, `text`, `url`,
    `people` (each with `role`, `name`, `handle`, `email` where known, and `self`), `occurred_at` and
    `added_at`.
  - `fact`: what memory learned: `ref`, `text` led by its date, `date` it was said, and `from` and `until`
    when it held, where known.
  - `version`: an earlier version of an item, in the item's fields, with its `version` number, `taken_at`
    and `replaced_at`. Only on a key that writes.
- `next` (string | null): The cursor of the next page. `null` on the last page.
- `withheld` (string[]): The entry types this key was not given: `["version"]` on a read key, `[]` on a key that writes.

## Errors

- `400` (bad request): `X-Alexein-User` is missing or not a usable id.
- `401` (unauthorized): The bearer is not a key this service issued.
- `403` (forbidden): The organisation has been closed in the console.
- `422` (invalid): A `limit` outside 1 to 500, or a `cursor` that is not a page's `next` (`` `cursor` is not the `next` of a page ``).
- `429` (too many requests): Past your organisation's rate limits. Retry after `Retry-After` seconds. See
  [Limits](/concepts/limits#rate-limits).
- `503` (unavailable): The service is busy or briefly unavailable. Retry after `Retry-After` seconds, or with backoff when
  there is none.
**cURL**

```bash title="Request"
curl https://api.alexein.ai/v2/memory/export \
  -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42" \
  -H "Content-Type: application/json" \
  -d '{ "limit": 200 }'
```
**Python**

```python title="Every page"
import os, requests

key = os.environ["ALEXEIN_API_KEY"]
entries, cursor = [], None
while True:
    r = requests.post(
        "https://api.alexein.ai/v2/memory/export",
        headers={"Authorization": f"Bearer {key}",
                 "X-Alexein-User": "user_42"},
        json={"limit": 200, **({"cursor": cursor} if cursor else {})},
    )
    page = r.json()
    entries += page["entries"]
    cursor = page["next"]
    if cursor is None:
        break
```
**TypeScript**

```ts title="Every page"
const key = process.env.ALEXEIN_API_KEY;
const entries: unknown[] = [];
let cursor: string | null = null;
do {
  const r = await fetch("https://api.alexein.ai/v2/memory/export", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${key}`,
      "X-Alexein-User": "user_42",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ limit: 200, ...(cursor ? { cursor } : {}) }),
  });
  const page = await r.json();
  entries.push(...page.entries);
  cursor = page.next;
} while (cursor);
```

```json title="200 OK, a read key"
{
  "user": "user_42",
  "exported_at": "2026-10-21T16:40:09+00:00",
  "entries": [
    {
      "type": "item",
      "id": "pref-diet",
      "kind": "note",
      "text": "Alice is vegan and allergic to peanuts.",
      "at": "2026-10-02T12:00:00+00:00",
      "metadata": { "source": "crm" },
      "status": "stored",
      "added_at": "2026-10-09T08:41:17+00:00"
    },
    {
      "type": "fact",
      "ref": "mem_Qy7cT0vVbN3rLm8wKs2HdA5fZe9XgJ1uPo4iRt6yWq0BnM3cSx7kLv",
      "text": "[2026-10-02] Alice is vegan",
      "date": "2026-10-02T12:00:00+00:00",
      "from": "2026-10-02T12:00:00+00:00",
      "until": null
    }
  ],
  "next": "cur_8ZpX2mQ4vL7nR1tY5wK9sD3fH6jB0cG",
  "withheld": ["version"]
}
```

```json title="200 OK, an app user nothing was written for"
{ "user": "bob", "exported_at": "2026-10-21T16:40:09+00:00", "entries": [], "next": null, "withheld": [] }
```
