Batch Save
Use Record.save_all() to create multiple records in parallel.
Lexicon type: procedure
function handle() local records = {} for _, item in ipairs(input.items) do local r = Record(collection, item) records[#records + 1] = r end Record.save_all(records)
local uris = {} for _, r in ipairs(records) do uris[#uris + 1] = r._uri end return { uris = uris }endHow it works
Section titled “How it works”- Iterate over
input.itemsand create aRecordinstance for each item. - Call
Record.save_all()to save all records in parallel, rather than one at a time. - Collect the resulting AT URIs and return them.
const response = await fetch("http://127.0.0.1:3000/xrpc/xyz.statusphere.batchCreate", { method: "POST", headers: { "X-Client-Key": CLIENT_KEY, Authorization: `Bearer ${TOKEN}`, "Content-Type": "application/json", }, body: JSON.stringify({ items: [ { text: "First", createdAt: "2025-01-01T00:00:00Z" }, { text: "Second", createdAt: "2025-01-01T00:01:00Z" }, ], }),});const data = await response.json();const response = await fetch("http://127.0.0.1:3000/xrpc/xyz.statusphere.batchCreate", { method: "POST", headers: { "X-Client-Key": CLIENT_KEY, Authorization: `Bearer ${TOKEN}`, "Content-Type": "application/json", }, body: JSON.stringify({ items: [ { text: "First", createdAt: "2025-01-01T00:00:00Z" }, { text: "Second", createdAt: "2025-01-01T00:01:00Z" }, ], }),});const data = await response.json();let response = client .post("http://127.0.0.1:3000/xrpc/xyz.statusphere.batchCreate") .header("X-Client-Key", client_key) .header("Authorization", format!("Bearer {}", token)) .json(&serde_json::json!({ "items": [ { "text": "First", "createdAt": "2025-01-01T00:00:00Z" }, { "text": "Second", "createdAt": "2025-01-01T00:01:00Z" } ] })) .send() .await?;body := `{ "items": [ { "text": "First", "createdAt": "2025-01-01T00:00:00Z" }, { "text": "Second", "createdAt": "2025-01-01T00:01:00Z" } ]}`req, _ := http.NewRequest("POST", "http://127.0.0.1:3000/xrpc/xyz.statusphere.batchCreate", bytes.NewBufferString(body))req.Header.Set("X-Client-Key", clientKey)req.Header.Set("Authorization", "Bearer "+token)req.Header.Set("Content-Type", "application/json")resp, err := http.DefaultClient.Do(req)curl -X POST http://127.0.0.1:3000/xrpc/xyz.statusphere.batchCreate \ -H "X-Client-Key: $CLIENT_KEY" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "items": [ { "text": "First", "createdAt": "2025-01-01T00:00:00Z" }, { "text": "Second", "createdAt": "2025-01-01T00:01:00Z" } ] }'Use case
Section titled “Use case”Batch saving is useful when a single user action should create multiple records (e.g. importing data, multi-step forms). save_all is significantly faster than calling r:save() in a loop because the PDS writes happen concurrently.

