api.models

create()

api.models.create(options) → Promise<AssistantSession>

Opens a model session. Four options decide everything that follows: which model, how it behaves, what shape it answers in, and whether it remembers.

POST /api/ai/modelsfree — nothing is generatedreturns an AssistantSession
Using Python?

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

Creating a session costs nothing and calls no model. It records a configuration; the first generate() is what spends.

Parameters

modelstringrequired

A model name from the catalogue. Missing → the SDK throws before any request.

settingsobject

How it behaves: instructions, temperature, output ceiling, server-side tools. See settings.

schemaobject

A JSON Schema. Set it and the session answers objects instead of prose. See schema.

memoryboolean

Defaults to true. false means nothing is stored and each call starts from nothing.

storagestring

A storage id. The documents uploaded there become available to the session as context.

Returns

const assistant = await api.models.create({ model: "gemini-3.5-flash" });

assistant.id;         // keep this to reopen the session later
assistant.model;
assistant.settings;   // {}
assistant.schema;     // null
assistant.memory;     // true
assistant.title;      // "" until the first exchange names it
assistant.createdAt;
assistant = api.models.create(model="gemini-3.5-flash")

assistant.id           # keep this to reopen the session later
assistant.model
assistant.settings     # {}
assistant.schema       # None
assistant.memory       # True
assistant.title        # "" until the first exchange names it
assistant.created_at

memory, and what it changes

This is the option people get wrong, because both values are reasonable and they are reasonable for opposite reasons.

memory: true (default)memory: false
The conversationKept, and re-sent on each callNot kept. Each call starts from nothing
Reopening laterget(id) carries onThere is nothing to carry on
Cost per callGrows with the conversation, then settlesFlat
Good forAn assistant, a thread, anything with follow-upsClassification, extraction, one-shot jobs at volume
memory: false is not a privacy setting

It stops the conversation being stored and replayed. What you send still reaches the model to be answered. Decide what leaves your side on the input, not on this flag.

What happens to a long conversation

A session with memory does not re-send an ever-growing history forever. Past a certain volume the older half is summarised once, the summary is kept with the session, and the recent messages follow it. The summary is redone only when the volume builds up again.

  • That summary is itself a model call, so it is billed — once, not per answer.
  • You do not trigger it and cannot turn it off; it is what keeps a long session from costing more every time.
  • A session you intend to keep forever is fine. A session you intend to keep forever and replay verbatim is not what this is.

storage, and what it is for

Pass a storage id and the documents uploaded there are available to the session as context — the relevant passages are found and supplied with your question, rather than you pasting them in.

const docs = await api.storage.get({ id: storageId });

const assistant = await api.models.create({
  model: "gemini-3.5-flash",
  storage: docs.id,
  settings: { instructions: "Answer only from the documents. Say so when they do not cover it." },
});

await assistant.generate({ inputs: [{ type: "text", content: "What is our refund window?" }] });
docs = api.storage.get(id=storage_id)

assistant = api.models.create(
    model="gemini-3.5-flash",
    storage=docs.id,
    settings={"instructions": "Answer only from the documents. Say so when they do not cover it."},
)

assistant.generate(inputs=[{"type": "text", "content": "What is our refund window?"}])
The instruction matters as much as the storage

Attaching documents makes them available; it does not stop the model answering from elsewhere. If you want it bounded to them, say so in instructions — and expect it to tell you when they do not cover the question.

Errors

CodeStatusWhen
— (thrown locally)—No model passed. The SDK throws before any request.
model_required400The model was empty by the time the server saw it.
unauthorized401No valid session or key on the call.

A model name that is not in the catalogue is not refused here. Creating a session records a name; the refusal comes on the first generate(), which is where the model is actually asked for.

// Check the name yourself if you want the failure early
const grid = await api.catalogue();
const known = grid.some((row) => row.model === wanted);
if (!known) throw new Error(`${wanted} is not in the catalogue`);
# Check the name yourself if you want the failure early
grid = api.catalogue()
if not any(row["model"] == wanted for row in grid):
    raise ValueError(f"{wanted} is not in the catalogue")