api.files

create()

api.files.create({ name, content, mimeType }) → IaGenifyFile

Builds a file object in memory. Nothing is sent, nothing is written, nothing is charged — this is the step before all of that.

no networksynchronousreturns an object to fill
Using Python?

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

Parameters

namestring

The file name. Used as-is on the account; the server reduces it to a safe one on its own disk.

contentstring|Buffer|Blob

The bytes. Can be set after construction — it is read at save(), not here.

mimeTypestring

Defaults to application/octet-stream, which makes the category document.

It returns synchronously and there is no await: this is a constructor in all but name.

The object

const file = api.files.create({ name: "notes.md", content: "…", mimeType: "text/markdown" });

file.name;
file.content;
file.mimeType;
file.sourceId;   // null until it is saved
file.location;   // null until it is saved
file.metadata;   // null until it is saved
file = api.files.create(name="notes.md", content="…", mime_type="text/markdown")

file.name
file.content
file.mime_type
file.source_id   # None until it is saved
file.location    # None until it is saved
file.metadata    # None until it is saved

Set the mimeType, even though it is optional

It decides two things that are awkward to change later: the category, and whether get() hands the content back as text or as bytes.

You passCategoryget() returns
text/markdowndocumentcontent as a string
application/jsondatacontent as a string
image/pngimagecontent as a Buffer
(nothing)documentcontent as a Buffer
Leaving it out makes text come back as bytes

Without a type the default is a binary one, so a perfectly readable Markdown file is handed back as a Buffer. One line of work now, or a confusing read later.

What content accepts

// A string
api.files.create({ name: "notes.md", content: "# Notes", mimeType: "text/markdown" });

// Bytes you already have
api.files.create({ name: "chart.png", content: pngBuffer, mimeType: "image/png" });

// Something generated — write it out the moment you have it
const { outputs } = await assistant.generate({ inputs, outputs: [{ type: "image" }] });
api.files.create({ name: "cover.png", content: outputs[0].content, mimeType: outputs[0].mime });
import base64

# A string
api.files.create(name="notes.md", content="# Notes", mime_type="text/markdown")

# Bytes you already have
api.files.create(name="chart.png", content=png_bytes, mime_type="image/png")

# Something generated — write it out the moment you have it
outputs = assistant.generate(inputs=inputs, outputs=[{"type": "image"}])["outputs"]
api.files.create(name="cover.png", content=base64.b64decode(outputs[0]["content"]), mime_type=outputs[0].get("mime"))

Filling it in afterwards

The content is read when you save, so building the object first and filling it later is fine — and it is how update() works.

const file = api.files.create({ name: "log.txt", mimeType: "text/plain" });

file.content = lines.join("\n");
await file.save();

// And to replace it later
file.content = "…";
await file.update();
file = api.files.create(name="log.txt", content="", mime_type="text/plain")

file.content = "\n".join(lines)
file.save()

# And to replace it later
file.content = "…"
file.update()
Saving with no content is refused locally

The SDK throws before any request when content is undefined or null — an empty string, on the other hand, is a legitimate empty file.