Get an API key
run · write

createCollection

storage.run({ action: "createCollection", collection })

Creates an empty collection. Rarely needed — writing to a name creates it — but explicit when the structure is the point.

document databasefreerefuses a duplicate
Using Python?

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

await storage.run({ action: "createCollection", collection: "invoices" });
// { ok: true, created: "invoices" }
storage.run(action="createCollection", collection="invoices")
# {"ok": True, "created": "invoices"}

When you actually need it

An insert into a name no collection carries yet creates it. So this is for the cases where the structure must exist before anything is written: a setup step, a migration, an interface that lists collections before there is data.

An existing name is refused, with a readable message

The refusal says the collection already exists

Rather than the database's own code, which names a condition without saying what to do. If creating twice is harmless for you, treat the refusal as success.

async function ensureCollection(storage, collection) {
  const existing = await storage.run({ action: "collections" });
  if (existing.some((c) => c.name === collection)) return "already there";
  await storage.run({ action: "createCollection", collection });
  return "created";
}
def ensure_collection(storage, collection):
    existing = storage.run(action="collections")
    if any(c["name"] == collection for c in existing):
        return "already there"
    storage.run(action="createCollection", collection=collection)
    return "created"

It is a write, and it is asked for as one

Structural changes are in the same permission category as data ones — an agent is asked before creating a collection, in every mode but the most open. See the storage category.