Uploads
Uploads add a recording or a transcript file as a teaching. The file bytes go straight to storage in parts, so large files do not pass through the API and an interrupted upload can resume.
Before you start
- A key with
teachings:ingest. - A recording (audio or video) or a transcript file (
.txt,.srt,.vttor.docx).
How an upload works#
- Start.
POST /uploadswith the file name and exact size. The response givespart_sizeandpart_count. - Get part URLs.
POST /uploads/{id}/partswith the part numbers to send next, 1 to 64 at a time. Each comes back with a short-lived URL and the exact number ofbytesto send. - Send the parts.
PUTexactly that many bytes to each URL, with no extra headers. Send up toparallelparts at once. - Finish.
POST /uploads/{id}/complete. Lectern checks that every part arrived, assembles the file, checks its size and type, creates the teaching and queues it.
Every part is part_size bytes except the last. The upload row stays open for about a day (see expires_at) and part URLs expire after 15 minutes: ask again for any part you did not send in time.
{
"status": true,
"message": "ok",
"data": {
"id": "upl_01m4h8mp8teepr7edaphqggw14",
"status": "created",
"kind": "transcript",
"filename": "grace.txt",
"mime": "text/plain",
"size_bytes": 205,
"part_size": 16777216,
"part_count": 1,
"parts": [],
"bytes_done": 0,
"duration_s": 0,
"duration_known": false,
"title": "Saved by grace",
"branch": {
"id": "brn_01m4h7y09deqtamqgs56j3gmb5",
"name": "Grace Community Church",
"slug": "hq",
"address": {}
},
"recorded_at": "2026-10-04T00:00:00Z",
"visibility": "church",
"language": "en",
"suggestions": {
"title": "grace"
},
"estimate": {
"seconds": 0,
"cost_usd": 0,
"processing_minutes": 1,
"free": true,
"hours_used": 0.06722222222222222,
"hours_cap": 40,
"hours_after": 0,
"over_cap": false
},
"expires_at": "2026-10-10T21:20:54Z",
"created_at": "2026-10-09T21:20:54Z"
},
"meta": {
"request_id": "req_01m4h8nry7eq2bfwf822ry0vwm"
}
}{
"status": true,
"message": "ok",
"data": {
"parts": [
{
"number": 1,
"url": "https://storage.example.com/uploads/upl_01m4h8mp8teepr7edaphqggw14/part-1?X-Amz-Expires=900&X-Amz-Signature=...",
"bytes": 205
}
],
"expires_at": "2026-10-09T21:35:54Z"
},
"meta": {
"request_id": "req_01m4h8nry7eq2bfwf822ry0vwm"
}
}Read the policy first#
/uploads/policyteachings:ingestDo not hard-code limits. The policy tells you the part size, how many parts to send in parallel, the largest file and transcript, the longest recording, the accepted extensions, and what the church has used this month.
{
"status": true,
"message": "ok",
"data": {
"enabled": true,
"part_size": 16777216,
"parallel": 4,
"max_file_bytes": 2147483648,
"max_transcript_bytes": 5242880,
"max_hours": 6,
"url_ttl_seconds": 900,
"media_extensions": [
".mp3",
".m4a",
".aac",
".wav",
".flac",
".ogg",
".opus",
".mp4",
".m4v",
".mov",
".webm"
],
"text_extensions": [
".txt",
".srt",
".vtt",
".docx"
],
"default_language": "en",
"usage": {
"active_uploads": 0,
"concurrent_cap": 8,
"stored_bytes": 1515,
"stored_cap": 536870912000,
"month_bytes": 1515,
"month_cap": 107374182400,
"hours_used": 0.06722222222222222,
"hours_cap": 40
},
"storage": {
"cors_checked": true,
"cors_ok": true,
"cors_problems": []
}
},
"meta": {
"request_id": "req_01m4h8nry7eq2bfwf822ry0vwm"
}
}| Field | Meaning |
|---|---|
| part_size, parallel | Bytes per part, and how many to send at once. |
| max_file_bytes, max_transcript_bytes, max_hours | The largest recording, the largest transcript file, and the longest recording. |
| media_extensions, text_extensions | Accepted extensions. |
url_ttl_seconds | How long a part URL works. |
usage | Uploads in progress, bytes stored, bytes this month and hours used, against their caps. |
storage.cors_ok | Whether browsers on the church’s own origin can send parts directly. See below. |
Upload from a server#
This is the recommended way. It reads the file in parts, sends several in parallel, and can resume an interrupted upload because it asks Lectern which parts are already stored.
import { open, stat } from "node:fs/promises";
import { basename } from "node:path";
async function uploadFile(path, { title, parallel = 4 } = {}) {
const { size } = await stat(path);
const { data: created } = await lectern("/uploads", {
method: "POST",
body: { filename: basename(path), size_bytes: size, title },
idempotencyKey: crypto.randomUUID(),
});
return resumeUpload(created.id, path, parallel);
}
async function resumeUpload(uploadId, path, parallel = 4) {
const { data: upload } = await lectern("/uploads/" + uploadId);
const stored = new Set(upload.parts.map((part) => part.number));
const missing = [];
for (let number = 1; number <= upload.part_count; number++) {
if (!stored.has(number)) missing.push(number);
}
const file = await open(path);
try {
for (let start = 0; start < missing.length; start += parallel) {
const { data: grant } = await lectern("/uploads/" + uploadId + "/parts", {
method: "POST",
body: { part_numbers: missing.slice(start, start + parallel) },
});
await Promise.all(
grant.parts.map(async (part) => {
const bytes = Buffer.alloc(part.bytes);
await file.read(bytes, 0, part.bytes, (part.number - 1) * upload.part_size);
const response = await fetch(part.url, { method: "PUT", body: bytes });
if (!response.ok) throw new Error("Part " + part.number + " failed with " + response.status);
}),
);
}
} finally {
await file.close();
}
const { data: finished } = await lectern("/uploads/" + uploadId + "/complete", {
method: "POST",
body: {},
idempotencyKey: "complete-" + uploadId,
});
return finished.teaching;
}
const teaching = await uploadFile(process.argv[2], { title: "Forgiveness that frees" });
console.log("Queued", teaching.id, teaching.status);The Go version needs path/filepath added to the imports from the quickstart.
Call resumeUpload with the upload id and the same file after a crash or a lost connection. It reads GET /uploads/{id}, sends only the missing parts, and completes the upload.
Upload from a browser#
A browser can send parts straight to storage, but the key must stay on your server. The page talks to three small endpoints on your own server, and your server calls Lectern with the key. Check the person is allowed to upload before you forward anything.
async function api(path, body) {
const response = await fetch("/api/lectern" + path, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.detail ?? parsed.message ?? response.statusText);
return parsed.data;
}
async function uploadFromBrowser(file, onProgress = () => {}) {
const upload = await api("/uploads", { filename: file.name, size_bytes: file.size, title: file.name });
const numbers = Array.from({ length: upload.part_count }, (_, index) => index + 1);
let sent = 0;
for (let start = 0; start < numbers.length; start += 4) {
const grant = await api("/uploads/" + upload.id + "/parts", { part_numbers: numbers.slice(start, start + 4) });
await Promise.all(
grant.parts.map(async (part) => {
const from = (part.number - 1) * upload.part_size;
const response = await fetch(part.url, { method: "PUT", body: file.slice(from, from + part.bytes) });
if (!response.ok) throw new Error("Part " + part.number + " failed with " + response.status);
sent += part.bytes;
onProgress(sent / file.size);
}),
);
}
const finished = await api("/uploads/" + upload.id + "/complete", {});
return finished.teaching;
}
document.querySelector("#recording").addEventListener("change", async (event) => {
const teaching = await uploadFromBrowser(event.target.files[0], (fraction) => {
document.querySelector("#progress").value = fraction;
});
document.querySelector("#result").textContent = "Queued " + teaching.id;
});This is the server side, which holds the key and forwards only what is needed:
import express from "express";
import { requireStaff } from "./auth.js";
const base = process.env.LECTERN_BASE_URL + "/v1/api/o/" + process.env.LECTERN_SLUG;
const app = express();
app.use(express.json());
app.use("/api/lectern", requireStaff);
async function forward(path, body, idempotencyKey) {
const headers = { Authorization: "Bearer " + process.env.LECTERN_API_KEY, "Content-Type": "application/json" };
if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
const response = await fetch(base + path, { method: "POST", headers, body: JSON.stringify(body) });
return { status: response.status, body: await response.json() };
}
app.post("/api/lectern/uploads", async (req, res) => {
const { filename, size_bytes, title } = req.body;
const result = await forward("/uploads", { filename, size_bytes, title }, crypto.randomUUID());
res.status(result.status).json(result.body);
});
app.post("/api/lectern/uploads/:id/parts", async (req, res) => {
const result = await forward("/uploads/" + encodeURIComponent(req.params.id) + "/parts", { part_numbers: req.body.part_numbers });
res.status(result.status).json(result.body);
});
app.post("/api/lectern/uploads/:id/complete", async (req, res) => {
const id = encodeURIComponent(req.params.id);
const result = await forward("/uploads/" + id + "/complete", {}, "complete-" + id);
res.status(result.status).json(result.body);
});
app.listen(process.env.PORT ?? 3000);A browser may only PUT to storage from an origin the church’s storage allows. Lectern sets this up for its own web app, and storage.cors_ok in the policy reports the state. If your page is served from another origin, parts fail with a CORS error in the browser. In that case send the file to your server and use the server upload above.
Step by step with curl#
curl -X POST "$LECTERN_BASE_URL/v1/api/o/$LECTERN_SLUG/uploads" \
-H "Authorization: Bearer $LECTERN_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"filename": "sermon.vtt", "size_bytes": 1515, "title": "Forgiveness that frees"}'
curl -X POST "$LECTERN_BASE_URL/v1/api/o/$LECTERN_SLUG/uploads/$UPLOAD_ID/parts" \
-H "Authorization: Bearer $LECTERN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"part_numbers": [1]}'
curl -X PUT --data-binary @sermon.vtt "$PART_URL"
curl -X POST "$LECTERN_BASE_URL/v1/api/o/$LECTERN_SLUG/uploads/$UPLOAD_ID/complete" \
-H "Authorization: Bearer $LECTERN_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{}'Upload states#
| Status | Meaning |
|---|---|
created | Started. No parts yet. |
uploading | Some parts are stored. |
completing | Lectern is assembling the file. |
ready | Done. The upload has a teaching, in status queued. |
aborted | Cancelled with DELETE /uploads/{id}. |
expired | Left open too long. |
failed | The file did not pass a check. failure says why. |
{
"status": true,
"message": "ok",
"data": {
"id": "upl_01m4h8mp8teepr7edaphqggw14",
"status": "ready",
"kind": "transcript",
"filename": "grace.txt",
"mime": "text/plain",
"size_bytes": 205,
"part_size": 16777216,
"part_count": 1,
"parts": [],
"bytes_done": 0,
"duration_s": 0,
"duration_known": false,
"title": "Saved by grace",
"branch": {
"id": "brn_01m4h7y09deqtamqgs56j3gmb5",
"name": "Grace Community Church",
"slug": "hq",
"address": {}
},
"recorded_at": "2026-10-04T00:00:00Z",
"visibility": "church",
"language": "en",
"suggestions": {
"title": "grace"
},
"expires_at": "2026-10-10T21:20:54Z",
"created_at": "2026-10-09T21:20:54Z",
"teaching": {
"id": "tch_01m4h8mpgtexd9dm3b93qkcmrs",
"title": "Saved by grace",
"recorded_at": "2026-10-04T00:00:00Z",
"duration_s": 0,
"status": "queued",
"visibility": "church",
"branch": {
"id": "brn_01m4h7y09deqtamqgs56j3gmb5",
"name": "Grace Community Church",
"slug": "hq",
"address": {}
},
"kind": "",
"standing": {
"state": "current"
}
}
},
"meta": {
"request_id": "req_01m4h8nry7eq2bfwf822ry0vwm"
}
}Uploading a transcript instead of a recording#
A .txt, .srt, .vtt or .docx file becomes a teaching without any transcription: the text you upload is the transcript, with origin set to import. Use this when you already have captions. Time-coded files (.srt, .vtt) keep their timestamps. Plain text has none, so each paragraph becomes a segment with an estimated time.
Limits and errors#
- Wrong extension, too large, too long, empty transcript:
422with a specific code such asunsupported_typeorfile_too_large. See Errors. - The church is out of hours or storage:
403withplan_hours_exhaustedorupload_quota_reached. - Too many uploads in progress:
429 too_many_uploads. Finish or cancel one. DELETE /uploads/{id}cancels an unfinished upload and removes what was stored. An upload that already became a teaching cannot be cancelled here.
If a video is too large, send just the audio. Lectern only needs the sound.