> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/observability/save-ai-message-history.md).

# How to save AI message history

**AI message history** stores each `sendAI` turn on the server so your product can reload conversations with **`fetchAIHistory`** and remove entries with **`deleteAIHistoryMessage`**.

Control it with **`saveHistory: true`** (default) or `false` on each `sendAI` call.

## Why save AI history?

* Rebuild a support chat UI after refresh
* Continue audits / compliance with stored turns
* Pair with [`sessionId`](https://dnotifier.gitbook.io/product-docs/ai/sessions.md) for multi-turn assistants
* Keep internal workflow routing calls ephemeral (`saveHistory: false`)

{% hint style="warning" %}
`saveHistory` is **not** dashboard session logging. For ops telemetry use [`logs: true`](https://dnotifier.gitbook.io/product-docs/observability/enable-session-logs.md).
{% endhint %}

## How to save AI message history

### Store turns (default)

{% tabs %}
{% tab title="JavaScript" %}

```js
await notifier.sendAI({
  senderId: "user-123",
  message: { text: "How do I reset my password?" },
  saveHistory: true, // default — can omit
});

const history = await notifier.fetchAIHistory({ senderId: "user-123" });
```

{% endtab %}

{% tab title="Python" %}

```python
await notifier.send_ai(
    sender_id="user-123",
    message={"text": "How do I reset my password?"},
    save_history=True,
)

history = await notifier.fetch_ai_history(sender_id="user-123")
```

{% endtab %}

{% tab title="Dart" %}

```dart
await notifier.sendAI(
  senderId: 'user-123',
  message: {'text': 'How do I reset my password?'},
  saveHistory: true,
);

final history = await notifier.fetchAIHistory(senderId: 'user-123');
```

{% endtab %}
{% endtabs %}

### Skip storage (ephemeral / internal)

Use `saveHistory: false` for classification, routing, or workflow steps you do not want in the user-facing history:

```js
await ctx.sendAI({
  message: {
    messages: [
      { role: "system", content: "Classify intent as search|general" },
      { role: "user", content: String(ctx.input) },
    ],
  },
  saveHistory: false,
  label: "Intent classification",
});
```

## Load and delete history

| Method                                            | Purpose                         |
| ------------------------------------------------- | ------------------------------- |
| `fetchAIHistory({ senderId })`                    | List stored AI turns for a user |
| `deleteAIHistoryMessage({ senderId, messageId })` | Delete one message              |

Prefer **`transport: "http"`** so history methods return the payload directly.

→ Full API: [AI history](https://dnotifier.gitbook.io/product-docs/ai/ai-history.md)

## saveHistory vs logs vs observability

| Flag                  | Saves conversation for your app? | Dashboard                    |
| --------------------- | -------------------------------- | ---------------------------- |
| `saveHistory: true`   | Yes — via `fetchAIHistory`       | No dedicated list            |
| `logs: true`          | No                               | **Logs** (sessions / tokens) |
| `observability: true` | No                               | **Workflows** (step graph)   |

Production assistants usually enable **all three**: history for UX, logs for ops, observability for multi-agent pipelines.

## AI history vs chat history

| API                                        | What it stores                |
| ------------------------------------------ | ----------------------------- |
| **AI history** (`saveHistory` on `sendAI`) | User ↔ AI turns               |
| **Chat history** (`saveHistory` on `send`) | User ↔ user realtime messages |

→ [Chat history](https://dnotifier.gitbook.io/product-docs/chat/chat-history.md) · [Chat saveHistory flag](https://dnotifier.gitbook.io/product-docs/chat/save-history.md)

## Next steps

* [Enable session logs](https://dnotifier.gitbook.io/product-docs/observability/enable-session-logs.md)
* [AI sessions (`sessionId`)](https://dnotifier.gitbook.io/product-docs/ai/sessions.md)
* [Observability FAQ](https://dnotifier.gitbook.io/product-docs/observability/faq.md)
