api.files

file.save()

file.save({ storageId, path, localOnly }) → Promise<Result>

Writes the file — to the account, to the local disk, or to both. The one call here that costs a credit.

POST /api/files/save1 creditrefunded if the write fails
Using Python?

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

Parameters

storageIdstring

Which storage to write to. Without it, the account's default.

pathstring

Node only. Also write the bytes to this local path, creating the folders.

localOnlyboolean

With path: write locally and stop. Nothing is uploaded, nothing is charged.

The three ways to use it

// 1. To the account — the usual one
await file.save();

// 2. To the account AND to this machine, in one call
await file.save({ path: "./out/report.md" });

// 3. To this machine only — no request, no credit
await file.save({ path: "./out/report.md", localOnly: true });
// { ok: true, status: "saved_local", path: "./out/report.md" }
# 1. To the account — the usual one
file.save()

# 2. To the account AND to this machine, in one call
file.save(path="./out/report.md")

# 3. To this machine only — no request, no credit
file.save(path="./out/report.md", local_only=True)
# {"ok": True, "status": "saved_local", "path": "./out/report.md"}
A failed local write does not fail the call

If the path cannot be written, the SDK warns on the console and carries on to the upload. Check the file yourself when the local copy is the one that matters — a read-only folder will not raise.

Returns

{
  ok: true,
  status: "saved",
  sourceId: "…",            // how you find it again
  name: "report.md",
  category: "document",
  mimeType: "text/markdown",
  location: "object",       // the kind of storage it landed in
  metadata: {
    size: 2048,
    storageId: "…",
    remainingBytes: null,   // what is left, when the storage tracks it
    durationMs: 260
  },
  creditsUsed: 1
}
{
    "ok": True,
    "status": "saved",
    "sourceId": "…",            # how you find it again
    "name": "report.md",
    "category": "document",
    "mimeType": "text/markdown",
    "location": "object",       # the kind of storage it landed in
    "metadata": {
        "size": 2048,
        "storageId": "…",
        "remainingBytes": None,   # what is left, when the storage tracks it
        "durationMs": 260,
    },
    "creditsUsed": 1,
}

The object learns from it: file.sourceId, file.location and file.metadata are set, which is what makes update() possible straight afterwards.

Choosing where it goes

// The account's default
await file.save();

// A storage you named
const all = await api.storage.list();
const archive = all.find((s) => s.label === "Archive");
await file.save({ storageId: archive.id });
# The account's default
file.save()

# A storage you named
archive = next(s for s in api.storage.list() if s.label == "Archive")
file.save(storage_id=archive.id)
Storage kindSave to it
object · databaseyes — bytes are kept on the account
filesystem (a computer)refused: storage_is_local
phone · browserrefused: storage_is_local

The refusal comes before the credit is spent. It is not a failure to retry: those devices keep their own files, and the way to write them is from the device.

The credit, and when it comes back

  • One credit is taken before the write.
  • If the write then fails, it is refunded in full and you get 502 storage_failed.
  • A refusal that happens first — no storage, a local one, no content — costs nothing at all.

A document keeps being worked on after you get your answer

When the category is document, the text is indexed for semantic search once the response has been sent. So a file is immediately readable and findable-by-meaning a moment later.

Do not search for something you just saved, in the same breath

Indexing is deliberately not awaited — it keeps the save fast. A search run immediately afterwards may not see it yet.

Errors

CodeStatusWhenCredit
— (thrown locally)—content is undefined or null.none taken
missing_file_content400Neither a file nor text content reached the server.none taken
storage_not_found404The account has no storage at all.none taken
storage_is_local400The target is a computer or a phone.none taken
not_enough_credits402The balance will not cover it.none taken
storage_failed502The write itself failed.refunded
import { IaGenifyError } from "iagenify";

try {
  await file.save({ storageId });
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "storage_is_local") {
    // That storage is a device. Write it there instead.
    const device = await api.storage.get({ id: storageId });
    await device.files.write("report.md", file.content);
  } else throw err;
}
from iagenify import IaGenifyError

try:
    file.save(storage_id=storage_id)
except IaGenifyError as error:
    if error.code != "storage_is_local":
        raise
    # That storage is a device. Write it there instead.
    device = api.storage.get(id=storage_id)
    device.files.write("report.md", file.content)