api.files

Overview

Files kept on the account: created locally, saved to a storage, read back, replaced, deleted.

4 methods · 2 on the file1 credit to savereading is free
Using Python?

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

The shape is unusual and worth a sentence: create() makes nothing anywhere. It hands you an object you fill, and save() is what reaches the server. That separation is what lets the same object be written to disk, to the account, or to both.

The surface

CallDoesCosts
api.files.create({ name, content, mimeType })Builds a file object. No network.nothing
file.save({ storageId, path, localOnly })Writes it — to the account, to disk, or both.1 credit
file.update()Replaces the content of one already saved.nothing
api.files.get(sourceId)Reads one back, content included.nothing
api.files.list()Every file on the account.nothing
api.files.delete(sourceId)Removes it, and what was indexed from it.nothing

End to end

// 1. Build it — nothing has happened yet
const file = api.files.create({
  name: "report.md",
  content: "# Q4\n\nRevenue was…",
  mimeType: "text/markdown",
});

// 2. Save it — this is the call that spends
const saved = await file.save();
saved.sourceId;      // how you will find it again
file.sourceId;       // the object learned its own id

// 3. Read it back, anywhere
const again = await api.files.get(saved.sourceId);
again.content;       // "# Q4\n\nRevenue was…"

// 4. Replace its content
again.content = "# Q4\n\nRevised.";
await again.update();

// 5. Remove it
await api.files.delete(saved.sourceId);
# 1. Build it — nothing has happened yet
file = api.files.create(
    name="report.md",
    content="# Q4\n\nRevenue was…",
    mime_type="text/markdown",
)

# 2. Save it — this is the call that spends
saved = file.save()
saved["sourceId"]    # how you will find it again
file.source_id       # the object learned its own id

# 3. Read it back, anywhere
again = api.files.get(saved["sourceId"])
again.content        # "# Q4\n\nRevenue was…"

# 4. Replace its content
again.content = "# Q4\n\nRevised."
again.update()

# 5. Remove it
api.files.delete(saved["sourceId"])

Where a file actually goes

To the account's default storage, unless you name another with storageId. One kind of storage cannot take it at all.

A computer or a phone keeps its own files

Saving to one through the server is refused with storage_is_local, before any credit is spent — not a failure, a statement: those bytes live on that device. Read and write them from the device itself.

Which means api.files is for files on the account. For a machine's own files, see LocalFiles; for an object storage's contents, storage.run().

The category is deduced, not declared

mimeTypecategory
image/*image
audio/*audio
video/*video
json · yaml · xml · csvdata
anything elsedocument

It matters for one reason: a document is indexed for semantic search after it is saved, so it can be found by meaning later. Nothing else is.

Two things worth knowing before you build on it

  • Saving costs one credit, refunded in full if the write fails. Reading, listing and deleting cost nothing.
  • The file object is a handle you fill. create() never touches the network, so a validation mistake surfaces at save().