Skip to content
undertext developers
Skip to Content
undertext developers
REST API

Documents

Create documents, name them, set link access, move them to the trash, export them and read their provenance.

A document is what people write in the embedded editor: its text, its suggestions and comments, and the record of how it was written. Every document has one or more owners, and other people reach it as members or through its link access. See Documents and access.

The document object

AttributeTypeDescription
idstringUndertext's id for the document, starting doc_.
namestring or nullThe name an editor gave it, or null when it has none.
titlestringWhat to call it in your lists: its name, or its first line when it has no name.
ownersarrayThe Undertext ids of its owners, in the order they became owners.
link_accessstringWhat people get by link without being members: restricted, view, suggest or edit.
created_attimestampWhen it was created.
edited_attimestampWhen its text last changed.
trashed_attimestamp or nullWhen it was moved to the trash, or null.
{
  "id": "doc_8Hq2Lm4R",
  "name": "On the Analytical Engine",
  "title": "On the Analytical Engine",
  "owners": ["usr_5Kq2Lm8R"],
  "link_access": "restricted",
  "created_at": "2026-10-13T21:12:40Z",
  "edited_at": "2026-10-30T16:30:52Z",
  "trashed_at": null
}

Create a document

POST /v1/documents

Creates an empty document owned by owner, who becomes its first member, and sends document.created.

ParameterTypeDescription
ownerstring, requiredThe Undertext id of the user who owns it. The user must exist.
namestringUp to 120 characters, once trimmed. Without one, the document is called by its first line.
reuse_untouchedbooleantrue to answer with one of the owner's documents that nobody has touched yet, if there is one, instead of making another: none written in, named, shared or sealed. It comes back to the top of their list, with 200. For a "New document" button people may press again and again.
exceptarrayWith reuse_untouched, document ids not to reuse, such as the one already open.

Starting text isn't supported yet: markdown is refused with 400 invalid_parameter. People and agents write the text in the editor or through the MCP tools.

curl https://api.undertext.sh/v1/documents \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"owner": "usr_5Kq2Lm8R", "name": "On the Analytical Engine"}'

Returns the document with 201, or a reused one with 200.

{
  "id": "doc_8Hq2Lm4R",
  "name": "On the Analytical Engine",
  "title": "On the Analytical Engine",
  "owners": ["usr_5Kq2Lm8R"],
  "link_access": "restricted",
  "created_at": "2026-10-13T21:12:40Z",
  "edited_at": "2026-10-13T21:12:40Z",
  "trashed_at": null
}
ErrorWhen
400 invalid_parameter on nameLonger than 120 characters once trimmed.
400 invalid_parameter on markdownStarting text isn't supported yet.
404 user_not_foundowner doesn't exist. Create the user first.

Retrieve a document

GET /v1/documents/{document_id}

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"

Returns the document, or 404 document_not_found. Documents in the trash are returned with trashed_at set.

Update a document

PATCH /v1/documents/{document_id}

Renames a document or changes its link access. Only the fields you send change. People in the editor see a new name at once.

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
namestring or nullUp to 120 characters, once trimmed. null removes the name, so the document is called by its first line again.
link_accessstringrestricted, view, suggest or edit. See Share documents.
curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R \
  -X PATCH \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"link_access": "suggest"}'

Returns the updated document.

ErrorWhen
400 invalid_parameter on nameLonger than 120 characters once trimmed.
400 invalid_parameter on link_accessNot one of the four.

Lowering link access takes effect at once: people in the editor who came by link get the new role, or lose the document if it's now restricted.

Move a document to the trash

POST /v1/documents/{document_id}/trash

A document goes to the trash for everyone when an owner trashes it. While it's there, its owners can still open it in the editor, only to read; nobody else can, agents can't reach it, and its seals are down. It's listed with trashed=true on its owners' documents. Undertext deletes it 30 days after it was trashed, as if you had called Delete a document.

Any other member who trashes it puts it in their own trash only: it leaves their list and nobody else's, and they can still open it to read. After 30 days there, they stop being a member.

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
userstringThe Undertext id of the member trashing it. Leave it out to trash it as its first owner, for everyone.
curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/trash \
  -X POST \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"

Returns the document. With user, it has one more field, trash: "everyone" when it went to the trash for everyone, "own" when it went to the member's own, or null when it was there already.

