api.files

file.update()

file.update() → Promise<Result>

Replaces the content of a file already saved. It takes no arguments: it sends whatever is on the object now.

PUT /api/files/:idfreeneeds a sourceId
Using Python?

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

The unusual part is that it reads the object rather than its arguments. Set file.content, call update(), and that is the new content.

const file = await api.files.get(sourceId);

file.content = "# Q4\n\nRevised after the audit.";
await file.update();
file = api.files.get(source_id)

file.content = "# Q4\n\nRevised after the audit."
file.update()

What it needs

ConditionOtherwise
file.sourceId is setthe SDK throws: there is nothing to update
file.content is not nullthe SDK throws: an empty file is not a content

Both are thrown locally, before any request. A file comes with its sourceId from get(), or acquires it on save() — so the natural sequence works and a freshly create()d object does not.

const file = api.files.create({ name: "notes.md", content: "…" });
await file.update();   // throws — never saved, so no sourceId

await file.save();     // now it has one
file.content = "…";
await file.update();   // fine
file = api.files.create(name="notes.md", content="…")
file.update()   # raises ValueError — never saved, so no source_id

file.save()     # now it has one
file.content = "…"
file.update()   # fine

Returns

{
  ok: true,
  message: "…",
  sourceId: "…",
  metadata: { size: 2048, mimeType: "text/markdown" }
}
{
    "ok": True,
    "message": "…",
    "sourceId": "…",
    "metadata": {"size": 2048, "mimeType": "text/markdown"},
}

It replaces, it does not append

The new content is the whole content. To add to a file, read it, concatenate, and update.

const file = await api.files.get(sourceId);
file.content = `${file.content}\n${newLine}`;
await file.update();
file = api.files.get(source_id)
file.content = f"{file.content}\n{new_line}"
file.update()
There is no previous version

The old content is gone. Read it first if it mattered — reading is free. A file whose history matters wants a new file per version, not an update.

What it does not change

ChangedUnchanged
The content, and its sizeThe name
The storage's remaining spaceThe mimeType, and so the category
The sourceId

So a text file cannot become an image by updating it. Save a new one for that.

Searchable text is not re-indexed

Semantic search still answers from the old text

Indexing happens on save. After an update, a search can return the version you replaced. Where that matters, delete and save again rather than update.

Errors

CodeStatusWhen
— (thrown locally)—No sourceId, or no content.
file_not_found404No file of this account with that id.
missing_content400Nothing usable reached the server.