api.tools

image

tools: { image: api.tools.image }, model: { main, image }

Lets a run generate an image. It is a declaration resolved against a model session named image — so the model that writes is not the model that draws.

declaration onlyneeds an image sessiondeclared cost 26
Using Python?

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

Nothing to call. What produces the image is a model session you created and handed to the run under the name image.

Declaring it

const writer = await api.models.create({ model: "gemini-3.5-flash" });
const painter = await api.models.create({ model: "gemini-3.1-flash-image" });

const agent = api.agents.create({
  model: { main: writer, image: painter },     // the name matters
  tools: { image: api.tools.image },
  budget: 200,
});

const run = await agent.run({
  inputs: [{ type: "text", content: "Draw a logo for a tide-forecasting app, then describe it." }],
});
writer = api.models.create(model="gemini-3.5-flash")
painter = api.models.create(model="gemini-3.1-flash-image")

agent = api.agents.create(
    model={"main": writer, "image": painter},   # the name matters
    tools={"image": api.tools.image},
    budget=200,
)

run = agent.run(inputs=[
    {"type": "text", "content": "Draw a logo for a tide-forecasting app, then describe it."},
])
The session's name is image, not whatever you called the tool

You may rename the tool freely; the session is looked up by the builtin's own name. Without an image entry in model, the run answers that no image session was supplied — and it says so instead of generating with the writing model.

What the model sends

promptstringrequired

What to create. The whole description, in one argument.

Where the image goes

It is attached to the run as an artifact, and it is in the run's result — not written anywhere. Saving it is yours, which is what lets the same run serve a page, a file on the machine or a bucket.

const [picture] = run.artifacts.filter((a) => a.type === "image");

await pc.files.write("Assets/logo.png", Buffer.from(picture.content, "base64"));
// or
await api.files.create({ name: "logo.png", content: Buffer.from(picture.content, "base64"),
                         mimeType: picture.mime }).save();
import base64

picture = next(a for a in run["artifacts"] if a["type"] == "image")

pc.files.write("Assets/logo.png", base64.b64decode(picture["content"]))
# or
api.files.create(name="logo.png", content=base64.b64decode(picture["content"]),
                 mime_type=picture.get("mime")).save()

The declared cost is 26, and it over-estimates

The budget guard decides before the call, on the declared number — so that number has to be at or above what the generation really costs. 26 is the default; raise it with cost if you work with a more expensive model, and never lower it to fit a budget.

tools: {
  image: { run: api.tools.image, cost: 40, options: { aspectRatio: "16:9" } },
}
tools = {
    "image": {"run": api.tools.image, "cost": 40, "options": {"aspectRatio": "16:9"}},
}

options is merged into the session's settings for that call, so a fixed aspect ratio or quality can be pinned without taking the subject away from the model.

What is charged

The generation is billed to the account like any other, and the run's own credit total carries it. Nothing is charged when the guard refuses, since the call never happens.

It feeds the video tool

The most recent image artifact of a run is passed to video as its starting picture. So « draw it, then animate it » is two calls with nothing of yours in between.