# getHistory()

Canonical URL: https://developers.iagenify.com/sdk/ref/assistant-session/get-history/
Language: en

`assistant.getHistory() → Promise<{ ok, messages }>`

Everything said in this session, in order, as it was stored. Reading it adds nothing and costs nothing.

Status: GET /api/ai/models/:id/messages · free · oldest first

## Returns {#returns}

```javascript
{
  ok: true,
  messages: [
    { role: "user",
      parts: [{ type: "text", content: "Résume ce contrat." },
              { type: "file", content: "", mime: "application/pdf", url: "…" }] },

    { role: "assistant",
      parts: [{ type: "text", content: "Le contrat porte sur…" }],
      model: "gemini-3.5-flash" }
  ]
}
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `role` | string |  | `user` or `assistant`. |
| `parts` | array |  | The message, piece by piece. Always at least one. |
| `parts[].type` | string |  | `text` · `json` · `image` · `audio` · `video` · `file`. |
| `parts[].content` | string |  | The text. Empty on a part that is not text. |
| `parts[].mime · url · path · sourceId` | string |  | Where a non-text part came from, when it is known. |
| `model` | string |  | On an assistant message: which model answered. |

## Binary is referenced, not stored {#binary}

A picture you sent, or one the session produced, is remembered by its reference — not by its bytes. So the history tells you an image was part of the conversation and does not hand it back.

> **This is not an archive of your files**
>
> If a generated image matters, write it out when generate() hands it to you. The history will not give it to you a second time.

Long text is bounded too: a very long message is stored up to a limit and marked as truncated past it. The conversation keeps working; the stored copy is not byte-for-byte what was sent.

## What the model sees is not this {#versus}

This is the record. What is actually sent on the next `generate()` is the summary of the older part plus the recent messages — so a long session shows a full history here while sending something shorter.

|  | getHistory() | What the next call sends |
| --- | --- | --- |
| Old messages | All of them, in order | Replaced by a summary once it grows |
| Recent messages | Present | Present |
| Binary | Referenced | Not re-sent |

## What it is for {#uses}

```javascript
// Rebuild a thread in your own interface
const { messages } = await assistant.getHistory();

for (const m of messages) {
  const text = m.parts.filter((p) => p.type === "text").map((p) => p.content).join("\n");
  const files = m.parts.filter((p) => p.type !== "text");
  ui.append({ who: m.role, text, attachments: files.length });
}
```

```javascript
// Export a conversation before deleting it
const { messages } = await assistant.getHistory();
await fs.writeFile(`${assistant.id}.json`, JSON.stringify({ session: assistant.data, messages }, null, 2));
await assistant.destroy();
```

## When it is empty {#empty}

A session created with `memory: false` stores nothing, so this always answers an empty list — not an error. The same is true of a session nothing has been generated in yet.

## Errors {#errors}

| Code | Status | When |
| --- | --- | --- |
| discussion_not_found | 404 | No session of this account with that id. |

- [destroy()](/sdk/ref/assistant-session/destroy): Removing the session and these messages.
- [api.models.list()](/sdk/ref/models/list): Finding the session this belongs to.

```python
{
    "ok": True,
    "messages": [
        {"role": "user",
         "parts": [{"type": "text", "content": "Résume ce contrat."},
                   {"type": "file", "content": "", "mime": "application/pdf", "url": "…"}]},

        {"role": "assistant",
         "parts": [{"type": "text", "content": "Le contrat porte sur…"}],
         "model": "gemini-3.5-flash"},
    ],
}
```

```python
# Rebuild a thread in your own interface
messages = assistant.get_history()["messages"]

for m in messages:
    text = "\n".join(p["content"] for p in m["parts"] if p["type"] == "text")
    files = [p for p in m["parts"] if p["type"] != "text"]
    ui.append(who=m["role"], text=text, attachments=len(files))
```

```python
import json
from pathlib import Path

# Export a conversation before deleting it
messages = assistant.get_history()["messages"]
Path(f"{assistant.id}.json").write_text(
    json.dumps({"session": assistant.data, "messages": messages}, indent=2, ensure_ascii=False),
    encoding="utf-8",
)
assistant.destroy()
```
