AssistantSession

getHistory()

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

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

GET /api/ai/models/:id/messagesfreeoldest first
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Returns

{
  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" }
  ]
}
{
    "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"},
    ],
}
rolestring

user or assistant.

partsarray

The message, piece by piece. Always at least one.

parts[].typestring

text · json · image · audio · video · file.

parts[].contentstring

The text. Empty on a part that is not text.

parts[].mime · url · path · sourceIdstring

Where a non-text part came from, when it is known.

modelstring

On an assistant message: which model answered.

Binary is referenced, not stored

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

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 messagesAll of them, in orderReplaced by a summary once it grows
Recent messagesPresentPresent
BinaryReferencedNot re-sent

What it is for

// 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 });
}
# 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))
// 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();
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()

When it is 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

CodeStatusWhen
discussion_not_found404No session of this account with that id.