{
  "id": "doc_8Hq2Lm4R",
  "name": "On the Analytical Engine",
  "title": "On the Analytical Engine",
  "owners": ["usr_5Kq2Lm8R"],
  "link_access": "restricted",
  "created_at": "2026-10-13T21:12:40Z",
  "edited_at": "2026-10-30T16:30:52Z",
  "trashed_at": "2026-10-30T18:20:00Z",
  "trash": "everyone"
}

Trashing a document that's already in the trash returns it unchanged.

ErrorWhen
403 not_memberuser isn't a member of the document.

Restore a document

POST /v1/documents/{document_id}/restore

Takes a document out of the trash, with its members, link access and agents' roles as they were. With user, it takes it out of that member's trash: an owner's restores it for everyone; anyone else's, for them.

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
userstringThe Undertext id of the member restoring it. Leave it out to restore it as its first owner.
curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/restore \
  -X POST \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"

Returns the document, with trash when you passed user, as for trashing.

Delete a document

DELETE /v1/documents/{document_id}

Deletes a document now, for everyone. Open editors close, agents lose it, its images are deleted, and every seal made from it is withdrawn: its pages at seal.undertext.sh say it was withdrawn. This can't be undone; to give people a way back, move it to the trash instead.

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R \
  -X DELETE \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
{
  "id": "doc_8Hq2Lm4R",
  "deleted": true
}

Export a document

GET /v1/documents/{document_id}/export

The document's text as it stands, as Markdown (text/markdown; charset=utf-8). Pending suggestions and comments are left out. The response body is the file itself, not JSON. HTML and Word come from the editor's export method for now.

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
formatstring, requiredmarkdown. Anything else is refused with 400 invalid_parameter.
curl "https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/export?format=markdown" \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
# On the Analytical Engine

The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.

Read a document's provenance

GET /v1/documents/{document_id}/provenance

Where a document's words came from and how it was written, read live under the current method. These are the numbers its seal would show if it were sealed now; a seal keeps the numbers it was sealed with. See Provenance for what each part means.

ParameterTypeDescription
document_idstring, path, requiredThe document's id.
curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/provenance \
  -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY"
{
  "document": "doc_8Hq2Lm4R",
  "method": "v0.2",
  "composition": { "typed": 85.8, "shaped": 10.2, "ai": 2.3, "external": 1.7 },
  "by_actor": [
    { "type": "person", "user": "usr_5Kq2Lm8R", "typed": 80.6, "shaped": 0, "ai": 0, "external": 1.7 },
    { "type": "person", "user": "usr_8Nf4Tq2W", "typed": 5.2, "shaped": 0, "ai": 0, "external": 0 },
    { "type": "agent", "agent": "agt_3Fv8Kq2Lm9Wd", "user": "usr_5Kq2Lm8R", "typed": 0, "shaped": 10.2, "ai": 2.3, "external": 0 }
  ],
  "presence": { "share": 99, "verified_share": 98, "verified": false },
  "prompts": 101,
  "sittings": 9,
  "duration": "11hr2min",
  "duration_minutes": 662
}
AttributeTypeDescription
methodstringThe version of the method that produced these numbers.
compositionobjectPercentages of the document by where its words came from, summing to 100: typed by people, shaped (agent text people revised), ai (agent text kept as written) and external (pasted or imported). Unrounded; a seal rounds them to whole numbers.
by_actorarrayEach contributor's part of composition, in the same four percentages, so the entries add up to it. Each names a person or an agent as webhook actors do: a person has their typed and pasted text, an agent its text. { "type": "unattributed" } is text nobody can be credited with, which counts as external. Empty for an empty document.
presenceobjectshare: percent of session time with a person present, or null before anyone has worked on it. verified_share: the part of it vouched for by check-ins. verified: true when every sitting people wrote in was verified.
promptsintegerRounds of back-and-forth with agents.
sittingsintegerSeparate stretches of work on the document.
durationstringSession time across those sittings, the minutes someone edited or was present, without the gaps within a sitting, as the seal line writes it, such as 11hr2min; empty when nothing was measured.
duration_minutesintegerThe same time in minutes; 0 when nothing was measured.

The editor's breakdown (the openBreakdown method) and each seal's page show who wrote what too.

On this page