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"},
],
}rolestringuser or assistant.
partsarrayThe message, piece by piece. Always at least one.
parts[].typestringtext · json · image · audio · video · file.
parts[].contentstringThe text. Empty on a part that is not text.
parts[].mime · url · path · sourceIdstringWhere a non-text part came from, when it is known.
modelstringOn 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.
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 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
// 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
| Code | Status | When |
|---|---|---|
| discussion_not_found | 404 | No session of this account with that id. |