# Quickstart: give your AI app a memory in five minutes

> Give one of your users a memory, ask it a question, and erase it. Three requests, about five minutes, and no SDK needed.

You'll add a message to one user's memory, search it, and then forget it. Every example is plain HTTP, so it works
from any language. The SDKs for [Python](/sdks/python) and [TypeScript](/sdks/typescript) do the same in a few
lines.

[Video: the SDK quickstart, 1:47](https://alexein.ai/videos/alexein-sdk-quickstart.mp4)

Prefer to watch? The SDK quickstart adds and searches with the [Python SDK](/sdks/python), a step at a time, in
under two minutes, then shows the same in [TypeScript](/sdks/typescript).

**You need** an account on the Alexein Console, to create a key, and one of `curl`, Python 3 with `requests`, or
Node 20 or newer. When you [sign up](https://app.alexein.ai/sign-up) at app.alexein.ai, it sets up your default organisation
and a first project, Production, for your app's users, without asking anything. A memory of your own, for claude.ai, ChatGPT and your coding
agents, is in My memory instead: [sign in at
memory.alexein.ai](https://memory.alexein.ai/sign-in) with the same account.

> **No code yet?**
>
> The Console's **[Playground](https://app.alexein.ai/console/playground)** needs no key. **Try memory** saves something for a **playground user**, asks about it, and
> can answer with a model from what memory found. A playground user is a test user of the project's own, kept apart
> from your app users: nothing you try there reads or changes their memory. **API explorer** has every operation, with the request written out as
> cURL, Python and TypeScript.

> **Run the example**
>
> These three requests, ready to run in Python and TypeScript, are in [quickstart](https://github.com/Alexein-AI/examples/tree/main/quickstart).

## Three calls

With a key (step 1 below) and your own id for one of your users, this is all of it: add what they said,
search it, and read what is true about them now.

**cURL**

```bash
curl https://api.alexein.ai/v2/memory/add -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42" -H "Content-Type: application/json" \
  -d '{"wait": true, "items": [{"text": "I just moved to Lisbon from Berlin."}]}'
curl https://api.alexein.ai/v2/memory/search -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42" -H "Content-Type: application/json" \
  -d '{"query": "Where do I live?"}'
curl https://api.alexein.ai/v2/memory/profile -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42"
```
**Python**

```python
from alexein import Memory  # pip install alexein

user = Memory().user("user_42")  # reads ALEXEIN_API_KEY
user.add("I just moved to Lisbon from Berlin.", wait=True)
print(user.search("Where do I live?").context())
print(user.profile().text)  # for your system prompt: fills in once the message is processed
```
**TypeScript**

```ts
import { Memory } from "@alexein/sdk"; // npm install @alexein/sdk

const user = new Memory().user("user_42"); // reads ALEXEIN_API_KEY
await user.add("I just moved to Lisbon from Berlin.", { wait: true });
console.log((await user.search("Where do I live?")).context());
console.log((await user.profile()).text); // for your system prompt: fills in once processed
```

- **Add** keeps the text in that user's memory; `wait` returns once it is searchable.
- **Search** answers with `memories`, a list of facts and excerpts: what memory holds true now, then dated facts,
  then excerpts, each with its `text` and a `ref`; see [Search](/api/search).
- **Profile** answers with `text`, what memory holds to be true about the user now, ready for your system
  prompt. Right after the add it is still empty: it fills in once the message is processed, usually within
  minutes. Until then search finds the message itself; see [Profile](/api/profile).

Everything else is optional, and the steps below show it: an `id` makes a retry safe, a `session` groups a
conversation, and an `author` says who said what when more than one person speaks.

## 1. Create a key

In the Console, open **[API keys](https://app.alexein.ai/console/keys)** and create a key with **read and write** access. It's shown once, so copy it now.
Keep it on your backend, never in a browser, and export it for the examples below:

```bash
export ALEXEIN_API_KEY="ax_..."
```

[Authentication & keys](/authentication) explains which key goes where.

## 2. Add a message

Every request names one of your app users with the `X-Alexein-User` header. Use whatever id your app already has for
them: the first write creates their memory.

**cURL**

```bash
curl https://api.alexein.ai/v2/memory/add \
  -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42" \
  -H "Content-Type: application/json" \
  -d '{
    "wait": true,
    "items": [{
      "id": "msg-001",
      "session": "onboarding",
      "role": "user",
      "author": {"name": "Alice Chen", "self": true},
      "text": "I just moved to Lisbon from Berlin for the new job at Acme."
    }]
  }'
```
**Python**

```python
import os, requests

r = requests.post(
    "https://api.alexein.ai/v2/memory/add",
    headers={
        "Authorization": f"Bearer {os.environ['ALEXEIN_API_KEY']}",
        "X-Alexein-User": "user_42",
    },
    json={"wait": True, "items": [{
        "id": "msg-001",
        "session": "onboarding",
        "role": "user",
        "author": {"name": "Alice Chen", "self": True},
        "text": "I just moved to Lisbon from Berlin for the new job at Acme.",
    }]},
)
print(r.status_code, r.json())
```
**TypeScript**

```ts
const r = await fetch("https://api.alexein.ai/v2/memory/add", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ALEXEIN_API_KEY}`,
    "X-Alexein-User": "user_42",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    wait: true,
    items: [
      {
        id: "msg-001",
        session: "onboarding",
        role: "user",
        author: { name: "Alice Chen", self: true },
        text: "I just moved to Lisbon from Berlin for the new job at Acme.",
      },
    ],
  }),
});
console.log(r.status, await r.json());
```

`author` with `"self": true` says these are the app user's own words, so memory knows whose details they are.

`"wait": true` holds the request until the message is stored, up to 10 seconds, so the search in the next step
finds it. You get `200 OK` with `waiting: 0`:

```json
{
  "items": [{ "id": "msg-001", "status": "stored" }],
  "waiting": 0
}
```

Without `wait`, you get `202 Accepted` straight away with the message `queued`, and it is `stored` and searchable
a moment later: a search sent at once can come back empty. In your app, leave `wait` out where nothing searches
right after the add, such as saving each turn of a chat.

> **Retrying is always safe**
>
> The same `id` again is an edit of that item, never a second copy. Reuse an `id` only to fix the same statement;
> when something changes, add a new item, and memory keeps both, dated. [Items](/concepts/items) has every field.

## 3. Search it

Ask a question in plain words:

**cURL**

```bash
curl https://api.alexein.ai/v2/memory/search \
  -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42" \
  -H "Content-Type: application/json" \
  -d '{ "query": "Where does Alice live?" }'
```
**Python**

```python
import os, requests

r = requests.post(
    "https://api.alexein.ai/v2/memory/search",
    headers={
        "Authorization": f"Bearer {os.environ['ALEXEIN_API_KEY']}",
        "X-Alexein-User": "user_42",
    },
    json={"query": "Where does Alice live?"},
)
print(r.json())
```
**TypeScript**

```ts
const s = await fetch("https://api.alexein.ai/v2/memory/search", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ALEXEIN_API_KEY}`,
    "X-Alexein-User": "user_42",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ query: "Where does Alice live?" }),
});
console.log(await s.json());
```

> **Right after the add, expect less**
>
> A search a few seconds after the add finds the message as an excerpt, but no facts or known lines yet: those
> follow once the message is `processed`, usually within minutes. And a search for an app user nothing was ever
> added for is not an error: it answers `200` with `memories` empty.

Once the message is `processed` (see [What appears when](#what-appears-when)), the answer looks like this
(shortened):

```json
{
  "query": "Where does Alice live?",
  "search_id": "srch_wmZy0ij0Vnq8oZq_lmRUo7yprA1by84fPGDKHa6YjzJTX10OXmX0G65OGPIv4Kp6QK0iwzkMNdI",
  "answerable": true,
  "notes": ["Values are listed as stated, newest first."],
  "memories": [
    { "type": "known", "text": "Alice Chen · home city: Lisbon [said 2026-10-01]" },
    {
      "type": "fact",
      "ref": "mem_FCvKOH-c9mqPoLIXgeYm8RdoddLiZAhBasAbzO5OrA9UtT0A2xFz03",
      "text": "(happened 2026-10-01) Alice lives in Lisbon",
      "source": "mem_fwxGL-7yFNDYjuZempGr76TvTQkbNc6QzGf_AxLqTohry2zpsyQjR4"
    },
    {
      "type": "excerpt",
      "ref": "mem_fwxGL-7yFNDYjuZempGr76TvTQkbNc6QzGf_AxLqTohry2zpsyQjR4",
      "text": "…I just moved to Lisbon from Berlin for the new job at Acme…",
      "date": "2026-10-01T09:30:00+00:00",
      "added_at": "2026-10-01T09:30:02+00:00",
      "session": "onboarding",
      "roles": ["user"],
      "part_of": "Alice's move to Lisbon for a new job at Acme"
    }
  ],
  "mode": "full"
}
```

Hand `notes` and `memories` to your model as context, in the order they came. `search_id` names this search,
for [`feedback`](/api/feedback); `mode` says how fully it was searched (see [Search](/api/search)). A fact's `source` is the ref of the
excerpt it was learned from, so the answer can cite it; [`open`](/api/open) returns either whole.

### What appears when

Memory works in the background, so an answer fills in over the next few minutes. [`status`](/api/status) tells you
how far an item has got.

| Status      | When                       | What search adds          |
| ----------- | -------------------------- | ------------------------- |
| `queued`    | Straight after the add     | Nothing yet               |
| `stored`    | Seconds after the add      | The message, as excerpts  |
| `processed` | Usually within minutes     | Dated facts, known lines  |

[Facts & timing](/concepts/facts) has the details.

## 4. Forget it

**cURL**

```bash
curl https://api.alexein.ai/v2/memory/forget \
  -H "Authorization: Bearer $ALEXEIN_API_KEY" \
  -H "X-Alexein-User: user_42" \
  -H "Content-Type: application/json" \
  -d '{ "items": ["msg-001"] }'
```
**Python**

```python
import os, requests

r = requests.post(
    "https://api.alexein.ai/v2/memory/forget",
    headers={
        "Authorization": f"Bearer {os.environ['ALEXEIN_API_KEY']}",
        "X-Alexein-User": "user_42",
    },
    json={"items": ["msg-001"]},
)
print(r.json())
```
**TypeScript**

```ts
const f = await fetch("https://api.alexein.ai/v2/memory/forget", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ALEXEIN_API_KEY}`,
    "X-Alexein-User": "user_42",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ items: ["msg-001"] }),
});
console.log(await f.json());
```

The message is gone, and so is everything learned from it: its excerpts, the facts taken from it and its versions.
Nothing erased is left readable in storage; backups age it out within about 48 hours. The answer counts what was
erased. Keep it as your proof of the erasure; see [Erasure & receipts](/concepts/erasure).

```json
{ "erased": { "items": 1, "facts": 1, "versions": 1, "waiting": 0 }, "complete": true }
```

## Next steps

- [Build a chat assistant](/guides/chat-assistant): Search before each reply, and add each turn after it.
- [Connect a coding agent](/mcp/claude-code#app-user): Give Claude Code user_42's memory over MCP, with the same key.
- [Your own agent](/api/mcp): Any agent you wrote, over MCP with the same key and an app user.
- [Search reference](/api/search): Date bounds, filters and every field of the answer.
- [Core concepts](/core-concepts): App users, items, excerpts, facts and known lines, on one page.
