Most of the time you want a session: you ask, you get text or a structured object or a file, and the conversation carries on by itself. The turn is the lower layer — it is what an agent loop calls, over and over, and what you call when the loop is yours to write.
The two shapes, side by side
| Session | Turn | |
|---|---|---|
| Created by | api.models.create() | nothing — it is one call |
| State | Kept server-side when memory is on | None. You send the whole history every time |
| Hands back | Finished outputs: text, JSON, images, audio, video | The model's next move: text, or tool calls |
| Tools | Server-side search and fetch, by setting | Your own declarations, called back to you |
| Deadline | None — a long generation runs to the end | Five minutes |
| You use it for | Assistants, extraction, generation | Writing your own agent loop |
The turn asks you to carry the conversation, re-send it each time, and decide what a tool call means. That is the right trade when you are building a loop, and an unnecessary one when you are not.
The methods
| Method | Does |
|---|---|
| create({ model, settings, schema, memory, storage }) | Opens a session. Returns an AssistantSession. |
| get(id) | Reopens a saved session. Returns an AssistantSession. |
| list({ limit }) | The account's sessions, newest first. Returns plain objects. |
| turn({ model, messages, tools, … }) | One stateless model turn, with native tool calling. |
get() hands back an AssistantSession, with generate() on it. list() hands back plain data, with no methods — pass an id from it to get() when you want to carry on.
A session, end to end
const assistant = await api.models.create({
model: "gemini-3.5-flash",
settings: { instructions: "Answer in French, in at most three sentences." },
});
const result = await assistant.generate({
inputs: [{ type: "text", content: "Résume ce contrat." },
// A document is always a url — unlike image, audio or video, "file" has no content form.
{ type: "file", url: "https://example.com/contrat.pdf" }],
});
result.outputs; // [{ type: "text", content: "…" }]
result.usage.credits; // what it actually cost
await assistant.generate({ inputs: [{ type: "text", content: "Et les risques ?" }] });
// the contract is still in the conversation — you do not re-send itassistant = api.models.create(
model="gemini-3.5-flash",
settings={"instructions": "Answer in French, in at most three sentences."},
)
result = assistant.generate(inputs=[
{"type": "text", "content": "Résume ce contrat."},
{"type": "file", "url": "https://example.com/contrat.pdf"},
])
result["outputs"] # [{"type": "text", "content": "…"}]
result["usage"]["credits"] # what it actually cost
assistant.generate(inputs=[{"type": "text", "content": "Et les risques ?"}])
# the contract is still in the conversation — you do not re-send itA turn, end to end
let messages = [{ role: "user", content: "What is the weather in Tunis?" }];
const turn = await api.models.turn({
model: "gemini-3.5-flash",
messages,
tools: [{ name: "weather", description: "Current weather for a city.",
parameters: { city: { type: "string", required: true } } }],
});
turn.stopReason; // "tool_use"
turn.message.toolCalls; // [{ id, name: "weather", args: { city: "Tunis" }, signature }]
// You run the tool, you append the result, you call again.messages = [{"role": "user", "content": "What is the weather in Tunis?"}]
turn = api.models.turn(
model="gemini-3.5-flash",
messages=messages,
tools=[{"name": "weather", "description": "Current weather for a city.",
"parameters": {"city": {"type": "string", "required": True}}}],
)
turn["stopReason"] # "tool_use"
turn["message"]["toolCalls"] # [{"id", "name": "weather", "args": {"city": "Tunis"}, "signature"}]
# You run the tool, you append the result, you call again.The loop around that is yours. If you would rather not write one, the agent engine is that loop already built — see Agent engine.
What each one costs
Both are billed on what reaches the provider, in the units the catalogue gives for that model. Two things are worth knowing before you design around either.
- A session with memory pays for its history. Every call re-sends the conversation, so a long one costs more per answer than a short one — until the older part is summarised for you, which happens on its own.
- A turn pays for its declarations. Tool definitions travel on every single turn. Ten tools you never call still cost tokens each time.