# save()

Canonical URL: https://developers.iagenify.com/sdk/ref/memory/save/
Language: en

`api.memory.save(note) → Promise<Memory>`

Creates a note, or replaces the one with the same name. The name is the identity — there is no separate update.

Status: POST /api/ai/memories · free · upsert by name

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `name` | string | required | Lowercase, digits and hyphens, up to 64. Anything else is converted; what cannot be is refused. |
| `content` | string | required | The note itself, up to 4 000 characters. Empty is refused. |
| `description` | string |  | One line, up to 200. This is what the agent sees when choosing — see [below](#description). |
| `type` | string |  | `preference` · `project` · `fact` · `correction` · `other`. Unknown values become `other`. |
| `source` | string |  | `user` or `agent`. Anything that is not `user` becomes `agent`. |
| `sessionId` | string |  | The session this was learned in, when there was one. |

## The name is the identity {#name}

Saving with a name that already exists replaces that note. That is the whole update mechanism, and it is why the name is worth choosing well: it is the thing you will have to match later.

```javascript
await api.memory.save({ name: "tone-of-voice", content: "Short answers.", source: "user" });
await api.memory.save({ name: "tone-of-voice", content: "Short answers, in French.", source: "user" });
// One note. The second content replaced the first.
```

| You pass | Stored as |
| --- | --- |
| Tone Of Voice | tone-of-voice |
| user_preferences | user-preferences |
| Déploiement !! | d-ploiement |
| !!! | refused — invalid_name |

> **Names are converted, not validated**
>
> Two different names can converge on one, and the second save then replaces the first note without saying so. Pick plain, stable names, and read back the name that comes back when you built it from user input.

## Write the description for the agent {#description}

The content is only opened when a note looks relevant, and relevance is judged on the description alone. So the description should say *when this is worth reading*, not what it contains.

| Weak description | Better |
| --- | --- |
| « Preferences » | « How this user wants to be written to » |
| « Database » | « Which database to use, and which never to touch » |
| « Notes about the project » | « The deploy rules for this project, including what is forbidden » |

## Returns {#returns}

```javascript
const note = await api.memory.save({
  name: "deploy-rules",
  description: "The deploy rules for this project, including what is forbidden",
  content: "No deploys on Friday. Staging first, always. Migrations run separately.",
  type: "project",
  source: "user",
});

note.name;        // "deploy-rules"
note.type;        // "project"
note.updatedAt;
```

The note as stored — after the name has been converted and the text trimmed to its limits. Read it back rather than assuming what you sent is what was kept.

## Errors {#errors}

| Code | Status | When |
| --- | --- | --- |
| invalid_name | 400 | Nothing usable was left after conversion. |
| content_required | 400 | The content was empty or only whitespace. |
| too_many_memories | 400 | 200 notes already, and this would be a new one. |

`too_many_memories` only applies to a *new* note: replacing an existing one works at the cap, because it adds nothing. That is deliberate — being full should not stop you correcting something wrong.

```javascript
import { IaGenifyError } from "iagenify";

try {
  await api.memory.save({ name, content, description, type, source: "user" });
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "too_many_memories") {
    // Let the user choose what goes. Do not evict on their behalf.
    return { needsPruning: await api.memory.list() };
  }
  throw err;
}
```

## source, and why it is worth setting {#source}

Anything that is not `"user"` is recorded as `agent`. Setting it honestly is what lets an interface separate « you told me this » from « I worked this out » — and the second deserves to be easier to question.

- [list()](/sdk/ref/memory/list): Reading them all back, content included.
- [delete()](/sdk/ref/memory/delete): Removing one.

```python
api.memory.save(name="tone-of-voice", content="Short answers.", source="user")
api.memory.save(name="tone-of-voice", content="Short answers, in French.", source="user")
# One note. The second content replaced the first.
```

```python
note = api.memory.save(
    name="deploy-rules",
    description="The deploy rules for this project, including what is forbidden",
    content="No deploys on Friday. Staging first, always. Migrations run separately.",
    type="project",
    source="user",
)

note["name"]        # "deploy-rules"
note["type"]        # "project"
note["updatedAt"]
```

```python
from iagenify import IaGenifyError

try:
    api.memory.save(name=name, content=content, description=description, type=kind, source="user")
except IaGenifyError as error:
    if error.code != "too_many_memories":
        raise
    # Let the user choose what goes. Do not evict on their behalf.
    needs_pruning = api.memory.list()
```
