# Build with an agent > Give Claude Code, Codex or another coding agent these docs and a prompt that adds Undertext to your app. These docs are written to be read by coding agents as well as people. Every page is plain Markdown at its own address plus `.md`, and the whole set is gathered in one file agents can fetch in one go. | File | What's in it | | --- | --- | | [`/llms.txt`](/llms.txt) | The map: what Undertext is, and every page with what it covers | | [`/llms-full.txt`](/llms-full.txt) | Every page, in full | | `/.md` | One page, e.g. [`/quickstart.md`](/quickstart.md) | Each page also has a **Copy Markdown** button under its title, for pasting one page into a chat, and an **Open** menu with the page as Markdown and links that hand it to ChatGPT, Claude and other assistants. ## A prompt that adds Undertext to your app Paste this into Claude Code, Codex or your agent of choice from the root of your project. Put your development platform's key in your environment first, so the agent never needs to see it. ```text title="prompt.txt" Add the Undertext editor to this app using the Undertext API. Read https://docs.undertext.sh/llms-full.txt first. Then: 1. Install @undertext/sdk (server) and @undertext/embed (browser). 2. Keep every Undertext call on the server, with the key from UNDERTEXT_SECRET_KEY. Never send the key to the browser. 3. Add an undertext_user_id column to our users. When a user signs up or changes their name or picture, PUT them to /v1/users/external/{our user id} and store the Undertext id it returns. 4. Store an Undertext document id beside each of our documents. Create the Undertext document when ours is created, with our user's Undertext id as owner. 5. Add a POST route that checks our own session and permissions, then creates an Undertext editor session for that user and document and returns the token. 6. Mount the editor where we show a document, with getToken calling that route. 7. Add a webhook route that verifies the Undertext-Signature header and logs events. Use our existing auth, routing and styles. Show me the plan before writing code. ``` Adjust step 4 to how your app stores documents. If your app already has sharing, ask the agent to mirror it into [members](/reference/api/members) as well. ## Keep the docs in reach Add a line to the instructions file your agent reads (`CLAUDE.md`, `AGENTS.md` or similar), so it checks the docs instead of guessing: ```md title="AGENTS.md" ## Undertext We embed the Undertext editor. Before changing anything that calls the Undertext API, read the relevant page from https://docs.undertext.sh/llms.txt (each page is also at its path plus .md). Use a platform of its own for development; never log or expose UNDERTEXT_SECRET_KEY. ``` ## Things agents tend to get wrong - **Calling Undertext from the browser.** Everything but the editor itself goes through your server. The browser only gets editor session tokens. - **Treating Undertext as the account system.** Undertext has no sign-in. Your session check comes first, then the Undertext call. - **Passing your own ids where Undertext ids go.** Your id for a user goes in one place, `PUT /v1/users/external/{external_id}`. Everything else takes the Undertext id (`usr_…`) that call returns, so store it beside your user. - **Skipping signature checks on webhooks.** Verify `Undertext-Signature` before trusting an event. The Node SDK's `undertext.webhooks.verify` does it in one call. - **Mixing up the two MCP servers.** Your users' agents connect to `mcp.undertext.sh/` to work in documents. That is a feature for your users, not a tool for building your app. # Changelog > What changed in the Undertext API, the embed script, the Node SDK and the MCP server. Changes to `/v1` are additive: new endpoints, new optional parameters, new fields in responses and new event types. Your code should ignore fields and event types it doesn't know. A change that would break existing code ships as a new version, with at least 12 months in which both work. See [Versioning](/reference/api/overview#versioning). ## 27 November 2026 - **Your people choose how often check-ins come**: list the intervals they may pick from in [`PATCH /v1/platform`](/reference/api/platform#update-the-platform)'s new `checkin_choices`, or in the console's Check-ins section. `checkin_minutes` stays your default and is always among them. Each person picks one in presence settings, for all their documents; someone whose choice you stop offering is asked at your default. Empty, as unless you set it, nothing changes. The platform object gains `checkin_choices`, and the Node SDK (`@undertext/sdk` 0.4.0) takes it in `platform.update`. - **Presence** counts a person's minutes only within five minutes of their own edits, before or after: moving in the editor, or keeping it open, longer away from their writing counts neither way, as a sitting only read in already didn't. A seal's time, `9 sessions, 11hr2min`, is the session's minutes, the gaps within its sittings left out, where it ran from each sitting's first minute to its last; [provenance](/reference/api/documents#read-a-documents-provenance)'s `duration` and `duration_minutes` follow. [Verified Presence](/concepts/presence-and-check-ins#verified-presence) verifies all of a person's presence in a sitting whose writing their check-ins vouch for, so someone who passes every check-in is verified throughout. Documents being written read under this now; published seals keep their numbers. The method stays `v0.2`, as it has for earlier fixes to presence. - **Editor**: in the seal dialog, changes to who can read its seals (public or private, the readers listed, the password) wait for **Save**. Leaving Who can read, or closing the dialog, with changes not saved asks whether to save them. ## 23 November 2026 - **MCP server**: `tools/list` shows each tool's input schema, your platform's tools too, without `additionalProperties` and without an empty `properties`, which Gemini's connected apps can't read; a tool that takes no arguments is `{"type": "object"}`. What a tool accepts is unchanged. ## 21 November 2026 - **MCP server**: Gemini connects as a custom connected app. Dynamic client registration gives a client that asks for `client_secret_basic` or `client_secret_post` a `client_secret`, which it then gives at the token endpoint by HTTP Basic or in the form; such a client keeps its refresh token when it uses it, as Google asks, where a public client's still changes each time. The authorization server's metadata lists all three ways in `token_endpoint_auth_methods_supported`. ## 16 November 2026 - **Sealing and sharing are two flows**: sharing is for working on the document; a seal is its proof to others. A document's owners seal it, choose who reads its seals, and withdraw versions, where editors could before. Everyone who can open the document still sees its seals, and can read private ones. - **REST API**: [`POST /v1/documents/{document_id}/seals`](/reference/api/seals#seal-a-document) seals for one of the document's owners, and refuses anyone else with `403 not_owner`, which replaces `not_editor`. - **Editor**: the seal dialog opens on the seal: its newest version, whether it matches the document, its link, and **Seal new version** once it doesn't. Who can read and Versions are each a step in. Its editors see who reads its seals, the readers listed and whether there's a password, without changing them. - **Asking to read a private seal**: someone signed in on your seal page, whose email your seal session vouched for, and whom a private seal turns away, can ask its owners to let them read it, with a message, in the seal's frame. Its owners see how many are asking on the seal dialog's Who can read, which opens each request to let them read, adding their email to its readers, or decline. - **Webhooks**: [`seal_request.created`](/reference/webhooks#seal_requestcreated), with the owners to tell, then `seal_request.accepted` or `seal_request.declined`. - **Embed**: a private seal's page tells a reader with a session it isn't shared with who it isn't shared with, whether or not you vouched for an email, rather than offering to sign in. ## 15 November 2026 - **Seal line on exports** (`v1.js`, and `@undertext/embed` 0.4.1): `editor.export(format, { sealLine: true })` and `editor.print({ sealLine: true })` end the document with its newest seal's line, the seal's address linking to its page: a final linked line in Markdown and HTML, a last paragraph in Word, and small type at the end of the PDF. While the document no longer reads as its newest seal does, `export` rejects with an error whose `code` is `seal_changed`, or `not_sealed` with no seal: method errors now carry a `code` where the method documents one. - **Verified Presence, a document at a time**: each person turns [Verified Presence](/concepts/presence-and-check-ins#check-ins) on in the documents that need it, a switch of their own, and is asked to check in only while writing there, about every 5 minutes. A check-in still counts wherever it was asked: a tap vouches for their writing in every document at the time, and one still waiting shows in whichever document they write in next. People who had check-ins on have Verified Presence on in every document they'd written in; the interval they chose goes, and check-ins already kept vouch as they did. - **REST API**: [`PUT /v1/documents/{document_id}/checkins/{user_id}`](/reference/api/users#turn-verified-presence-on-or-off-in-a-document) turns it on or off for a user, refusing to turn it on without a key with `409 no_security_keys`, and [`GET`](/reference/api/users#retrieve-verified-presence-in-a-document) reads it. This breaks with the rule above: people no longer choose how often they're asked, so `PUT /v1/users/{id}/checkins` is gone, and [`GET`](/reference/api/users#retrieve-a-users-security-keys) gives only `security_keys`, without `every_minutes`. - **Embed** (`v1.js`, and `@undertext/embed` 0.4.0): the [`status` event](/reference/embed#events) gains `verifiedPresence`, `{ on }`, or `null` for someone who can't write in the document, and [`editor.setVerifiedPresence(on)`](/reference/embed#methods) turns it on or off. Without a key it stays off and the editor sends `presence-settings`; it turns on once the person comes back to the editor with a key. Presence settings no longer choose an interval, and what they report is only `keys`, without `everyMinutes`. - **Node SDK** (`@undertext/sdk` 0.3.0): `documents.retrieveCheckins` and `documents.updateCheckins`; `users.updateCheckins` is gone, and `users.retrieveCheckins` gives only `security_keys`. - **Editor**: the breakdown's Hardware key row turns it on or off for you, where it linked to presence settings. A check-in's card sits beside the seal, no longer at the foot of the page. - **Platforms choose how check-ins work**: a platform can require Verified Presence of everyone writing in its documents, and choose how often check-ins come, in the console's Check-ins section or with [`PATCH /v1/platform`](/reference/api/platform#update-the-platform)'s `checkins_required` and `checkin_minutes` (`1`, `5`, `10` or `30`; `5` unless set). Required, it's on for everyone, with no switch to turn it off, and someone without a key is asked all the same, with the card offering to add one. The breakdown's Hardware key row says how often the check-ins came. - **REST API**: the platform object gains `checkins_required` and `checkin_minutes`. [Verified Presence in a document](/reference/api/users#retrieve-verified-presence-in-a-document) gains `required`, and turning it off where it's required answers `409 checkins_required`. - **Embed** (`v1.js`, and `@undertext/embed` 0.4.0): the `status` event's `verifiedPresence` gains `required`, and `setVerifiedPresence(false)` leaves it on where it's required. - **Node SDK** (`@undertext/sdk` 0.3.0): `platform.update` takes `checkins_required` and `checkin_minutes`. - **Seals**: anyone who can edit a document can seal it and choose who reads its seals, not only its owners. In the editor that's whoever edits it, as a member or by its link; [`POST /v1/documents/{id}/seals`](/reference/api/seals#seal-a-document) seals for a member who edits it, and refuses anyone else with `403 not_editor`, which replaces `not_owner`. In the seal dialog, whoever sealed a version can withdraw it, and an owner can withdraw any. A seal's `sealed_by` can now be an editor. - **Editor**: everyone who can open a document sees its seals in the seal dialog, with their links and who reads them, not only its owners. Only its editors see the readers listed and whether there's a password. - **Private seals** open to whoever can open the document: its members, as before, and, while its link lets anyone in, anyone with a [seal session](/reference/api/sessions#for-seals), with or without an email. A seal's page can't tell who has the document's link, so the seal's link stands in for it. - **Seal pages** say who sealed the version, by the name they had then, and so does each version in the seal dialog. - **Wording**: the editor and seal pages say seal, not publish: a private seal's page reads "This seal is private", and a withdrawn version's page says when it was taken down, no longer that its author deleted it, as an owner may have. ## 14 November 2026 - **MCP server**: people can mention their own agents, in a comment or the text, to ask something of them, and each agent has an inbox of what it was asked. [`list_inbox`](/reference/mcp#inbox) lists what it hasn't dealt with, the whole thread for a comment, and [`mark_inbox_read`](/reference/mcp#inbox) takes items out, as replying in or resolving the thread does. `list_documents` and `read_document` say when the inbox holds something, and the server's instructions tell agents to look there, and who they are. `list_people` lists the agent's own person among the people, and the person's other agents after them, so an agent can tell its person what it did and agents can mention each other. A mention of an agent is written `@[Research](agent:agt_4Rk8Vn2Lp7Qs)`, in a comment or in the text's Markdown. - **Editor**: typing `@` lists your own agents, with their bot, after the people who may be mentioned. - **Webhooks**: a mention of an agent sends no `mention.created`, and isn't among a thread event's `mentions`. An agent's mention of its own person now sends one, and is among `mentions`. ## 13 November 2026 - **Agents**: a person can name their agents, as they approve them or later. [Approving an agent request](/reference/api/agent-requests#approve-an-agent-request) takes a `name`, and [retrieving one](/reference/api/agent-requests#retrieve-an-agent-request) for a `user` gives the `agent` of theirs it would update, with the name they gave it. [`PATCH /v1/agents/{agent_id}`](/reference/api/agents#update-an-agent) takes a `name` (with `access` now optional), the agent object gains `client_name`, what its client calls itself, and approving the same client again keeps the name. A new name shows at once in the documents open now. Node SDK: `agents.update` and `agentRequests.approve` take `name`, and `agentRequests.retrieve` takes `user`. Agents and agent requests' clients gain `local`: an app on the person's own device, coming back to a loopback address or its own scheme, whose host says nothing to check. - **Embed** (`v1.js`, and `@undertext/embed` 0.3.0): - The editor's `rails` option is gone, and a `rails` you pass is ignored. The attribution rail now shows with [`highlight`](/reference/embed#options), on the left, so like highlighting it's off until the person or your page turns it on. - [`headerItems`](/reference/embed#options) puts your own buttons in the editor's header, such as a menu or a notification bell, which the editor lays out with its own; a click sends a `command` event with the button's `anchor`, for your page to open its menu or panel there, and whether what it opens was `expanded`. `headerStart` and `headerEnd`, which kept room for controls laid over the frame, are gone. - `sealNote`, a line of your own in the seal dialog, is gone, and one you pass is ignored. - `@undertext/embed` 0.3.0 also has the [`chrome`](/reference/embed#options) and `commentPane` options and the [`focus` event](/reference/embed#events), which `v1.js` already had. - **Editor**: typing `@` in the text lists the people who may be mentioned there, as in a comment, and the one taken is written as a mention, `@Grace Hopper`, which tells them. It's text, so it can be suggested, and Backspace just after it takes the whole name. Where there's room beside the text, the panel of comments and suggestions runs from the top of the frame to the bottom, and the header and the text make way for it; otherwise it still opens over the text, under the header. Along the top, the format bar keeps to one row: the buttons there isn't room for, beside the panel, a wide sidebar or on a phone, go under » at its end, rather than the bar taking a row of its own. From the keyboard, the format bar is one Tab stop, the arrow keys moving along its buttons, so Tab reaches what's after it at once. - **Webhooks**: [`mention.created`](/reference/webhooks#mentioncreated) is sent for mentions in the text too, a minute after they're written, with a `block_id` and null `thread_id` and `message_id`. Every `mention.created` gains `author`, who wrote the mention with the name they wrote it under, and `block_id`, null for a mention in a message. - **Markdown**, in the REST export, `editor.export("markdown")` and what agents read and write: a mention in the text is written `@[Grace Hopper](user:usr_9Tb3Wc1X)`, as in a comment, and an agent writing one mentions that person. ## 8 November 2026 Proof is now Undertext, and seals can be shown on your own site. These are the breaks with the rule above: no old name or host keeps working, and reader requests are gone. - **Seals on your site**: your platform's [`seal_url`](/reference/api/platform), such as `https://acme.com/seals/{code}`, is where seals' `url` and seal lines point. [`mountSeal`](/reference/embed#mountseal) (`@undertext/embed` 0.2.0) shows a seal there, drawn by Undertext in a frame from `embed.undertext.sh`, and the seal object's `preview` gives a public seal's link-preview tags. Every seal stays at `seal.undertext.sh/` as Undertext's own page. See [Show seals on your site](/guides/seal-and-verify#show-seals-on-your-site). - **Private seals**: readers get in with a [seal session](/reference/api/sessions#for-seals) (`POST /v1/sessions` with `purpose: "seal"` and the email you've verified), which `mountSeal` asks your page for. Reader requests, `reader_url` and `/v1/reader-requests` are gone, and so is `readerRequests` in the Node SDK (`@undertext/sdk` 0.2.0). What a seal's password earns is a token the page keeps, not a cookie. - **Node SDK** (`@undertext/sdk` 0.1.0, was `@exalto/proof`): the client is `Undertext` and its errors are `UndertextError`. `@undertext/sdk/roles` and `@undertext/sdk/people` replace `@exalto/proof/roles` and `@exalto/proof/people`. - **Embed** (`v1.js` and `@undertext/embed` 0.1.0, was `@exalto/proof-embed`): `v1.js` is at `https://embed.undertext.sh/v1.js` and defines `window.Undertext`. `@undertext/embed/links` and `@undertext/embed/protocol` replace the old subpaths. The editor and presence settings name their platform in ``. - **Hosts**: the REST API is at `api.undertext.sh/v1`, the editor at `embed.undertext.sh`, the MCP server at `mcp.undertext.sh/`, seal pages at `seal.undertext.sh/`, and seal lines begin with that address. The console is at `undertext.sh/console` and these docs at `docs.undertext.sh`. - **Headers**: webhooks and calls to your own agent tools are signed in `Undertext-Signature` and sent as `Undertext-Webhooks/1` and `Undertext-Tools/1`. Every API response carries `Undertext-Request-Id`. - **Domain verification** reads a TXT record at `_undertext.` holding `undertext-verification=`. ## 2 November 2026 - **Embed** (`v1.js` and `@exalto/proof-embed` 0.0.4): The editor opens only documents of the platform whose embed origins may frame it, and takes messages only from the page that frames it; framed presence settings likewise open only for a person of their platform. `target` events name only cards whose ids a link could. `getToken` is asked only for the document open or the one opening in its place, whatever the frame names. Without an `origin`, `v1.js` takes the one it was loaded from, and a page's own bundle of the package, loaded as a script, takes `https://embed.proof.exalto.ai` rather than its own address. - **REST API**: sealing a document that reads exactly as its newest seal returns that seal with `200`, rather than refusing with `409 unchanged`. A document's [provenance](/reference/api/documents#read-a-documents-provenance) gains `by_actor`, each person's and agent's part of its composition, and `duration_minutes`. - **Node SDK** (`@exalto/proof` 0.0.3): `documents.provenance` resolves to a `Provenance`, and `Seal` types every field of the seal object. `@exalto/proof/roles` and `@exalto/proof/people`, whose names the root exports too, ship in it. - **MCP server**: a client gives at most 10 redirect URIs of up to 2,000 characters, each over https, on a loopback address or in an app's own scheme (never `javascript:`, `data:` or `file:`), and a `logo_uri` longer than that is ignored; a client ID metadata document is read up to 64 kB. One address (an IPv6 one by its /64) can register 100 clients, and start 100 authorizations, an hour. A refresh token used again within a minute of its first use, as by two requests at once, gets new tokens instead of ending all the agent's. - **Your own agent tools**: an answer over 1 MB reaches the agent as a failed call. - **Editor**: outside suggest mode, what you type inside someone else's suggestion splits it and stays yours, rather than joining it. A suggestion written in someone else's name, or words put under someone else's suggestion, the server takes back. - **Markdown**, in the REST export, `editor.export("markdown")` and what agents read and write: underlined text is written `like this` rather than `++like this++`, so text such as "C++ beats C++" is no longer read as underlined. ## 1 November 2026 - **Embed** (`v1.js` and `@exalto/proof-embed` 0.0.3): - `editor.open(document)` opens another document in the same editor, without loading it again; `getToken` is passed the document it's for. - A `target` event names the card that's open, for your page's address, and `editor.closeDialog()` closes the editor's dialog from your page. - Presence settings gain `setOptions({ colorScheme })`, and `openPresenceSettings` takes a `colorScheme`. - Frames start in the colour scheme you chose, with no light frame first in dark mode. While offline, tokens are asked for again once back online rather than counted as refused. - **Editor**: Copy link on a card gives your `document_url`, and ⌘P prints the document. `editor.export("html")` leaves out pending suggestions, as the other formats do, and is sanitized. - **MCP server**: An edit whose Markdown links anywhere but an http, https, mailto or tel address or a relative one, or shows an image from anywhere but an http or https address or one stored with the document, is refused, saying why. A code block's language is its fence's first word. - **Markdown**, in the REST export, `editor.export("markdown")` and what agents read, escapes link and image addresses, titles and alt text, and fences code with more backticks than it holds. ## v1 The first release of the Proof API. - **REST API** at `api.proof.exalto.ai/v1`: users, documents, members, sessions, agents, agent requests, seals and reader requests, webhook endpoints, and platform settings with your own agent tools. - **Embed script** `v1.js` and `@exalto/proof-embed`: the editor with suggestions, comments, the live seal and check-ins, and presence settings, framed or in a window. - **Node SDK** `@exalto/proof`. - **MCP server** at `mcp.proof.exalto.ai/` for each platform, with the same document, editing, suggestion and comment tools as Undertext's own agents, and your own tools beside them. - **Webhooks** for threads, mentions, documents, seals and agents, signed with `Proof-Signature`. Suggestion and missed check-in events are reserved, not yet sent. - **Seal method** v0.2, the same method Undertext seals with. # Agents > An agent is an AI client a person connected to their documents on your platform, acting for that person alone. An **agent** is an AI client, such as Claude Code, Codex or any other MCP client, that one of your users approved to work in their documents. It reads, writes, suggests and comments through Undertext's MCP server, and everything it writes is credited to it. An agent acts for exactly one person on one platform. ## Your MCP address Each platform has its own MCP server address, made from your slug: ```text https://mcp.undertext.sh/acme ``` You show this address in your product, usually on a settings screen with a ready-made command or install link for each kind of agent. An agent needs nothing else: from the address, it finds Undertext's sign-in, registers itself and asks its person to approve it. An agent's tokens work only at the address they were issued for. Someone who uses two platforms built on Undertext connects their agent to each separately. Agent clients keep tools from different servers apart, so the two connections sit side by side. ## Approving an agent Undertext has no accounts, so the approval step happens on your site: 1. The agent asks Undertext to connect, and Undertext sends the person's browser to your **consent URL** with a request id. 2. Your page signs the person in if needed and fetches the request: the agent's name and its verified domain, such as "Claude Code (claude.ai)". 3. The person names it, if they like, and allows or denies it. Your server tells Undertext which user it is, what they call the agent, and which documents it may reach. 4. Undertext finishes the connection and issues the agent's tokens straight to the agent. Your platform never holds an agent's tokens, so it can't act as the agent. [Connect agents](/guides/connect-agents) walks through building the consent page. An agent's domain is checked: it's where the agent's own metadata document lives, or where it sends people back to. Two agents can share a name; the domain tells them apart. ## What an agent may reach An agent's access is one of two kinds: | Access | The agent reaches | | --- | --- | | `all` | Every document its person can open, by membership or by link, editing at most. The default. | | `chosen` | Only the documents its person gave it a role in: `editor`, `suggester` or `viewer`. | Whichever it is, an agent can do at most what its person can do right now. Undertext checks the lower of the agent's grant and the person's current role on every call, so when Ada loses access to a document, Ada's agents lose it too. Agents never own documents and never get more than `editor`. An agent can also start documents for its person. They're owned by the person, with the agent as an editor, and Undertext sends you `document.created` so the document shows up in your lists. ## Suggesting by default Agents are told to propose changes as suggestions unless their person asked them to edit directly. Where an agent may only suggest, every edit it makes becomes a suggestion anyway. People accept or reject each one in the editor; an accepted suggestion an agent wrote counts as [AI](/concepts/provenance) until a person changes its words. ## Credit Every word an agent writes, every comment and every read is recorded under the agent, with its person's name beside it: ```text Claude Code (Ada Lovelace's agent) ``` An agent is called what its client calls itself, such as Claude Code, until its person gives it a name of their own, such as Research: as they approve it, or later, which you set with [`PATCH /v1/agents/{agent_id}`](/reference/api/agents#update-an-agent). Like a person's, an agent's name is the current one wherever it shows, and so is its person's: renaming either updates the documents open now. The breakdown behind a seal lists each agent's reads and edits. ## What agents can do Agents work through Undertext's tools: listing and searching documents, reading them as Markdown, editing blocks and text, accepting and rejecting suggestions, commenting, mentioning people, handling images, and reading their inbox. The [MCP tools reference](/reference/mcp) lists them all. ## Mentioning an agent People ask their agents for things where they work, as they ask each other: by mentioning them. Typing `@` in a comment or the text lists your own agents after the people, and mentioning one puts the request in that agent's inbox, which it checks with `list_inbox`. An agent answers in the thread, or does what it was asked in the text, and can mention you back to tell you what it did. You can mention only your own agents, so nobody else directs yours; anyone else's agent is only a name. See [Mentioning agents](/reference/mcp#mentioning-agents). Undertext's tools cover what's inside documents. Folders, pins and anything else your product keeps for itself aren't there. If you want agents to reach those, register tools of your own, which Undertext's server lists beside its own and forwards to your server; see [Add your own agent tools](/guides/your-own-agent-tools). When an agent and a person write in the same document at once, people's edits always go first. Each agent request gets a short slice of work at a time, so a burst of agent edits never holds typing back. ## Removing an agent `DELETE /v1/agents/{agent_id}` removes an agent and revokes its tokens at once. Its words stay in documents, still credited to it. People usually do this from a list of their agents in your settings, which `GET /v1/users/{user_id}/agents` provides, where they name them too. Undertext sends `agent.connected` and `agent.revoked`, so the list stays current however an agent arrives or leaves. Deleting a user revokes their agents. [Merging](/concepts/users) a user moves their agents to the user they join. ## Related - [Connect agents](/guides/connect-agents) - [Agents reference](/reference/api/agents) and [Agent requests reference](/reference/api/agent-requests) - [MCP tools](/reference/mcp) # Documents and access > What a document holds, who may do what in it, and how people get into the editor. A **document** is one piece of writing and its whole record: the text, its images, comments and suggestions, who wrote each word, and the seals made from it. Undertext stores all of that. Your product decides who can reach which document, and Undertext enforces it in the editor and for agents. ## What Undertext keeps and what you keep Undertext keeps what has to be on the record, and nothing about how your product is organised. | Undertext keeps | You keep | | --- | --- | | The text, images, comments and suggestions | Folders, pins, favourites and ordering | | The document's name | Your document list and search screens | | Members, their roles, and link access | Invitations, share dialogs and emails | | Who wrote what, presence and check-ins | Notifications (Undertext sends you [events](/reference/webhooks)) | | Seals | Anything else your product shows around the editor | `GET /v1/users/{user_id}/documents` lists the documents a user is a member of, most recently edited first. Most platforms show that list with their own folders and pins laid over it, keyed by document id. ## Names and titles A document's **name** is set by an editor, in the editor or with `PATCH /v1/documents/{id}`. Its **title** is what to show: the name if it has one, otherwise the document's first line. Show `title` in your lists and it stays right as people write. ## Roles Each member has one role. Undertext checks it on every change, in the editor and over MCP. | Role | May | | --- | --- | | `owner` | Everything an editor may, and withdraw any seal, trash and delete. A document has one or more owners, and always at least one. | | `editor` | Write, rename, accept and reject suggestions, comment, seal, choose who reads its seals, and withdraw the seals they made. | | `suggester` | Propose changes as suggestions, and comment. Their edits never change the text until an editor accepts them. | | `viewer` | Read, and see comments and its seals. | You set roles with `PUT /v1/documents/{id}/members/{user_id}`. Setting someone's role to `owner` makes them an owner too; to hand a document over, then lower the old owner's role. Lowering or removing the last owner is refused. A role change reaches open editors at once: someone made a viewer reloads unable to type, and someone removed sees the document close. Agents act with at most `editor`, never `owner`, and never more than their person's current role. See [Agents](/concepts/agents). ## Link access A document can also be open to anyone you send through its link. `link_access` is one of: | Value | People who come by link get | | --- | --- | | `restricted` | Nothing. Only members can open it. This is the default. | | `view` | `viewer` | | `suggest` | `suggester` | | `edit` | `editor` | Undertext doesn't know your document URLs, so "came by link" is your call: when someone who isn't a member opens your page for a document, start their session with `via: "link"`. They get the link's role, or are refused if access is `restricted`. A member always gets the higher of their own role and the link's. People who come by link are still users. Give them an id and a name first, even a made-up one for someone signed out; see [Anonymous users](/guides/anonymous-users). ## Sessions are the only way in Nobody opens a document in the editor without a **session**: a token your server asks for with `POST /v1/sessions`, naming one user and one document. Undertext works out the user's role when it issues the token and refuses one for a user who may not open the document. The token lasts 15 minutes; the embedded editor asks your page for a new one before it lapses, so your server can refuse when access has ended. Because a session is for one user and one document, a token that leaks from a page reaches only that document, as that person, for a few minutes. See [Embed the editor](/guides/embed-the-editor). ## Trash and deletion - **Trash.** An owner, or their agent, can move a document to the trash for everyone. It disappears from everyone's lists, agents can't reach it, its seals are down, and only its owners can still open it, to read. `POST /v1/documents/{id}/restore` brings it back. After 30 days in the trash it is deleted. Another member who trashes it puts it in their own trash: it leaves only their list, and after 30 days they leave the document. - **Delete.** `DELETE /v1/documents/{id}` deletes it for everyone at once, agents included. Open editors close, its images are deleted, and its seals are withdrawn: their pages say so. Deleting can't be undone. Undertext sends `document.trashed`, `document.restored` and `document.deleted` events for trashing for everyone, restoring and deleting, so your lists stay in step when an agent does it. ## Images People drop or paste images into the text. Undertext resizes each to fit 1.9 MB in the browser, stores up to 100 MB of images per document, and serves them only to people who may open the document. Deleting the document deletes them. ## Related - [Share documents](/guides/share-documents) - [Documents reference](/reference/api/documents) and [Members reference](/reference/api/members) - [Sessions reference](/reference/api/sessions) # Platforms and keys > A platform is your product as Undertext knows it, set up in the console and reached with secret keys. A **platform** is your product as Undertext knows it. Everything you create through the API belongs to one platform: its users, documents, agents, seals and webhook endpoints. Platforms never see each other's data. A user `usr_5Kq2Lm8R` on Acme Notes and a user `usr_5Kq2Lm8R` on another platform are two unrelated people. Undertext's own app, at undertext.net, is a platform too. It uses the same API and the same keys you do. ## Console settings You create a platform in the [console](https://undertext.sh/console). Its settings decide how Undertext presents and protects your product. | Setting | What it does | | --- | --- | | Name | Shown wherever Undertext speaks for you, most visibly on seal pages: "Written in Acme Notes". | | Slug | A short, permanent id, such as `acme`. It is part of your MCP address, `https://mcp.undertext.sh/acme`, so pick it once. | | Embed origins | The origins allowed to show the editor, such as `https://acme.com`. The editor refuses to load in a frame anywhere else. | | Consent URL | The page on your site where people approve an agent, such as `https://acme.com/undertext/connect`. See [Agents](/concepts/agents). | | Icon URL | The icon agents' apps show beside your platform's MCP server. | | Document URL | Where your product shows a document, such as `https://acme.com/docs/{document}`, for links between documents and in agents' answers. | | Seal URL | Where your product shows a seal, such as `https://acme.com/seals/{code}`. Seal links and seal lines name it. See [Seals](/concepts/seals#the-seal-page). | | Domain | Your domain, such as `acme.com`, proved yours with a DNS record. Seal pages show it beside your name, "Acme Notes (acme.com, Verified)", and say "Unverified" without it. See [Verify your domain](/reference/api/platform#verify-your-domain). | | Agent tools | Tools of your own that agents get beside Undertext's, set from your server. See [Add your own agent tools](/guides/your-own-agent-tools). | | Webhook endpoints | Where Undertext sends events. You can also manage these [through the API](/reference/api/webhook-endpoints). | | Keys | Your secret keys. | Everything but the slug and keys can be set from your server too, with [`PATCH /v1/platform`](/reference/api/platform) and `PUT /v1/platform/tools`. You can delete a platform in the console. Everything on it goes with it, its seals too. Embed origins are enforced by the browser, not by a check you can forget. Undertext sends a `frame-ancestors` policy listing only your origins, and the editor framed there opens only your platform's documents, so another site can't put your users' editor in its page, even with a valid session token. ## Secret keys Your server calls the API with a secret key in the `Authorization` header: ```bash curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R \ -H "Authorization: Bearer sk_51Hx…" ``` A secret key can do anything on your platform, including start an editor session as any of your users. Keep it on your server. The browser never needs it: it gets a short-lived [session token](/reference/api/sessions) for one document instead. Every key has a public id, such as `key_3Fq9`, shown beside it in the console. Undertext records which key started each writing session, and a seal lists the key ids behind it in `attested_by`. If a key ever leaks, that record tells you and anyone checking a seal which sessions it could have touched. The [trust model](/concepts/trust-model) explains why this matters. ## A platform to try things on Make one platform for development and CI, such as **Acme Notes (dev)**, and another for your real users. Nothing moves between them: a document made on one can't be opened with the other's key, and the same `external_id` on each is two separate users, with different Undertext ids. See [Go live](/guides/go-live). ## Replacing a key Replace a key in the console when someone who held it leaves, or on a schedule: create a new key, deploy it, and once the console shows the old key is no longer used, revoke it. When you revoke a key because it leaked, every request with it stops at once. Seals record the ids of the keys that started their writing sessions, so you can find every seal it had a hand in. ## Related - [Go live](/guides/go-live) - [REST API overview](/reference/api/overview): authentication, errors, limits and versions - [Trust model](/concepts/trust-model) # Presence and check-ins > How Undertext measures when someone was active in the editor while a document was written, and how security-key check-ins verify it. [Provenance](/concepts/provenance) says where words came from. **Presence** says how much of the writing happened with someone active in the editor. A seal carries both: the outer ring is provenance, the inner ring is presence. ## Presence signals While a person has a document open and the page is visible, the editor reports every half minute whether they typed or pointed in it since the last report. These come from events the browser itself sent, not from anything your page can trigger: the editor runs on Undertext's own origin, and your page can't script it. Undertext keeps one record a minute for each person. Nothing here records what people type outside the editor, their screen, or their camera. Presence is about attention to this document, nothing more. ## Sittings and the session A **sitting** is a stretch of work on a document with no gap longer than 30 minutes. A document's **session** is all the minutes in which anyone edited it, or someone writing in it was present. The seal line reports sittings and the session's time, the gaps within a sitting left out: `9 sessions, 11hr2min`. ## The Presence share **Presence** is the share of the session with a person present: editing, and moving in the editor or keeping it open after moving, within five minutes of their own edits, before or after, which covers reading back and thinking. Minutes when only an agent was working, or when nobody was looking, aren't present. Reading or moving in the editor longer away from their writing counts neither way, nor does a sitting someone only read in: reading alone isn't writing, and it doesn't count against anyone. ## Check-ins Presence signals show that someone was at the editor. **Check-ins** show it was someone with a particular security key, and they are the one signal neither a script nor a platform can produce. Each person turns **Verified Presence** on in the documents that need it, from the editor: it's their own switch, a document at a time, and it's off until they turn it on. Your platform can instead require it of everyone writing in your documents; then it's on, with no switch to turn it off. Turning it on needs a security key. People add keys in presence settings, which run on Undertext's own domain (`embed.undertext.sh`) so that keys are registered to Undertext, not to any one platform. You frame them in your settings with `mountPresenceSettings()`, or open them in a window with `openPresenceSettings()`; see [Set up check-ins](/guides/set-up-check-ins). How asks work: - Asks come only while they write in a document where Verified Presence is on: one they turned it on in, or any, if your platform requires it. Elsewhere nothing is asked. - Asks come about every 5 minutes, unless your platform chose 1, 10 or 30, the same for everyone on it. The first comes with their first edit after half an hour away from writing anywhere on your platform; each next one at a random time between half and one and a half intervals later (2½ to 7½ minutes, every 5), so it can't be told ahead of. A seal's breakdown says how often its check-ins came. - Only editing asks. Reading, pointing and clicking ask nothing; accepting or rejecting a suggestion is an edit, so it can. - A card beside the seal asks for a tap. It's answered within a minute or recorded as missed. Nothing stops them writing either way. A check-in still waiting shows in whichever document they write in next, even one where Verified Presence is off, since answering it keeps the miss from counting. - A check-in is about the person at that moment, wherever it was asked. One tap vouches for their writing in every document they work in then, and a miss counts against what they go on writing anywhere. Your page can turn Verified Presence on from a control of your own with `editor.setVerifiedPresence()`, and your server with `PUT /v1/documents/{document_id}/checkins/{user_id}`; either needs the person to have a key, which `GET /v1/users/{user_id}/checkins` tells you. To require it, or choose how often check-ins come, set [`checkins_required` and `checkin_minutes`](/reference/api/platform#update-the-platform) on your platform, in the console or the API. Where it's required, someone without a key is asked all the same, and the editor offers to add one; until they do, their check-ins go unanswered. Adding keys always happens in Undertext's presence settings. ## Key tiers When someone adds a key, Undertext sorts it into a tier and keeps the tier with each check-in it answers: | Tier | Keys | | --- | --- | | Attested | Hardware that proves its model is on the FIDO Metadata Service's list: security keys such as a YubiKey, Windows Hello on a TPM. | | Claimed | Built-in authenticators that send no proof of their model, such as Touch ID through iCloud Keychain or Google Password Manager. | | Refused | Third-party password managers and unknown software. These can't be added. | The tier is kept as data. Today it doesn't change the seal; a later method could read it. A tap shows that someone with the key was there when asked. It doesn't show they wrote every word, and it doesn't identify them beyond the key: your platform still vouches for who the person is. ## Verified Presence Check-ins turn presence into **Verified Presence**, one sitting at a time. A person's sitting is verified when: - every minute they edited in it came soon enough after a check-in they passed (within one and a half intervals and the minute to answer: about nine minutes at every 5), and - no check-in they left unanswered was followed by more of their edits. Then all their presence in that sitting is verified: their writing, and the reading around it that Presence counts. So: - a miss costs only the sittings they went on writing in soon after it; - someone who passes every check-in has all their presence verified; - turning Verified Presence off in a document stops the asks there, so writing there afterwards is verified only if taps they make elsewhere at the time vouch for it; - someone who never checks in simply goes unverified. Nothing counts against them. When every sitting anyone wrote in was verified, the seal shows a shield, Presence reads **Verified Presence**, and the seal line ends `(verified)`. When some was, it ends with the share, such as `(98% verified)`. ## Real browsers Each editor connection is also asked, invisibly, to prove it's a real browser rather than a script, when it first writes and every five minutes after. Undertext keeps the answers as data with the record. They aren't shown on the seal. ## Related - [Set up check-ins](/guides/set-up-check-ins) - [Seals](/concepts/seals) - [Trust model](/concepts/trust-model) # Provenance > How Undertext knows where every word in a document came from, and what the four origins mean. **Provenance** is where a document's words came from. Undertext records it as the writing happens, not by reading the finished text, so it doesn't guess: every character that survives in the document carries who wrote it and how it got there. ## Who wrote each character Every change in the editor arrives at Undertext from a known writer: a person in a session you started, or an agent with a token Undertext issued. Undertext writes the credit itself. A browser can't claim another person's or an agent's words, and edits sent under someone else's identity are refused. That credit follows the text. When someone deletes a sentence, it leaves the count; when someone else rewrites it, the new words are theirs. ## Four origins Each surviving word falls into exactly one of four origins. Together they make up 100% of the document. | Origin | What counts | | --- | --- | | **Typed** | Words people wrote themselves in the editor. | | **Shaped** | Text an agent wrote, in sentences a person has since changed. A person's change to the words of a sentence makes the agent's words around it shaped, for as long as the change lasts. | | **AI** | Text an agent wrote that people kept as written. An agent's suggestion accepted without changes is AI. | | **External** | Text pasted in, imported from a file, or inserted with no key pressed for it, as tools that drive a browser do. Its origin is unknown, so it counts toward neither people nor agents. | Seals show Typed and Shaped together as **Typed & Shaped**, the share people wrote or reworked. The breakdown behind a seal keeps them apart. Moving agent text, formatting it, or accepting it as a suggestion doesn't shape it. Only changing its words does. ### Suggestions A suggestion's words are its author's from the moment it's proposed. When an editor accepts a person's suggestion, those words count as that person's typing; when they accept an agent's suggestion unchanged, they count as AI. A rejected suggestion leaves nothing behind. ## Moving words keeps their credit Rearranging text doesn't change who wrote it. These all keep each word's original writer and origin: - indenting a list item, changing a block's type, splitting or joining paragraphs, dragging text; - undo, which puts back what was there; - cutting text and pasting it back, or an agent deleting a block and inserting it again; - copying several whole words from elsewhere in the same document: a copied agent paragraph is still AI, a copied pasted quote still external. Moved words count as neither written nor deleted in the activity below. ## Activity Surviving text can't show everything, so Undertext also records what happened along the way: - **Revisions:** who deleted whose text. - **Rounds:** each back-and-forth between agents and people. The seal line counts these as prompts. - **Minutes:** when people were writing or reading, which [presence](/concepts/presence-and-check-ins) is built from. - **Traces:** every read and edit an agent made. ## What provenance can't tell Provenance records how text arrived in the editor. It can't know what was in someone's head or on another screen: a person retyping an AI answer by hand is typing. That's why a seal carries [presence and check-ins](/concepts/presence-and-check-ins) beside the four origins, and why it has no single score. Readers see each part and judge for themselves. ## Reading it through the API `GET /v1/documents/{id}/provenance` returns the live reading under the current method: ```json { "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 } ``` `by_actor` splits the composition person by person and agent by agent. A [seal](/concepts/seals) freezes the document's numbers, rounded, at the moment of sealing. ## Related - [Seals](/concepts/seals) - [Presence and check-ins](/concepts/presence-and-check-ins) - [Documents reference](/reference/api/documents) # Seals > A seal freezes a document and its record at a short link anyone can open and check. A **seal** is a snapshot of a document as it stands, with everything Undertext recorded about how it was written, at a short link such as `https://acme.com/seals/66G4LF343`, on your site, or `https://seal.undertext.sh/66G4LF343`. Your users copy the text wherever it's going and send the link with it. Anyone can open the link and see where the words came from, without an account on your platform or ours, unless the document's owners made its seals [private](#who-reads-it). ## What sealing captures - **The text**, read-only, with its images, as it stood at that moment. A document with pending suggestions can't be sealed until they're accepted or rejected. - **The numbers**: the four [origins](/concepts/provenance) as shares of the text, [Presence](/concepts/presence-and-check-ins) and how much of it was verified, prompts, sittings and time, frozen under the method of the day. - **The record behind them**: who did what, agent reads and edits, the sittings on a timeline, and which signals were on. - **The names** people had when it was sealed, the name of whoever sealed it among them. Later name changes don't reach it. - **Who vouches for identity**: your platform's name and the ids of the keys that started the writing sessions. A seal is the document's proof to others, so its owners make it: from the editor's Seal button, or your server seals it for one of them, with `POST /v1/documents/{id}/seals`. Undertext sends a `seal.created` event either way. Everyone who can open the document sees its seals in the seal dialog, with their links. ## Versions Sealing never stops the writing. People keep editing after they seal, and sealing again makes a new seal with its own code and the next version number. Each seal's link always shows the version it was made from. When a newer seal of the same document exists, the page says so and links to it. A seal can't be changed. If the text needs fixing, edit and seal again. ## The seal line Every seal has one line of text that sums it up, made for pasting under the work it travels with: ```text seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified) ``` | Part | Meaning | | --- | --- | | `96% typed/shaped` | Typed and Shaped together: what people wrote or reworked. | | `2% AI` | Agent text kept as written. | | `2% external` | Pasted or imported text of unknown origin. | | `101 prompts` | Rounds of back-and-forth between people and agents. | | `9 sessions, 11hr2min` | Sittings, and the time spent in them. | When check-ins verified every sitting people wrote in, the line ends `(verified)`; when they verified some, it ends with the share, such as `(98% verified)`. There is no overall score: readers see each part. The seal object returns the line ready to use, in `line`. The editor's exports can end with it, its address linking to the seal, while the document still reads as its newest seal does: see [`editor.export`](/reference/embed#methods). ## The method The rules that turn a record into numbers are versioned, and each seal keeps the version it was made under, such as `v0.2`. When the method improves, sealed numbers don't change. The seal page shows a reading under the newer method beside the original, labelled as such, and `GET /v1/documents/{id}/provenance` always returns the reading under the current method. ## The seal page A seal's page is drawn by Undertext, so that what it shows can't be edited by anyone who wrote the document or by the platform it was written in. It shows: - the text and the seal, with its breakdown one click away; - who sealed it, and when; - "Written in Acme Notes", with your platform's name from the console; - that Acme Notes vouches for who the writers are, and which keys started their sessions. It's at your own address once you set a [`seal_url`](/reference/api/platform), such as `https://acme.com/seals/{code}`, and show the seal there with [`mountSeal`](/reference/embed#mountseal): your page gives it your address, link preview and sign-in, and Undertext draws the seal in a frame from its own domain, as it does the editor. Seal links and seal lines then name your address. Every seal's page is also on Undertext's own domain, at `seal.undertext.sh/{code}`, where anyone can check what yours shows; without a `seal_url`, that's the seal's link. See [Show seals on your site](/guides/seal-and-verify#show-seals-on-your-site). Shared on the web, a public seal's link unfurls into a preview image with the title, who wrote it, the seal and the seal line. Your page gets these from the seal's `preview`. ## Who reads it A document's owners choose, in the editor's seal dialog, who reads its seals, every version alike: - **Anyone with the link**, the default. - **Private**: whoever can open the document, readers they name by email or as `*@domain`, and whoever has the password, if they set one. Whoever can open the document means its members and, while its link lets anyone in, anyone signed in with your platform: a seal's page can't tell who has the document's link, so the seal's link stands in for it. Readers prove who they are by signing in with your platform, which vouches for them, and for their verified email, with a [seal session](/reference/api/sessions#for-seals). A private seal has no link preview. Sharing the document and sealing it stay apart: people you share it with collaborate on it, and can always read its seals; the seal dialog decides who else may. Someone a private seal turns away, signed in with an email your platform vouched for, can ask its owners to let them read it, from the seal's page on your site. The owners see who's asking, and their message, in the seal dialog, and let them read, which adds their email to the readers, or decline. Undertext tells your server with [`seal_request` events](/reference/webhooks#seal_requestcreated), so you can tell the owners, and the person asking once they're let in. ## Withdrawing In the editor's seal dialog, its owners can withdraw any version; your server can withdraw any with `DELETE /v1/seals/{code}`. Its page then says it was withdrawn, and nothing else; the link keeps answering so that anyone who has it learns why. Deleting a document withdraws all its seals. While a document is in its owners' trash, its seals are down, and come back if it's restored. ## The seal object ```json { "code": "66G4LF343", "url": "https://seal.undertext.sh/66G4LF343", "document": "doc_8Hq2Lm4R", "version": 3, "sealed_at": "2026-10-30T16:31:00Z", "sealed_by": "usr_5Kq2Lm8R", "method": "v0.2", "line": "seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified)", "composition": { "typed": 86, "shaped": 10, "ai": 2, "external": 2 }, "presence": { "share": 99, "verified_share": 98, "verified": false }, "prompts": 101, "sittings": 9, "duration": "11hr2min", "attested_by": { "platform": "acme", "key_ids": ["key_3Fq9"] }, "withdrawn_at": null, "preview": { "title": "On the Analytical Engine", "description": "96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified). Sealed with Undertext, written in Acme Notes (acme.com, verified).", "image_url": "https://seal.undertext.sh/api/seals/66G4LF343/preview.png" } } ``` ## Related - [Seal and verify](/guides/seal-and-verify) - [Seals reference](/reference/api/seals) - [Trust model](/concepts/trust-model) # Trust model > What a seal proves, who vouches for each part of it, and what it can't tell anyone. A seal is only worth what the party who watched the writing can't fake. This page sets out who watches what when you build on Undertext, so you can say accurately what a seal means to your users and to the people who read their work. ## Two parties, two claims Every seal made on your platform rests on two claims from two parties: - **Undertext observes the writing.** Every change in the editor travels from Undertext's own code, on Undertext's own domain, to Undertext's servers. Undertext decides which words were typed, shaped, written by an agent or pasted, and when someone was active in the editor. - **You vouch for who wrote it.** Undertext has no accounts. When your server creates a user for your id `u_42`, named Ada Lovelace, and starts editor sessions for them, Undertext takes your word for it. The seal page says both. A seal made in Acme Notes names it, with its domain once Acme Notes has proved it holds acme.com, and the people on it are named as Acme Notes named them, with a note that Acme Notes vouches for who they are. ## Where a seal is shown A seal's page can be at your address, such as `acme.com/seals/66G4LF343`, and its link and seal line then name it. What it shows is still Undertext's: the text, the seal and its breakdown are drawn by Undertext's own code, in a frame from Undertext's domain, which your page can't script, as with the editor. Your page around it gives it your address, your link preview and your sign-in for private seals. A reader can't tell from your address alone whether your page shows Undertext's frame or something made to look like it. So every seal is also at `seal.undertext.sh/{code}`, Undertext's own page on Undertext's own domain, and anyone who wants to be sure opens the code there. A public seal shows the same text and numbers in both places; a private one asks for its password there, or sends the reader to sign in on your page. ## What Undertext observes directly | Signal | How Undertext knows | | --- | --- | | Typed text | Each change arrives over the editor's own connection, from keys pressed in the editor. | | Pasted and imported text | Text that arrives without keys pressed for it, from a paste, a drop, or a tool driving the browser, is counted as external. | | Agent text | Agents write only through Undertext's MCP server, under their own tokens, so their words carry their own credit. | | Shaped text | Words of an agent's sentence that a person changed afterwards, while the change lasts. | | Presence | Every half minute while a writer's editor is visible, the browser reports whether they typed or pointed there, from events the browser itself sent. | | A real browser | Each editor connection earns a Cloudflare Turnstile token when it first writes and every few minutes after. Undertext keeps whether it passed. | | Check-ins | Taps of a security key registered on Undertext's domain, answered within a minute of being asked. | Your page can't reach any of these. The editor is a cross-origin iframe: your scripts can't read it, type into it or change what it sends. Embed origins in the console decide which sites may show it at all. ## What you vouch for - **Identity.** Names, pictures and the detail line come from you. If your sign-in is weak, so is the name on a seal. - **Access.** Who may open, edit or suggest in a document is your decision, stored at Undertext through your API calls. - **Agent approvals.** A person approves an agent on your consent page, signed in to your product. Undertext records that you said this person approved it. Your secret key can start an editor session as any of your users. That is what lets you build without Undertext accounts, and it's also the main thing to protect. Each seal records which of your keys started the sessions behind it, so if a key leaks you can revoke it and find the seals whose sessions it started. ## What nobody can fake easily A check-in needs a physical tap on a security key at the moment Undertext asks. A script can't do it, and neither can your server. That makes check-ins the strongest signal on a seal: when every sitting with writing in it is covered, Presence reads Verified Presence and the seal line ends "(verified)". A tap shows that someone with that key was at the keyboard when asked. It doesn't show which person. Keys are registered in a window on Undertext's domain, opened with a session you start, so who registered a key rests on your sign-in too. ## What a seal can't tell anyone - **Where ideas came from.** Someone retyping text from another window, by hand, is typing. A seal shows how the words got into the editor, not whose thinking they were. - **What happened outside the editor.** Drafts written elsewhere and pasted in count as external, with their origin unknown. - **Who a person is beyond your word.** See above. Seals don't change after they're made. Each records the version of the method that produced its numbers; when the method improves, a seal page shows the new reading beside the old one and never rewrites it. A seal can be withdrawn, and its page then says so. ## Attacks and what stops them | Someone tries to | What stops it | What's left | | --- | --- | --- | | Inject text from your page into the editor | The iframe is cross-origin; your page can't script it | Nothing, short of compromising the browser | | Pass agent text off as typed | Agents write through MCP under their own credit; text inserted without key presses counts as external | Retyping by hand | | Type with a script driving a browser | No key presses means external; Turnstile results are kept | A script faking key events in a real browser; check-ins catch the absence of a person | | Start sessions as your users with your key | Seals record which key started each session | You remain the authority on identity | | Edit a document after sealing it | Seals are snapshots; a version can't change | Sealing again makes a new version, which is shown as new | | Rescore an old seal | Each seal keeps its method version | Newer readings appear beside, labeled | | Show something else at a seal's address on your site | The seal is drawn in Undertext's frame, and every seal is also on `seal.undertext.sh` | A reader who doesn't check the code there | ## What to tell your users Keep it to what is true for everyone: a seal shows where each word in the document came from and how much of the writing happened with someone active in the editor, as recorded by Undertext, for a person your product signed in. With check-ins on, it also shows the times someone was there to tap their security key when Undertext asked. # Users > Users are your people; Undertext gives each one its own id, keeps yours beside it, and takes your word for who they are. Undertext has no accounts, no passwords and no sign-in. A **user** is one of your people. Your server tells Undertext who they are, and Undertext records what they do in the editor. ## Two ids Every user has two ids: | Id | Example | Whose | | --- | --- | --- | | `id` | `usr_5Kq2Lm8R` | Undertext's. It never changes, and it is what documents, seals, members, sessions and webhooks use. | | `external_id` | `u_42` | Yours: whatever your product already calls this person, up to 128 characters. Unique on your platform, and you can change it. | Undertext's records refer only to its own ids, so the history of who wrote what never depends on a key you might change, and your ids, which may be emails or database keys, never end up in documents or on seals. Keep the Undertext id beside your user, the way you'd keep a Stripe customer id: an `undertext_user_id` column is enough. When you have only your own id, look the user up by it. ## Creating and updating `PUT /v1/users/external/{external_id}` creates the user the first time you send an `external_id` and updates them after that, and returns the user with its Undertext id. Call it when someone signs up, and again whenever their profile changes: ```json { "name": "Ada Lovelace", "avatar_url": "https://acme.com/avatars/42.png", "detail": "ada@acme.com" } ``` | Field | Meaning | | --- | --- | | `name` | How the person appears to others: beside their cursor, on comments, in the seal's breakdown. Up to 48 characters. | | `avatar_url` | Optional. A picture Undertext fetches once and serves itself: PNG, JPEG or WebP, at most 1 MB. | | `detail` | Optional. A second line under the name in mention lists, such as an email or a team, to tell two people with the same name apart. | A user needs a name before they can open the editor. See the [Users reference](/reference/api/users) for every field. ## Changing your ids If your ids change, for example in a migration or when someone switches login method, point the Undertext user at the new one with `PATCH /v1/users/{id}` and a new `external_id`. Nothing else moves: documents, seals and agents follow the Undertext id. ## You vouch for who people are Undertext takes your word for a user's identity. When Ada's seal says "Ada Lovelace", it means "Acme Notes says this is Ada Lovelace", and the seal page says so. Undertext can vouch for what happened in the editor; only you know who was signed in. The [trust model](/concepts/trust-model) covers what each side vouches for. ## Name changes Documents name people by their Undertext id, not by the name they had when they wrote. When you change a user's name or picture, every open editor shows the new one at once, and so do comments, the breakdown and agents' reads. Nothing in the documents is rewritten. Seals are the exception: a seal is a snapshot, so it keeps the name each person had when it was sealed. ## Deleting a user `DELETE /v1/users/{id}` removes a user from your platform. - Documents they wrote in keep their last name, without the picture, so what they wrote stays credited. - Documents they owned pass to their other members with the highest role; one with no other member, and nobody else who wrote in it, is deleted, with its seals. - Their agents are revoked at once. - Their security keys and check-in history go with them. Their `external_id` is free again afterwards. Sending it to `PUT /v1/users/external/{external_id}` creates a new person with a new Undertext id: nothing from before comes back. ## Merging users Some products let people write before they have an account, then sign up later. `POST /v1/users/{id}/merge` moves everything from one user to another: - their documents and memberships, - the credit for everything they wrote, - their security keys and check-ins, and the documents they turned Verified Presence on in, - their agents; one for a client the user they join already connected joins that agent. The first user is deleted afterwards. See [Anonymous users](/guides/anonymous-users) for the whole flow. ## Related - [Users reference](/reference/api/users) - [Documents and access](/concepts/documents-and-access) - [Anonymous users](/guides/anonymous-users) # Anonymous users > Let people write before they sign up, then carry their documents, credit, keys and agents over to their account when they do. Many apps let people start writing before they make an account, or let a visitor who opened a shared link comment without signing up. Undertext doesn't mind who your users are, only that you give each one an id of yours, so an anonymous visitor is just another user to Undertext. By the end of this guide, visitors can write straight away, and everything they did moves to their account when they sign up. ## Give visitors a user 1. **Make an id when a visitor first needs one**, such as when they start a document or open a shared link, and keep it in your own session. It becomes the user's `external_id` at Undertext. Any string up to 128 characters works; a prefix makes these easy to spot. ```ts title="session.ts" async function currentUser(req) { if (req.user) return req.user; if (!req.session.anonymousId) { req.session.anonymousId = `anon_${crypto.randomUUID()}`; req.session.anonymousName = randomName(); // "Brisk Heron" } return { id: req.session.anonymousId, name: req.session.anonymousName, anonymous: true }; } ``` 2. **Create the user in Undertext** with a name that reads well in the margin and in comments, and keep the Undertext id in the session beside your own. A made-up name is friendlier than "Anonymous", and lets people tell two visitors apart. ```ts const visitor = await currentUser(req); if (!req.session.undertextUserId) { const undertextUser = await undertext.users.upsert(visitor.id, { name: visitor.name }); req.session.undertextUserId = undertextUser.id; } ``` 3. **Use them like any other user.** Create documents they own, start editor sessions, and start link sessions for shared documents. Everything they write is credited to their made-up name. Anonymous users can do everything signed-in users can in Undertext: write, comment, add security keys, connect agents and seal. Which of those your app allows before sign-up is up to you. ## Merge when they sign up When a visitor signs up or signs in, merge their anonymous user into their account: ```ts title="sign-in.ts" app.post("/sign-in/complete", async (req, res) => { const account = await finishSignIn(req); // your own sign-in if (req.session.undertextUserId) { // undertextUserId: the helper from Embed the editor, which creates the account's Undertext user if needed. await undertext.users.merge(req.session.undertextUserId, { into: await undertextUserId(account) }); delete req.session.anonymousId; delete req.session.undertextUserId; } res.redirect("/notes"); }); ``` Merging moves, from the anonymous user to the account: - **Documents and memberships.** Where both were members of the same document, the account keeps the higher role. - **Credit.** Everything the visitor wrote, commented and suggested now shows under the account's name, in open editors too. - **Security keys** and their check-ins, and the documents the visitor turned Verified Presence on in. - **Agents**, still reaching the same documents. One for a client the account already connected joins that agent. The anonymous user is then gone: its Undertext id answers `404`, and its `external_id` is free. Existing seals keep the name they were sealed with, as seals always do. Merge before you start the next editor session. An editor still open as the anonymous user loses its session when the merge completes and asks your page for a new token; once your session route starts sessions as the account, it picks up where it left off. ## Clean up visitors who never come back Anonymous users stay until you delete them, by the Undertext id you kept for each: ```ts await undertext.users.delete("usr_2Hd7Np4Q"); ``` Deleting a user deletes documents nobody else is a member of or wrote in, with their seals. In documents shared with others, what the visitor wrote keeps the name they last had, without a picture. ## Next - [Users](/concepts/users): how Undertext names people. - [Users](/reference/api/users) in the API reference, including `merge`. # Connect agents > Let your users connect Claude, Codex or any MCP client to their documents, with your sign-in on the consent page and Undertext crediting every word the agent writes. Your users can bring their own AI agents to the documents they keep in your app. An agent reads, suggests, edits and comments through Undertext's MCP server, and everything it writes is credited to it on the record and in the seal. You build two things: a page that tells people how to connect an agent, and a consent page where they approve one. Undertext does the rest. It runs the MCP server and the OAuth sign-in, issues the agent's tokens, and checks what the agent may do on every call. Your server never holds an agent's token, which is why an agent's words can't be passed off as a person's, or a person's as an agent's. ## How connecting works Each platform has its own MCP address. For Acme Notes it is: ``` https://mcp.undertext.sh/acme ``` Your server can read it as `mcp_url` from [`GET /v1/platform`](/reference/api/platform). When someone adds that address to their agent: 1. The agent calls Undertext, learns it needs to sign in, and registers itself with Undertext's OAuth server. Undertext checks where the agent comes from: its **host**, such as `claude.ai`, which the agent can't claim falsely. 2. The agent opens the person's browser at Undertext, which sends it straight on to your **consent URL** with a request id: `https://acme.com/undertext/connect?request=areq_5tNc81`. 3. Your consent page signs the person in, as any page of your app would, and shows which agent is asking. 4. When they click **Allow**, your server approves the request with your secret key, naming the signed-in user. Undertext answers with a URL, and you send the browser there. 5. Undertext finishes the sign-in and gives the agent its tokens. From then on the agent talks only to Undertext, as your user's agent. Tokens for one platform's address don't work on another's. Someone who uses two platforms built on Undertext connects their agent to each separately, and the agent keeps the two apart. ## Set your consent URL In the console, or with [`PATCH /v1/platform`](/reference/api/platform), enter the URL of your consent page, such as `https://acme.com/undertext/connect`. Until you set one, Undertext answers every connection attempt with an error telling the person that this platform doesn't accept agents yet. ## Show people how to connect Give your settings an Agents section that shows your MCP address and how to add it to the agents people use most. The address is the same for all your users; who they are is settled on the consent page. ```bash claude mcp add --transport http acme https://mcp.undertext.sh/acme ``` Then run `/mcp` inside Claude Code and choose **acme** to sign in. ```bash codex mcp add acme --url https://mcp.undertext.sh/acme codex mcp login acme ``` ```bash code --add-mcp '{"name":"acme","type":"http","url":"https://mcp.undertext.sh/acme"}' ``` VS Code asks to sign in the first time the agent uses the server. A `vscode:mcp/install?…` link with the same JSON does this in one click from your settings page. On gemini.google.com, open **Customize → Connectors** and choose **Custom**. Paste `https://mcp.undertext.sh/acme`, choose **Next**, accept the risks, choose **Connect**, and link the Google account. Custom apps need a personal Google account in the US and are added on the web; they then show in Gemini's mobile apps too. ```bash agy mcp add --type http acme https://mcp.undertext.sh/acme ``` Then run `/mcp auth acme` inside Gemini CLI to sign in. Any client that speaks MCP over Streamable HTTP with OAuth works. Add a server with the URL `https://mcp.undertext.sh/acme`; the client finds the sign-in on its own. In every case, signing in opens the person's browser on your consent page. Name the server after your product (`acme` above). Agents show tools grouped by server, so your users see `acme` rather than a name they don't recognise. ## Build the consent page The consent page is a normal page in your app, behind your normal sign-in. 1. **Look up the request.** Undertext tells you which agent is asking. `client.host` is verified; `client.name` is what the agent calls itself. Asked for the signed-in user, it also tells you whether they've connected this client before, as `agent`, with the name they gave it. ```ts title="connect.ts" app.get("/undertext/connect", requireSignIn, async (req, res) => { const request = await undertext.agentRequests.retrieve(String(req.query.request), { user: req.user.undertextUserId }); const documents = await undertext.users.listDocuments(req.user.undertextUserId); res.render("connect-agent", { requestId: request.id, agentName: request.client.name, // "Claude Code" agentHost: request.client.host, // "claude.ai" name: request.agent?.name ?? request.client.name, // what they'll call it documents: documents.data, }); }); ``` If the person isn't signed in, `requireSignIn` should send them through your sign-in and back to this URL, query string included. Requests last 10 minutes; an expired one returns `409 request_expired`, and the person starts again from their agent. 2. **Ask the person.** Show the agent's name and host together, such as "Claude Code (claude.ai) wants to work in your Acme Notes documents". Let them name it, as they'd tell apart two Claude Codes, and choose what it reaches: - **All documents**: every document they can open, editing at most. This is what most people want. - **Chosen documents**: only the ones they pick, each as an editor, suggester or viewer. Keep it to one screen with **Allow** and **Deny**. This is the one moment every connection passes through, however the person set the agent up, so it's the place to name it. 3. **Approve or deny on your server.** Always name the signed-in user from your session, never from the form. ```ts title="connect.ts" app.post("/undertext/connect", requireSignIn, verifyCsrf, async (req, res) => { const { requestId, decision, name, access, documents } = req.body; if (decision !== "allow") { const { redirect_url } = await undertext.agentRequests.deny(requestId); return res.redirect(303, redirect_url); } const { redirect_url } = await undertext.agentRequests.approve(requestId, { user: req.user.undertextUserId, name, // "Research" access, // "all" or "chosen" documents, // with "chosen": { "doc_8Hq2Lm4R": "suggester", ... } }); res.redirect(303, redirect_url); }); ``` 4. **Send the browser on.** The `redirect_url` returns the person to Undertext, which finishes the sign-in and hands them back to their agent. The page they land on tells them they can close it. Approve only from a `POST` your own page sent, with your usual cross-site request protection. A request id alone proves nothing about who is approving it: someone could send another person a link to your consent page with their own request id. Showing the verified host, and asking before approving, is what protects your users. ## Let people manage their agents List a person's agents in the same Agents section, with what each is called, what each reaches, and a way to remove it. ```ts const agents = await undertext.users.listAgents("usr_5Kq2Lm8R"); // [{ id: "agt_Qe71", name: "Claude Code", client_name: "Claude Code", host: "claude.ai", access: "all", // connected_at: "2026-10-29T16:02:11Z", last_used_at: "2026-10-30T09:14:52Z" }] ``` Show where each comes from beside its name: its host, as two agents can share a name but not a host, or for a `local` one, a command-line tool or desktop app, that it's on their computer, as its local address says nothing. **Name an agent.** It's called what its client calls itself until its person names it, as they'd tell apart two Claude Codes. The name shows wherever the agent works, at once. ```ts await undertext.agents.update("agt_Qe71", { name: "Research" }); ``` **Remove an agent.** Its tokens stop working at once, mid-task too. ```ts await undertext.agents.revoke("agt_Qe71"); ``` **Narrow what it reaches.** Switch it to chosen documents, then give it a role in each: ```ts await undertext.agents.update("agt_Qe71", { access: "chosen" }); await undertext.agents.putDocument("agt_Qe71", "doc_8Hq2Lm4R", { role: "suggester" }); await undertext.agents.deleteDocument("agt_Qe71", "doc_3pXw9KdA"); ``` A good place for per-document choices is your Share dialog: a row for each of the person's agents, with the same roles you offer people. Whatever you set, the agent never gets more than its person's own role in that document. See [Share documents](/guides/share-documents#what-agents-get). ## Hear about agents Two webhook events keep your Agents section current without polling: - `agent.connected` when someone approves an agent they hadn't connected before. - `agent.revoked` when an agent is removed, by your call or because its user was deleted. See [Send notifications](/guides/notifications) for receiving events, and the [event reference](/reference/webhooks) for their fields. ## What agents see Agents get Undertext's document tools: listing, searching, reading, writing in Markdown, suggesting, and commenting. They're told to suggest unless their person asked them to edit directly. An assistant your product runs is an agent like any other, approved by each person on your consent page, and is told the same. So when its person asks it for text, such as a first draft, have it write with `suggest: false` and their request as `instruction`: where it may edit, that writes directly. Each edit is credited with the agent's name and its person's, such as "Claude Code (Ada Lovelace's agent)", in the margin, in the record and in the seal. Folders, tags and anything else your app keeps itself aren't in Undertext's tools. To give agents those, register tools of your own, which Undertext's server lists beside its own and forwards to you; see [Add your own agent tools](/guides/your-own-agent-tools). ## Next - [MCP tools](/reference/mcp): every tool and what it may do. - [Agents](/concepts/agents): how agents are credited and limited. - [Agent requests](/reference/api/agent-requests) and [Agents](/reference/api/agents) in the API reference. # Embed the editor > Put the Undertext editor in your page, signed in as your user, sized and styled to fit, and wired to your app. By the end of this guide, a document opens inside your own page. Your users sign in to your app, not to Undertext. The editor runs in an iframe served from `embed.undertext.sh`, and talks to Undertext directly over its own socket. Your page tells it which document to open and how it should look, and it tells your page when something happens that your app should know about. You need a secret key (`sk_…`) from the [console](https://undertext.sh/console), and a document to open. The [quickstart](/quickstart) creates one. ## How the pieces fit Your server is the only thing that holds your secret key. When your page wants to show a document, it asks your server for a session token: a short-lived token for one user and one document. The page hands that token to the editor, and the editor uses it to connect to Undertext. When the token is about to lapse, the editor asks your page for a new one, and your page asks your server again. Because the editor is in its own origin, nothing on your page can reach into it. That is what lets Undertext tell typed words from pasted ones, and people from scripts. See the [trust model](/concepts/trust-model) for why that matters. ## Embed a document 1. **Allow your origins.** In the console, under **Embed origins**, or with [`PATCH /v1/platform`](/reference/api/platform), add each origin your app runs on, such as `https://acme.com`. The editor only loads inside pages on these origins; anywhere else the browser refuses the frame. For development, add your local origin, such as `http://localhost:5173`: plain `http` is allowed only for `localhost` and `127.0.0.1`. 2. **Add a session route to your server.** Check your own sign-in first: this route is where your app vouches for who the user is. Then start a session for the user's Undertext id, creating the Undertext user the first time. ```ts title="server.ts" import express from "express"; import Undertext from "@undertext/sdk"; const app = express(); const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY); // Your user's Undertext id, created at Undertext and stored on your user the first time. async function undertextUserId(user) { if (user.undertextUserId) return user.undertextUserId; const undertextUser = await undertext.users.upsert(user.id, { name: user.name, avatar_url: user.avatarUrl }); await db.users.update(user.id, { undertextUserId: undertextUser.id }); return undertextUser.id; } app.post("/undertext/session", requireSignIn, async (req, res) => { const documentId = String(req.query.doc); try { const session = await undertext.sessions.create({ user: await undertextUserId(req.user), document: documentId }); res.json({ token: session.token, role: session.role }); } catch (error) { if (error.code === "no_access") return res.status(403).json({ error: "no_access" }); throw error; } }); ``` Pass `group` with the id of the person's own sign-in session with you, and when they sign out, end every Undertext session it started with [`undertext.users.endSessions`](/reference/api/sessions#end-a-users-sessions): their open editors stop at once. The session's `role` is the user's role in the document: `owner`, `editor`, `suggester` or `viewer`. Undertext refuses the session with `no_access` when the user isn't a member and the document's link access doesn't let them in. When someone changes their name or picture in your product, call `undertext.users.upsert` again with your id, and every open editor shows the change. See [Sessions](/reference/api/sessions) for every field, and [Users](/concepts/users) for how your ids and Undertext's fit together. 3. **Mount the editor in your page.** Give it an element, the document id, and a `getToken` function that calls your route. ```ts title="editor-page.ts" import { mountEditor } from "@undertext/embed"; const documentId = "doc_8Hq2Lm4R"; const editor = mountEditor(document.querySelector("#editor"), { document: documentId, getToken: async () => { const response = await fetch(`/undertext/session?doc=${documentId}`, { method: "POST" }); if (!response.ok) throw new Error("No access to this document"); return (await response.json()).token; }, }); ``` The editor calls `getToken` once when it mounts and again two minutes before each token lapses (tokens last 15 minutes). Don't cache tokens yourself. If you don't use a bundler, load the script instead. It puts the same functions on `window.Undertext`: ```html
``` 4. **Remove it when you leave the page.** In a single-page app, call `editor.destroy()` when the route changes, so the socket closes and the last edits are saved first. ## Size it The editor sizes itself in one of two ways: - `height: "auto"` (the default) grows the iframe with the text, so your page scrolls as it would for any long article. Use this when the document is the page. - `height: "fill"` makes the editor fill its container and scroll inside it. Use this when the document sits in a fixed panel, such as beside a sidebar. Give the container a height. ```ts mountEditor(panel, { document: documentId, getToken, height: "fill" }); ``` Where the frame is too narrow, comment and suggestion cards move into a panel whatever you choose for `comments`. Beside a list of documents, mount the editor once and open each document in it with `editor.open(documentId)`: the next one loads while the one before stays in view, without loading the editor again. `getToken` is then asked for the document it names. See [Opening another document](/reference/embed#opening-another-document). ## Make it look like your app Appearance is set with options, not CSS: your stylesheets can't reach inside the iframe. ```ts mountEditor(element, { document: documentId, getToken, colorScheme: "auto", // "light", "dark", or follow the system toolbar: "floating", // "header", "floating" or "none" comments: "right", // "right", "left" or "hidden" highlight: true, // tint text by who wrote it, with the attribution rail beside each line }); ``` The seal's own colours never change: they mean the same thing on every platform. Keyboard shortcuts such as ⌘K (the editor's command palette) and ⌘P (print) belong to the editor while it has focus, and to your page otherwise. To change something after mounting, such as the colour scheme when your user flips your own theme switch, call `editor.setOptions({ colorScheme: "dark" })`. When the person changes a display setting inside the editor, it sends a `settings` event with the new options: keep them with your other preferences and pass them back next time. Put your own buttons in the editor's header, such as a menu or a notification bell, with `headerItems`: a click sends a `command` event with where the button is, for your page to open its menu or panel under it. Add your own commands to the editor's ⌘K palette with `commands`. See [Options](/reference/embed#options). ## Choose a mode People with the `editor` or `owner` role write directly by default. Pass `mode: "suggest"` to start them in suggestion mode instead, or switch later: ```ts editor.setMode("suggest"); ``` People with the `suggester` role always suggest, and viewers only read and comment where their role allows. The mode never grants more than the role. ## Wire it to your app The editor tells your page about the things your app owns. Listen with `editor.on`: ```ts editor.on("title", ({ title }) => { // The document's name, or its first line when it has none. documentList.rename(documentId, title); document.title = `${title} · Acme Notes`; }); editor.on("open-document", ({ document: id }) => { // Someone followed a link to another of your documents. Open it your way. router.push(`/notes/${id}`); }); editor.on("mention", ({ user }) => { // A name was clicked in the text, a comment or the margin. router.push(`/people/${user}`); }); editor.on("save-state", ({ state, unsaved }) => { savingIndicator.show(state); // "saving", "saved" or "offline" window.onbeforeunload = unsaved ? () => true : null; }); editor.on("seal", ({ code, url, line }) => { // The owner sealed the document from the editor's Seal button. toast(`Sealed: ${url}`); }); editor.on("error", ({ code, message }) => { // For example "no_access" after the user was removed from the document. if (code === "no_access") router.push("/notes"); }); ``` You can also drive the editor from your own buttons: ```ts editor.focus(); editor.print(); // the editor's own print layout, typeset for PDF const markdown = await editor.export("markdown"); // or "html", "docx" const sealed = await editor.export("docx", { sealLine: true }); // ending with its seal line, while its newest seal still reads as it does editor.openBreakdown(); // the seal's breakdown: where the words came from, sittings, check-ins editor.openSeal(); // the seal dialog ``` Every option, event and method is in the [embed API reference](/reference/embed). ## What the editor doesn't do The iframe is what makes the record trustworthy, so some things stay inside it: - **No custom content.** You can't add your own block types, or put your own components inside the text. Links, images, tables, checklists and code are built in. - **No styling beyond the options.** Your CSS doesn't reach in, and the editor doesn't read your fonts. - **No reaching into the page.** Your scripts can't read the editor's DOM or send it keystrokes. Text your page puts in by other means, such as through the clipboard, counts as pasted. - **No cookies.** Browsers wall off storage inside third-party frames, so everything rides on the session token. A user who is signed in to your app is signed in to the editor; nothing else is needed. - **No document list.** The editor shows one document. Lists, folders and search across documents are yours to build, with [`GET /v1/users/{user_id}/documents`](/reference/api/users). ## Next - [Share documents](/guides/share-documents) with members and links. - [Connect agents](/guides/connect-agents) so your users can bring Claude or Codex. - [Seal and verify](/guides/seal-and-verify) when a document is done. # Go live > Build on a platform of your own, then make the one your users get, with a checklist covering origins, agents, webhooks, replacing keys and rate limits. Make one platform to build and try things on, such as **Acme Notes (dev)**, and another for your real users. Each has its own keys, settings and MCP address, and they never see each other's data: users, documents, agents, seals and webhook endpoints on one don't exist on the other. Everything works the same on both, from the editor to agents and seals. ## Your development platform - **List where the editor loads**, such as `http://localhost:5173`, under **Embed origins**. Plain `http` is allowed only for `localhost` and `127.0.0.1`. - **Agents connect to its own address**, such as `https://mcp.undertext.sh/acme-dev`, which uses its consent URL. That URL may be on `localhost`, since the person's own browser opens it. - **Webhook endpoints must be `https`**, so point one at a tunnel to your machine, such as `cloudflared tunnel --url http://localhost:3000`. ## Before you go live Make your platform for real users in the [console](https://undertext.sh/console), then work through these with its key, in a staging copy of your app if you have one. ### Keep the secret key on your server Load your `sk_…` key from your secret store or an environment variable, on the server only. It never belongs in the browser, in a mobile app, or in your repository. The browser only ever needs session tokens, which your server starts for one user and one document at a time. Anyone holding your secret key can start a session as any of your users. That's why seals name your platform as the one vouching for who wrote, and record which key was used. ### Set your embed origins List every origin your app serves the editor from, such as `https://acme.com`, under **Embed origins**. Leave out anything you don't control. The editor won't load anywhere else, which stops other sites from framing your users' documents. ### Set your consent URL Set its consent URL in the console, or with [`PATCH /v1/platform`](/reference/api/platform), and connect a real agent to its address, `https://mcp.undertext.sh/acme`, from start to finish. See [Connect agents](/guides/connect-agents). ### Add your webhook endpoint Add its endpoint and store its `whsec_…` secret apart from your development platform's. Check your server answers `2xx` to a real event, such as a comment in a document. See [Send notifications](/guides/notifications). ### Check your name, and verify your domain Seal pages name your platform as where the text was written, which vouches for who wrote it. Make sure the platform's name in the console is the one your users know, and add your domain there: once its DNS record is found, seal pages read "Acme Notes (acme.com, Verified)" rather than "Acme Notes (Unverified)". Anyone can call a platform anything; only you can add a record to your domain. ### Replace keys To replace a key without downtime: 1. In the console, create a new key. 2. Deploy it. 3. Once the console shows the old key's last use was before your deploy, revoke it. If a key may have leaked, revoke it right away. Every request with it stops at once. Seals record the ids of the keys that started their writing sessions (`attested_by.key_ids`), so you can find every seal a leaked key had a hand in. ### Stay within rate limits The API doesn't limit requests yet. Even so, start one session per page load rather than one per action, and call `users.upsert` only when starting sessions or when a profile changes. When limits come, a request over them will get `429` with a `Retry-After` header, which the Node SDK already waits for and retries. In the editor, people's edits always go first, and each agent request gets a short slice of work at a time per document, so one busy agent never slows anyone's typing. ### Handle errors Every error has a `type` and a `code`, so your code can branch on them: ```ts try { await undertext.sessions.create({ user: "usr_9Tb3Wc1X", document: "doc_8Hq2Lm4R" }); } catch (error) { if (error.type === "permission" && error.code === "no_access") showNoAccess(); else throw error; } ``` The [API overview](/reference/api/overview) lists every type. ## Next - [Platforms and keys](/concepts/platforms-and-keys): settings and keys in detail. - [Trust model](/concepts/trust-model): what your key vouches for. # Send notifications > Receive Undertext's webhooks, check their signatures, and turn comments, mentions and seals into your own notifications and emails. Undertext doesn't send email or keep a notification list: people are yours, so telling them things is too. Instead, Undertext sends your server a webhook whenever something happens that someone might want to hear about, such as a comment, a reply, a mention or a seal. By the end of this guide, your server receives those events safely and turns them into your own bell and emails. ## Set up an endpoint 1. **Add the endpoint.** In the console under **Webhooks**, or from code: ```ts const endpoint = await undertext.webhookEndpoints.create({ url: "https://acme.com/undertext/webhooks", events: ["thread.created", "thread.replied", "thread.resolved", "thread.message_edited", "thread.message_deleted", "seal.created"], }); // endpoint.secret is "whsec_…": store it with your other secrets. It's shown only once. ``` Use `["*"]` to receive every event, including ones added later. 2. **Receive events with the raw body.** The signature covers the exact bytes Undertext sent, so read the body before any JSON parser touches it. ```ts title="webhooks.ts" import express from "express"; app.post("/undertext/webhooks", express.raw({ type: "application/json" }), async (req, res) => { let event; try { event = undertext.webhooks.verify(req.body, req.get("Undertext-Signature"), process.env.UNDERTEXT_WEBHOOK_SECRET); } catch { return res.sendStatus(400); } await queue.add("undertext-event", event); // do the work elsewhere res.sendStatus(200); }); ``` `verify` checks the HMAC and that the timestamp is within five minutes, then returns the parsed event. If you can't use the SDK, the [event reference](/reference/webhooks) shows how to check the `Undertext-Signature` header yourself. 3. **Answer quickly.** Respond with any `2xx` within 10 seconds, and do the real work afterwards. Anything else, or no answer, counts as a failure: Undertext tries again with growing gaps for three days. ## Handle each event once Undertext may send an event more than once, and doesn't promise any order. Two habits cover both: - **Keep the ids you've handled.** Every event has an `id` such as `evt_1Nf3Qa8Z`. Skip any you've seen. - **Don't trust order.** If you keep state from events, such as whether a thread is resolved, compare `created_at` before overwriting, or read the current state from the API. ```ts title="worker.ts" worker.process("undertext-event", async (event) => { const fresh = await db.handledEvents.insertIfMissing(event.id); if (!fresh) return; await handle(event); }); ``` ## Turn events into notifications Every event names who did it in `actor`: a person (`{ type: "person", user }`) or an agent acting for one (`{ type: "agent", agent, user }`). Don't notify people about what they or their own agents did. Thread events say whom they concern, so you needn't ask the API: the document's `owners`, the thread's earlier `participants`, the `suggestion_author` of a thread on a suggestion, and the people the message `mentions`. Here is how Undertext's own app fills its bell from them: ```ts title="notify.ts" async function handle(event) { const { data } = event; switch (event.type) { case "thread.created": case "thread.replied": { const message = event.type === "thread.created" ? data.thread.messages[0] : data.message; const threadId = event.type === "thread.created" ? data.thread.id : data.thread_id; // Owners, those who wrote in the thread, whose suggestion it's about, and those mentioned; never its author or their agent's person. const audience = new Set([...data.owners, ...data.participants, data.suggestion_author, ...data.mentions].filter(Boolean)); audience.delete(message.author.user); for (const user of audience) { await bell.add(user, { document: data.document, thread: threadId, message: message.id, kind: data.mentions.includes(user) ? "mention" : event.type === "thread.created" ? "comment" : "reply", from: message.author.name, excerpt: message.excerpt, }); } break; } case "thread.message_edited": { // Keep the excerpt current; those it newly mentions hear of it now. await bell.updateExcerpt(data.message.id, data.message.excerpt); for (const user of data.newly_mentioned) await bell.add(user, { document: data.document, thread: data.thread_id, message: data.message.id, kind: "mention" }); break; } case "thread.message_deleted": { if (data.thread_deleted) await bell.removeThread(data.document, data.thread_id); else await bell.removeMessage(data.message_id); break; } case "thread.resolved": { // Resolved, or gone with its text or suggestion: no longer news. Keep a reply that reopened it since. await bell.removeThread(data.document, data.thread_id, { before: event.created_at }); break; } } } ``` `mention.created` comes too, one per person mentioned, for a platform that only wants mentions. Use one or the other, or skip a mention you've already told someone of by its `message_id`. People can also mention someone in the document's text, by typing `@` in the editor, and agents by writing a mention in their Markdown. Those come only as `mention.created`, a minute after they're written so the excerpt has the whole sentence, with a `block_id` and no thread or message. Tell them as their own notification, opening the document. A mention looks like this: ```json { "id": "evt_1Nf3Qa8Z", "type": "mention.created", "created_at": "2026-10-30T14:12:09.217Z", "actor": { "type": "agent", "agent": "agt_3Vn8Qx2K", "user": "usr_5Kq2Lm8R" }, "data": { "document": "doc_8Hq2Lm4R", "mentioned": "usr_9Tb3Wc1X", "author": { "type": "agent", "agent": "agt_3Vn8Qx2K", "user": "usr_5Kq2Lm8R", "name": "Claude Code" }, "thread_id": "thr_6Pz3", "message_id": "msg_9Xc1", "block_id": null, "excerpt": "@Grace Hopper does this match your notes?" } } ``` Here an agent wrote the comment for Ada (`usr_5Kq2Lm8R`), so it reaches Grace (`usr_9Tb3Wc1X`) but not Ada. Show it as Undertext does, crediting both: "Claude Code (Ada Lovelace's agent) mentioned you". [`credit` and `colorOf`](/reference/node#people) give you that name, and the colour the editor shows them in. ## Link to the right place Events carry ids, not URLs, because the document lives at your URL. Build the link in your app, such as `https://acme.com/notes/doc_8Hq2Lm4R?thread=thr_6Pz3`, and open the editor at the comment with the `target` option: ```ts mountEditor(element, { document: "doc_8Hq2Lm4R", getToken, target: { kind: "comment", id: "thr_6Pz3" } }); ``` When the person reads a thread in the editor, by opening it or writing in it, the editor sends a `thread-read` event: mark your notifications of it read. Before showing notifications, check the person can still open each document: [`GET /v1/users/{id}/documents?ids=…`](/reference/api/users#list-a-users-documents) answers with those they can, and their titles. ## Email Most people want email for some of these, not all. Undertext's own app gathers what's still unread in a document after 10 minutes into one email. You can do the same from your bell: when an item is still unread after a while, send it. ## Keep your lists current Some events aren't notifications but tell you to refresh something you keep: - `document.created`, `document.renamed`, `document.trashed`, `document.restored`, `document.deleted`: an agent or a person changed a document your lists show. - `agent.connected`, `agent.revoked`: a person's agents changed. - `seal.withdrawn`: a seal link now says it was withdrawn. ## Next - [Webhook events](/reference/webhooks): every event and its fields. - [Webhook endpoints](/reference/api/webhook-endpoints) in the API reference. # Seal and verify > Seal a document from the editor or your server, show the seal line in your app and seals on your own site, and know what a reader sees when they open one. Sealing takes a snapshot of a document as it stands, together with the record of how it was written, and gives it a short link: on your own site once you [show seals there](#show-seals-on-your-site), and at `seal.undertext.sh` until then. The text can then go anywhere, such as an email, a submission form or a pull request, and the link goes with it. Anyone who opens the link sees the sealed text, where its words came from, and when someone was active in the editor, unless its owners [made its seals private](#private-seals). By the end of this guide, your users can seal from the editor or from your own button, your app knows about every seal, your site shows them, and you know what readers will see. ## Seal from the editor The editor has a **Seal** button (your own button can open it with `editor.openSeal()`). Anyone who can open the document sees its seals there, with their links and who reads them, and its editors the readers listed. Its owners also seal there on confirmation, choose who reads the document's seals, answer people asking to read them, and withdraw versions. You don't need to build anything for this, but your app should hear about it: ```ts editor.on("seal", ({ code, url, line }) => { sealList.add({ code, url, line }); }); ``` The same seal also arrives as a `seal.created` webhook, which is the one to rely on for anything you store: the page may be closed before the event reaches it. See [Send notifications](/guides/notifications). ## Seal from your server To seal from your own button, or as part of your own flow such as submitting an assignment, call the API with the user who is sealing. They must be one of the document's members who edit it, or an owner, and it can't be sealed while it has pending suggestions. ```ts title="submit.ts" app.post("/assignments/:id/submit", requireSignIn, async (req, res) => { const assignment = await db.assignments.find(req.params.id); const seal = await undertext.seals.create(assignment.documentId, { user: req.user.undertextUserId }); await db.submissions.insert({ assignment: assignment.id, seal: seal.code, at: seal.sealed_at }); res.json({ url: seal.url, line: seal.line }); }); ``` The seal comes back with everything a reader will see: ```json { "code": "66G4LF343", "url": "https://seal.undertext.sh/66G4LF343", "document": "doc_8Hq2Lm4R", "version": 1, "sealed_at": "2026-10-30T16:31:04Z", "sealed_by": "usr_5Kq2Lm8R", "method": "v0.2", "line": "seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified)", "composition": { "typed": 86, "shaped": 10, "ai": 2, "external": 2 }, "presence": { "share": 99, "verified_share": 98, "verified": false }, "prompts": 101, "sittings": 9, "duration": "11hr2min", "attested_by": { "platform": "acme", "key_ids": ["key_2wLx7Hq"] }, "withdrawn_at": null, "preview": { "title": "On the Analytical Engine", "description": "96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified). Sealed with Undertext, written in Acme Notes (acme.com, verified).", "image_url": "https://seal.undertext.sh/api/seals/66G4LF343/preview.png" } } ``` Sealing a document that reads exactly as its newest seal still up returns that seal, with `200` rather than `201`, so a form submitted twice doesn't seal twice. ## Before sealing To show where a document stands before anyone seals it, such as on a submit screen, read its live provenance. It uses the same method a seal would, but nothing is kept: ```ts const reading = await undertext.documents.provenance("doc_8Hq2Lm4R"); reading.composition; // { typed: 85.8, shaped: 10.2, ai: 2.3, external: 1.7 } reading.presence; // { share: 99, verified_share: 98, verified: false } ``` The editor's own seal, in the corner, shows the same reading as people write. ## Show the seal line The seal line is one string meant to travel with the text: the link, then the shares. Show it with a copy button wherever your users finish their work. ``` seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified) ``` When check-ins vouched for every sitting, the line ends `(verified)`; when they vouched for some, it says how much, such as `(98% verified)`. Show `seal.line` as it comes: don't rebuild it from the numbers, since rounding and wording are part of the method. Public seal links unfurl in chat apps and social sites with an image of the seal and its numbers. ## Show seals on your site Until you show seals yourself, a seal's link is its page on `seal.undertext.sh`. To show them at your own address instead, such as `https://acme.com/seals/66G4LF343`: 1. **Set your seal URL**, with `{code}` where the code goes, in the [console](https://undertext.sh/console) or from your server. Every seal's `url` and seal line name it from then on, those made before too. ```ts await undertext.platform.update({ seal_url: "https://acme.com/seals/{code}" }); ``` 2. **Serve a page there**, with a public seal's link-preview tags from its `preview`, so its link unfurls as it would on `seal.undertext.sh`: ```ts title="seals.ts" app.get("/seals/:code", async (req, res) => { const seal = await undertext.seals.retrieve(req.params.code).catch(() => null); if (!seal) return res.status(404).send(notFound()); // , og:title, og:description and og:image, from seal.preview when it isn't null, // escaped as any text people wrote: the title is theirs. res.send(sealPage(seal.code, seal.preview)); }); ``` 3. **Show the seal in it** with [`mountSeal`](/reference/embed#mountseal). Undertext draws the text, the seal and its breakdown in a frame of its own, as it does the editor, so what readers see is what Undertext recorded, whatever your page does around it. ```ts title="seal-page.ts" import { mountSeal } from "@undertext/embed"; const seal = mountSeal(document.getElementById("seal"), { code, getToken: async () => { const response = await fetch("/undertext/seal-session", { method: "POST" }); return response.ok ? (await response.json()).token : null; }, onSignIn: () => location.assign(`/sign-in?next=${encodeURIComponent(location.pathname)}`), }); seal.on("ready", ({ title }) => (document.title = title ?? "Acme Notes")); ``` Add `embed.undertext.sh` to your page's `frame-src` if it has a Content Security Policy, and make sure its origin is one of your embed origins. `seal.undertext.sh/<code>` keeps showing each public seal as Undertext's own page, where anyone can check what yours shows. ## Seal again A seal never changes. People can keep editing after sealing, and seal again whenever they like: each seal gets its own code and link, and its `version` counts up for that document. List them all with: ```ts const seals = await undertext.seals.list("doc_8Hq2Lm4R"); ``` ## Withdraw a seal Whoever sealed a version can withdraw it in the seal dialog, and an owner can withdraw any, for example one shared by mistake. Your server can withdraw any. Its link then says it was withdrawn, instead of showing the text. A seal can't be edited, only withdrawn. ```ts await undertext.seals.withdraw("66G4LF343"); ``` Deleting a document withdraws all its seals. You hear about each through `seal.withdrawn`. While a document is in its owners' trash, its seals are down, and come back when it's restored. ## Private seals In the seal dialog, its owners choose who reads a document's seals, every version alike: anyone with the link, or private: whoever can open the document, the readers they name by email (or `*@domain` for everyone at a domain), and whoever has a password, if they set one. A private seal's page offers the password. On your own seal page, your server also vouches for the person signed in with you, with a [seal session](/reference/api/sessions#for-seals) carrying the email you've verified for them, which `getToken` above asks for: ```ts title="seal-session.ts" app.post("/undertext/seal-session", requireSignIn, async (req, res) => { const user = req.user; const { token } = await undertext.sessions.create({ user: await undertextUserId(user), purpose: "seal", email: user.emailVerified ? user.email : null, }); res.json({ token }); }); ``` Undertext lets them in if they can open the document or their email is on the list. While the document's link lets anyone in, that's anyone you start a seal session for, as a seal's page can't tell who has the document's link. Pass the email only if you've verified it. Someone signed out, or signed in with an email it isn't shared with, sees a way to sign in that calls your `onSignIn`. On `seal.undertext.sh`, a private seal offers its password, and sends readers to sign in on your seal page. Someone signed in whose email you vouched for, and whom it doesn't let in, can ask its owners to let them read it, with a message, right on the seal's page. The owners answer in the seal dialog. Undertext sends [`seal_request.created`](/reference/webhooks#seal_requestcreated) with the owners to tell, then `seal_request.accepted` or `seal_request.declined`; tell the owners on the first, and the person asking on `accepted`, with the seal's link. ## What a reader sees 1. **The sealed text**, exactly as it stood, so a reader can compare it with what they were sent. 2. **The seal.** The outer ring is the whole document by where its words came from: typed by people, AI text people shaped, AI text kept as written, and external (pasted or imported). The inner ring is presence, in electric blue where check-ins vouched for it. 3. **The breakdown.** Prompts and agent work, who did what, the sittings on a timeline, which signals were on, and the date and method the seal was made under. Below it, who sealed it and when. 4. **Who vouches for what.** The page names your platform as where it was written, which vouches for who wrote it. Undertext vouches for how the text was written, because it recorded that itself. Your platform vouches for who the people are, because it signs them in. Check-ins are shown apart, as the part neither of you could produce. Each seal records the method version it was made under (`v0.2` above). When Undertext's method improves, existing seals keep their numbers; the page adds the reading under the newer method beside them, labelled as such, and never rewrites a seal. Each seal keeps the ids of the secret keys that started its writing sessions (`attested_by.key_ids`), so a seal written with a key you later find leaked can be traced to it. See [Go live](/guides/go-live#replace-keys). ## Next - [Seals](/concepts/seals): what each number means. - [Trust model](/concepts/trust-model): what a seal proves, and what it doesn't. - [Seals](/reference/api/seals) in the API reference. # Set up check-ins > Let your users add security keys and check in while they write, so their seals can show Verified Presence. A check-in is a tap on a security key while someone writes. It shows that a person with the key was there when asked, which is the one signal on a seal that neither an agent nor your own server can produce. When check-ins vouch for every sitting anyone wrote in, the seal's presence ring turns electric blue, shows a shield, and reads **Verified Presence**. By the end of this guide, your users can add a key from your own settings page, and turn Verified Presence on in the documents that need it. Check-ins are optional, and each person turns them on a document at a time: Verified Presence is a switch of their own in each document, off until they turn it on. A message needs none; a take-home exam might ask for them. ## Why the settings are Undertext's Security keys are tied to the website that registered them. For a key to vouch for writing recorded by Undertext, it has to be registered on Undertext's own domain, not yours. So adding keys happens in Undertext's presence settings, served from `embed.undertext.sh`: framed in your own settings page, or in a small window your page opens. Everything else about check-ins happens inside the editor, or through your own controls for it. ## Add presence settings to your app 1. **Add a presence session route.** It's like the editor's session route, with `purpose: "presence"` instead of a document. ```ts title="server.ts" app.post("/undertext/presence-session", requireSignIn, async (req, res) => { // undertextUserId: the helper from Embed the editor. const session = await undertext.sessions.create({ user: await undertextUserId(req.user), purpose: "presence" }); res.json({ token: session.token }); }); ``` 2. **Show them in your settings page.** Frame them where your settings are, with your platform's slug: ```ts title="settings.ts" import { mountPresenceSettings } from "@undertext/embed"; mountPresenceSettings(document.querySelector("#presence")!, { getToken: async () => (await (await fetch("/undertext/presence-session", { method: "POST" })).json()).token, platform: "acme", }, ({ keys }) => { presenceLabel.textContent = keys ? `${keys} key${keys === 1 ? "" : "s"}` : "No key yet"; }); ``` Or open them in a window of their own, which browsers that won't create a key in a frame need: ```ts title="settings.ts" import { openPresenceSettings } from "@undertext/embed"; document.querySelector("#presence-settings").addEventListener("click", () => { openPresenceSettings({ getToken: async () => { const response = await fetch("/undertext/presence-session", { method: "POST" }); return (await response.json()).token; }, }); }); ``` Call it from a click: browsers only let a page open a window in answer to one. 3. **Let people add keys.** People add, order and remove keys, and try a check-in (recorded nowhere). Framed, your callback hears each change; in the window, `openPresenceSettings` resolves with how many keys they have once they close it. ```ts const { keys } = await openPresenceSettings({ getToken }); presenceLabel.textContent = keys ? `${keys} key${keys === 1 ? "" : "s"}` : "No key yet"; ``` To know whether someone has a key without opening the window, ask your server: ```ts const { security_keys } = await undertext.users.retrieveCheckins("usr_5Kq2Lm8R"); ``` ## Turn Verified Presence on in a document People turn Verified Presence on or off in each document from the editor's breakdown. If your page has its own menu for the document, add a switch there: the editor's `status` event says whether it's on, `null` for someone who can't write in the document, and `setVerifiedPresence` turns it on or off. ```ts title="document.ts" editor.on("status", ({ verifiedPresence }) => { presenceSwitch.hidden = !verifiedPresence; presenceSwitch.checked = verifiedPresence?.on ?? false; presenceSwitch.disabled = verifiedPresence?.required ?? false; }); presenceSwitch.addEventListener("change", async () => { presenceSwitch.checked = await editor.setVerifiedPresence(presenceSwitch.checked); }); ``` Turning it on needs a key. Without one it stays off and the editor sends a `presence-settings` event: open presence settings for them, as you do when a check-in or the breakdown asks for them. It turns on once they come back to the editor with a key. ```ts editor.on("presence-settings", () => openPresenceSettings({ getToken: presenceToken })); ``` Your server can turn it on too, for example for every person writing a take-home exam who already has a key: ```ts await undertext.documents.updateCheckins("doc_8Hq2Lm4R", "usr_5Kq2Lm8R", { enabled: true }); ``` Without a key, it answers `409 no_security_keys`. ## Require it, or choose how often A take-home exam can't leave Verified Presence to each writer. Require it of everyone writing in your documents, and choose how often check-ins come, in the console's **Check-ins** section or with the API: ```ts await undertext.platform.update({ checkins_required: true, checkin_minutes: 5 }); ``` Required, it's on for everyone, whatever their switch said, and no one can turn it off: the editor's `status` says `verifiedPresence.required`, and `setVerifiedPresence(false)` leaves it on, so show your switch as on and locked. Someone without a key is asked all the same; the card offers to add one, and the editor sends `presence-settings`. Until they add one, their check-ins go unanswered and their writing unverified. `checkin_minutes` is `1`, `5`, `10` or `30`. Shorter asks more often, and each check-in vouches for less writing: about one and a half intervals. A seal's breakdown says how often its check-ins came, so readers can tell. To let your people choose how often, list the intervals they may pick from in `checkin_choices`. `checkin_minutes` stays the default, and is always among them: ```ts await undertext.platform.update({ checkin_minutes: 5, checkin_choices: [5, 10, 30] }); ``` Each person then picks one in presence settings, for all their documents. Leave `checkin_choices` empty, as it is unless you set it, and everyone is asked at `checkin_minutes`. ## Which keys work Undertext sorts each key when it's added: - **Hardware keys**, such as a YubiKey or Windows Hello on a TPM, prove the model they are. These count fully. - **Built-in authenticators** that can't prove their model, such as Touch ID through iCloud Keychain or Google Password Manager, are accepted as they are. - **Password managers and unknown software** are refused, because the key could be anywhere. The kind is kept with each check-in, so a reader of the seal's breakdown can see which keys vouched. ## What people see while writing Nothing changes until a check-in is due, and none is asked in a document where Verified Presence isn't on. Undertext asks on someone's first edit there after half an hour away from writing, then about every 5 minutes (or as often as you chose), at random times between half and one and a half intervals apart. A small card beside the seal asks for a tap. Reading, pointing and clicking never ask; writing, and accepting or rejecting suggestions, do. A tap within a minute passes. No tap is recorded as missed. Nothing stops writing either way: a miss only means the writing that follows it isn't verified, until the next check-in passes. ## How check-ins show on seals The seal's inner ring is presence: the share of the session with a person there, writing or reading as they write. The part vouched for by check-ins is drawn in electric blue. - When every sitting anyone wrote in was verified, the ring is blue all round, the shield shows, and the seal line ends `(verified)`. - When only some were, the line says how much, such as `(98% verified)`. - Someone who doesn't check in only goes unverified. Nothing counts against them. The seal object carries the same numbers, so your app can show them: ```ts const seal = await undertext.seals.retrieve("66G4LF343"); seal.presence; // { share: 99, verified_share: 98, verified: false } ``` See [Presence and check-ins](/concepts/presence-and-check-ins) for exactly what counts as verified. ## Next - [Seal and verify](/guides/seal-and-verify): what readers see on a sealed document. - [Trust model](/concepts/trust-model): why check-ins are the signal your own server can't produce. - [Embed API](/reference/embed#presence-settings) for every option of `mountPresenceSettings` and `openPresenceSettings`. # Share documents > Turn your sharing screen into members, roles and link access in Undertext, and know what agents can do as roles change. Your app owns the sharing screen: who to invite, how invitations are sent, and what a shared link looks like. Undertext owns the result: who may open each document and what they may do in it. By the end of this guide, your Share dialog writes members and link access to Undertext, and anyone who opens a shared link gets the right role in the editor. Undertext checks roles on every session and every agent call, so what you write here takes effect at once, in open editors too. ## Roles | Role | In the editor, can | | --- | --- | | `owner` | Everything an editor can, and seal the document. A document has one or more owners. | | `editor` | Write, accept and reject suggestions, and comment. | | `suggester` | Suggest changes and comment. Their suggestions wait for an editor. | | `viewer` | Read. | The first owner is whoever you name when you create the document. Who may share, change link access or delete is your app's rule, enforced in your routes, since those actions go through your server. See [Documents and access](/concepts/documents-and-access) for the full rules. ## Add and remove members When someone in your Share dialog invites a person, add them as a member with a role, by their Undertext id. `undertextUserId` is the helper from [Embed the editor](/guides/embed-the-editor): it creates the Undertext user the first time and returns the stored id after that. ```ts title="share.ts" app.post("/notes/:id/members", requireSignIn, async (req, res) => { const { userId, role } = req.body; // from your Share dialog const invitee = await db.users.find(userId); await undertext.members.put(req.params.id, await undertextUserId(invitee), { role }); await sendInviteEmail(invitee, req.params.id); // yours to send res.sendStatus(204); }); ``` Undertext doesn't check who is allowed to share: your route should. A common rule is the one Undertext's own app uses, where editors and owners may invite, and nobody may give a role above their own. Look up the caller's role with [`GET /v1/documents/{id}/members`](/reference/api/members) if you don't keep your own copy. To change someone's role, `PUT` it again. To remove them: ```ts await undertext.members.delete("doc_8Hq2Lm4R", "usr_9Tb3Wc1X"); ``` Removing a member ends their access straight away. If Grace has the document open, Grace's editor closes it and fires an `error` event with the code `no_access`. A change of role that changes how they write, such as editor to suggester, reloads their editor with the new role. `detail` is the second line Undertext shows under a name when someone types `@` to mention a person, here the email address. Leave it out if your app doesn't show emails to other people. ## Share by link Link access lets anyone who has the link open the document, with a role you choose, without being added as a member. It's off (`restricted`) until the owner turns it on. 1. **Set the link's role.** When the owner picks "Anyone with the link can suggest" in your dialog: ```ts await undertext.documents.update("doc_8Hq2Lm4R", { link_access: "suggest" }); ``` The values are `restricted`, `view`, `suggest` and `edit`. 2. **Give the link a page in your app.** The link is your own URL, such as `https://acme.com/n/doc_8Hq2Lm4R`. Undertext never hands out document links of its own. 3. **Start link sessions.** When someone who isn't a member opens that page, start their session with `via: "link"`: ```ts const session = await undertext.sessions.create({ user: await undertextUserId(visitor), document: "doc_8Hq2Lm4R", via: "link", }); // session.role is "suggester" here: the link's role, or their member role if that's higher. ``` Undertext refuses it with `no_access` when link access is `restricted`. Visitors still need to be users: if your app lets people in without signing up, see [Anonymous users](/guides/anonymous-users). Opening a document by link doesn't make someone a member, so it doesn't appear in their [document list](/reference/api/users). If your app keeps a list of documents people have opened by link, keep it yourself, or add them as members when they first write. Turning link access back to `restricted` ends every link session at once. ## Owners Give someone the `owner` role to make them an owner too. To hand a document over, make the new person an owner, then lower the old owner's role or remove them. A document always keeps an owner: lowering or removing the last one is refused with `409 last_owner`. ```ts await undertext.members.put("doc_8Hq2Lm4R", "usr_9Tb3Wc1X", { role: "owner" }); await undertext.members.put("doc_8Hq2Lm4R", "usr_5Kq2Lm8R", { role: "editor" }); ``` Seals already made keep the name of whoever sealed them. ## What agents get An agent acts for one person, and can never do more than that person can. Its role in a document is the lower of the role its person gave it and the person's own current role. So your sharing changes reach agents with no extra work: - Remove Grace from a document, and Grace's agents lose it at the same moment. - Make Grace a viewer, and Grace's agents can only read, even if Grace gave them editing. - Turn on link access, and agents of people who have the link may reach the document too, by its id, with at most the link's role: an agent with `access: "all"` reaches any document its person can open. Its `list_documents` lists only documents its person is a member of. Agents can never be owners. See [Connect agents](/guides/connect-agents) for how people choose what each agent reaches. ## Next - [Members](/reference/api/members) and [Documents](/reference/api/documents) in the API reference. - [Send notifications](/guides/notifications) when someone comments on or is mentioned in a shared document. # Add your own agent tools > Give agents your app's own features, such as folders and pins, as tools Undertext's MCP server lists beside its own and forwards to your server. Undertext's MCP server gives agents everything about documents: reading, writing, suggesting and commenting. It doesn't know about the things your app keeps itself, such as folders, pins, tags, projects or due dates. To let agents use those too, register tools of your own with Undertext. Its server lists them beside its own, at the same address, and forwards each call to your server, signed, saying which agent is calling and for whom. By the end of this guide, an agent can file a document it just wrote into one of your folders, with nothing more for your users to connect. ## How it fits | | Undertext's tools | Yours | | --- | --- | --- | | Address | Your MCP address, `https://mcp.undertext.sh/acme` | The same | | Tools | Documents: read, write, suggest, comment | Your features: folders, pins, tags | | Runs on | Undertext | Your server, called by Undertext | | Sign-in | Undertext's, via your consent page | The same: one approval covers both | Document ids are the same in both: `doc_8Hq2Lm4R` in Undertext's `list_documents` is the id your folders table already stores. So an agent can find a document with Undertext's tools and file it with yours, without any translation. Keep document text in Undertext's tools. Your tools never write text into a document: words that don't come through Undertext's own tools or editor aren't credited to whoever wrote them. ## Register your tools 1. **Describe them.** Each tool is a name, a description and a JSON Schema for its arguments, as MCP describes tools. Names can't be one of Undertext's own. Say in `instructions` how your tools relate to Undertext's, so agents use the two together. ```ts title="tools.ts" export const TOOLS = [ { name: "list_folders", title: "List folders", description: "The person's folders, in their order, with the documents in each.", inputSchema: { type: "object", properties: {}, additionalProperties: false }, }, { name: "move_document", title: "Move document", description: "File a document in one of the person's folders, or in none with folder_id null. Only when they ask.", inputSchema: { type: "object", properties: { document_id: { type: "string" }, folder_id: { type: ["string", "null"] } }, required: ["document_id", "folder_id"], additionalProperties: false, }, }, ]; ``` 2. **Register them when your server starts**, with the address Undertext sends calls to and a secret of at least 32 characters, which you choose and keep: ```ts title="server.ts" await undertext.platform.setTools({ url: "https://acme.com/undertext/tools", secret: process.env.ACME_TOOLS_SECRET!, instructions: "Folders are the person's own: list_folders shows them, move_document files a document in one.", tools: TOOLS, }); ``` Each call replaces what you registered before. Agents see the change at their next `tools/list`. 3. **Answer the calls.** Undertext posts each call as JSON, signed in an `Undertext-Signature` header as webhooks are: ```json { "tool": "move_document", "arguments": { "document_id": "doc_8Hq2Lm4R", "folder_id": "fld_2" }, "agent": { "id": "agt_3Vn8Qx2K", "name": "Claude Code", "access": "all" }, "user": "usr_5Kq2Lm8R" } ``` `user` is the Undertext id of the person the agent acts for. Check the signature, run the tool for that person, and answer within 10 seconds with `{ "text": … }`, what to tell the agent, and optionally `data`, given to it as structured content; or with `{ "error": … }` to refuse. ```ts title="tools.ts" import { verifySignature } from "@undertext/sdk"; app.post("/undertext/tools", express.raw({ type: "application/json" }), async (req, res) => { if (!verifySignature(req.body, req.get("Undertext-Signature"), process.env.ACME_TOOLS_SECRET!)) return res.sendStatus(401); const call = JSON.parse(String(req.body)); const user = await db.users.findByUndertextId(call.user); if (!user) return res.json({ error: "That person has no account here." }); switch (call.tool) { case "list_folders": { const folders = await db.folders.list(user.id); return res.json({ text: folders.map((f) => `- ${f.name} (folder_id: ${f.id})`).join("\n"), data: { folders } }); } case "move_document": { const { document_id, folder_id } = call.arguments; const mine = await undertext.users.listDocuments(call.user, { ids: [document_id] }); if (!mine.data.length) return res.json({ error: `No document ${document_id} for this person.` }); await db.folders.place(user.id, document_id, folder_id); return res.json({ text: "Moved." }); } } res.json({ error: `Unknown tool ${call.tool}.` }); }); ``` Check access against Undertext, as `move_document` does, so your tools never reach a document the person can't open. `agent.access` says whether the agent may reach all its person's documents or only those chosen for it; refuse what an agent with chosen documents shouldn't see, such as a list of every folder. An answer that isn't JSON, is over 1 MB, has a status other than `2xx`, or doesn't come in time reaches the agent as a failed call. ## Next - [Platform](/reference/api/platform#set-your-agent-tools): `PUT /v1/platform/tools` in the API reference. - [MCP tools](/reference/mcp): the tools Undertext's server already has, so yours don't repeat them. # How Undertext works > What runs where when you build on Undertext, the five connections between your product and Undertext, and who owns what. Undertext records how a document was written: who typed which words, what agents wrote, what was pasted, and when someone was active in the editor. To do that it needs to be the one watching the writing. So the editor is Undertext's own, served from Undertext's domain and embedded in your page. Everything around it stays yours: accounts, sign-in, document lists, sharing screens and notifications. ## The five connections 1. **Your server calls the REST API** with your secret key. It tells Undertext who your users are, creates documents, sets who may open them, starts editor sessions, approves agents and seals documents. See the [REST API reference](/reference/api/overview). 2. **Your page mounts the editor** with the embed script. You pass a short-lived session token and a few options, and you hear events back: the title changed, someone followed a link to another document, a seal was made. See the [Embed API](/reference/embed). 3. **The editor talks to Undertext directly.** Every change goes from Undertext's code, on Undertext's domain, to Undertext's servers. Your page can't see inside the iframe or type into it, and that is what lets a seal say where words came from. See the [trust model](/concepts/trust-model). 4. **Undertext sends webhooks to your server** when something happens that your users should hear about: a comment, a reply, a mention, a new seal, an agent connected. You turn them into your own notifications. See [Webhook events](/reference/webhooks). 5. **Your users' agents connect to Undertext's MCP server** at your platform's own address. When someone connects one, Undertext sends them to your consent page to approve it, then issues the agent's tokens itself. See [Connect agents](/guides/connect-agents). ## Who owns what | | Undertext | Your product | | --- | --- | --- | | Accounts and sign-in | No accounts; an Undertext id for each of your users | Yours | | Names and pictures | Shown in the editor and on seals | You send them, and vouch for them | | Who may open a document | Stored and enforced | You decide, and set it through the API | | Document text and its history | Stored | Read it through the API or exports | | Where each word came from | Recorded and classified | Read it through the API | | Check-ins and security keys | Stored, on Undertext's domain | You open the settings window | | Seals and seal pages | Made, and drawn in a frame of Undertext's | You trigger them, hear about them, and show them at your own address | | Agent connections and tokens | Issued and enforced | You approve, list and revoke them | | Document lists, folders, pins | A user's documents, by id | Your screens, your folders | | Notifications and email | Webhooks | Yours to send | ## From sign-in to seal 1. Ada signs in to Acme Notes, your product, as usual. 2. Ada opens a document. Your server checks that Ada may, asks Undertext for an editor session for Ada and that document, and sends the token to the page. 3. The page mounts the editor with the token, and Ada writes. Grace, who Ada shared the document with, suggests changes in a session of Grace's own. Ada's Claude Code, connected to Acme Notes last week, drafts a section through MCP, credited to "Claude Code (Ada Lovelace's agent)". 4. If Ada turned on Verified Presence in the document, the editor asks now and then, as Ada writes there, for a tap of Ada's security key. Each tap is recorded with the writing around it. 5. Ada seals the document, from the editor's Seal button or from a button in your product that calls the API. Undertext takes a snapshot of the text and its record and gives it a short address: on your site, like `acme.com/seals/66G4LF343`, where your page shows the seal in a frame of Undertext's, once you've set a seal URL; until then, `seal.undertext.sh/66G4LF343`. 6. Your server hears `seal.created`. Ada pastes the essay and its seal line wherever it is going. Anyone who opens the link sees the seal, where the words came from, and that Acme Notes vouches for who Ada is. ## What Undertext doesn't do - **Sign anyone in.** Undertext never sees a password or an email address unless you send one as a user's detail line. - **Send email.** Every notification goes to you as a webhook. - **Show lists of documents.** Your product decides how documents are found, filed and ordered. Undertext can list a user's documents for you, but the screens are yours. - **Decide who may open what.** Your sharing screens make that choice. Undertext stores the result and enforces it, for people and agents alike. Undertext's own app, at undertext.net, is built on this same API. Its accounts, sidebar, folders and email are its own, and its editor is the one you embed. # Quickstart > From an empty Node project to a document written in the embedded editor and sealed. By the end of this page you'll have a small Node app that signs nobody in, creates a document for one test user, opens it in the Undertext editor, and seals it. It takes about ten minutes. Make a platform just for trying things: what you make on it stays apart from the one your users get. You need Node 20 or later and an Undertext console account. 1. **Get a key.** In the [console](https://undertext.sh/console), create a platform. Call it anything; we'll use Acme Notes, with the slug `acme`. Copy its secret key, which starts with `sk_`, and keep it on your server only. ```bash export UNDERTEXT_SECRET_KEY=sk_51Hc… ``` Under **Embed origins**, add `http://localhost:3000`, where this app will run, so the editor loads there. 2. **Install the SDKs.** `@undertext/sdk` is for your server; `@undertext/embed` mounts the editor in the browser. ```bash mkdir acme-notes && cd acme-notes npm init -y && npm pkg set type=module npm install @undertext/sdk @undertext/embed express ``` 3. **Create a user and a document.** Undertext has no accounts. You tell it who your users are under your own ids, and it gives each one an Undertext id and stores a name to show in the editor and on seals. ```ts title="setup.js" import Undertext from "@undertext/sdk"; const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY); const ada = await undertext.users.upsert("u_42", { name: "Ada Lovelace" }); // u_42 is your id for Ada const doc = await undertext.documents.create({ owner: ada.id, name: "Notes on the Engine" }); console.log(ada.id, doc.id); ``` ```bash node setup.js # usr_5Kq2Lm8R doc_8Hq2Lm4R ``` In a real app you'd store `ada.id` beside your own user, as you would a Stripe customer id. 4. **Add a session route.** The browser never sees your secret key. Instead, your server starts an editor session for one user and one document, and hands the page its token, which lasts 15 minutes. In a real app you'd check who is signed in first; here everyone is Ada. ```ts title="server.js" import express from "express"; import Undertext from "@undertext/sdk"; const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY); const app = express(); app.post("/undertext/session", express.json(), async (req, res) => { // Your own sign-in check goes here; it would give you the user's stored Undertext id. const ada = "usr_5Kq2Lm8R"; // the id setup.js printed const session = await undertext.sessions.create({ user: ada, document: req.body.document }); res.json({ token: session.token }); }); app.use(express.static("public")); app.listen(3000); ``` 5. **Mount the editor.** The editor fills the element you give it and asks `getToken` for a new token whenever the old one is about to lapse. ```html title="public/index.html" <!doctype html> <title>Acme Notes
``` Run `node server.js` and open `http://localhost:3000`. Write a few paragraphs. Paste a sentence from somewhere else, too. The seal in the editor's corner fills in as you go: graphite for what you typed, grey for what you pasted. 6. **Seal it.** Use the editor's Seal button, or seal from your server: ```ts title="seal.js" import Undertext from "@undertext/sdk"; const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY); const seal = await undertext.seals.create("doc_8Hq2Lm4R", { user: "usr_5Kq2Lm8R" }); console.log(seal.line); // seal.undertext.sh/TQ81KD2MA · 91% typed/shaped · 0% AI · 9% external · 0 prompts · 1 session, 6min ``` Open `seal.url`. That is what anyone you share it with sees: the seal, where the words came from, the session on a timeline, and a note that Acme Notes vouches for who Ada is. ## What you built Your server owns who Ada is and which documents Ada may open. Undertext owns the editor and the record of what happened in it. The only thing that crossed from your server to the browser was a token for one document, good for 15 minutes. ## Next - [Embed the editor](/guides/embed-the-editor) properly: your own sign-in check, appearance, and events back from the editor. - [Share documents](/guides/share-documents) between your users, with roles and link access. - [Connect agents](/guides/connect-agents) so your users can bring Claude Code, Codex or any MCP client. - Read the [trust model](/concepts/trust-model) before you tell your users what a seal proves. # Agent requests > Approve or deny an agent from your consent page, so Undertext can issue it tokens. An agent request is one agent asking to act for one of your users. When someone adds your MCP address to their agent, the agent registers with Undertext and opens the person's browser at Undertext's authorize page. Undertext has no sign-in, so it sends the browser on to the consent URL you set in the [console](https://undertext.sh/console) or with [`PATCH /v1/platform`](/reference/api/platform), with the request's id: ``` https://acme.com/undertext/connect?request=areq_7Tc1Pz9M ``` Your page signs the person in if they aren't already, shows them which agent is asking, lets them name it, and on Allow or Deny calls one of the endpoints below from your server. Each returns a `redirect_url`; send the browser there, and Undertext finishes the OAuth flow with the agent directly. You approve; Undertext issues the agent's tokens; you never see them. See [Connect agents](/guides/connect-agents) for the whole flow. A request lasts 10 minutes and can be answered once. ## The agent request object | Attribute | Type | Description | | --- | --- | --- | | `id` | string | The request's id, starting `areq_`. | | `status` | string | `pending`, `approved`, `denied` or `expired`. | | `client` | object | The agent asking. `name`: the name it registered with. `host`: the domain its registration is published from, checked by Undertext, so it can't claim someone else's. `local`: whether it's an app on the person's own device, coming back to a loopback address or its own scheme, whose `host` says nothing people can check. `logo_url`: its logo, or `null`. | | `agent` | object or null | Retrieved for a `user`: their agent that approving would update, because they approved the same client before, with its `id` and the `name` they gave it. `null` otherwise. | | `expires_at` | timestamp | When the request lapses if it isn't answered. | ```json { "id": "areq_7Tc1Pz9M", "status": "pending", "client": { "name": "Claude Code", "host": "claude.ai", "local": false, "logo_url": "https://claude.ai/images/claude-code-icon.png" }, "agent": null, "expires_at": "2026-10-30T18:30:00Z" } ``` Show `client.name` and `client.host` together on your consent page. The name is whatever the client chose; the host is the part people can trust. For a `local` client, say it's an app on their computer instead of showing its local address. Offer a field for what the person will call the agent, filled in with `agent.name` when they're connecting the same client again, and `client.name` otherwise. ## Retrieve an agent request `GET /v1/agent-requests/{request_id}` | Parameter | Type | Description | | --- | --- | --- | | `request_id` | string, path, required | The `request` value from your consent URL. | | `user` | string, query | The Undertext id of the person signed in to your consent page, to learn which of their agents approving would update. | ```bash tab="curl" tab-group="lang" curl "https://api.undertext.sh/v1/agent-requests/areq_7Tc1Pz9M?user=usr_5Kq2Lm8R" \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const request = await undertext.agentRequests.retrieve("areq_7Tc1Pz9M", { user: "usr_5Kq2Lm8R" }); ``` Returns the [agent request](#the-agent-request-object), or `404 request_not_found` for an id that isn't one of yours, or a `user` that isn't. ## Approve an agent request `POST /v1/agent-requests/{request_id}/approve` Approves the agent for one of your users and creates the [agent](/reference/api/agents). Call it only after your own sign-in has confirmed who the person is, and only from a deliberate action such as a form post, never from a page load. If the user has already connected this same client, Undertext keeps the existing agent and replaces its access with what you pass here, and its name if you pass one. | Parameter | Type | Description | | --- | --- | --- | | `request_id` | string, path, required | The request's id. | | `user` | string, required | The Undertext id of the person approving: the one signed in to your product, never a value from the form. | | `access` | string, required | `all` for every document they can open, editing at most, or `chosen` for only the documents in `documents`. | | `name` | string | What the person calls the agent: 1 to 48 characters, trimmed, without control or invisible characters. Without it, a new agent is called what its client calls itself, and an existing one keeps its name. | | `documents` | object | With `chosen`: a map from document id to role, `editor`, `suggester` or `viewer`. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agent-requests/areq_7Tc1Pz9M/approve \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{ "user": "usr_5Kq2Lm8R", "access": "chosen", "name": "Research", "documents": { "doc_8Hq2Lm4R": "suggester" } }' ``` ```ts tab="Node" const { redirect_url } = await undertext.agentRequests.approve("areq_7Tc1Pz9M", { user: "usr_5Kq2Lm8R", access: "chosen", name: "Research", documents: { doc_8Hq2Lm4R: "suggester" }, }); // then redirect the browser to redirect_url ``` ```json { "redirect_url": "https://mcp.undertext.sh/acme/authorize/continue?state=pz9Kq2Vn8Lr4", "agent": { "id": "agt_6Bw4Ys7J", "user": "usr_5Kq2Lm8R", "name": "Codex", "host": "openai.com", "access": "chosen", "connected_at": "2026-10-30T18:21:40Z", "last_used_at": null } } ``` For an agent that's new, Undertext also sends `agent.connected` to your [webhook endpoints](/reference/webhooks). | Error | When | | --- | --- | | `400 missing_parameter` on `documents` | `access` is `chosen` and `documents` is empty or missing. | | `400 invalid_parameter` on `documents` | A role is `owner` or not a role. | | `404 user_not_found` | The user doesn't exist. | | `404 document_not_found` | A document in `documents` doesn't exist. | | `409 request_expired` | More than 10 minutes have passed. The person starts again from their agent. | | `409 request_already_answered` | The request was approved or denied already. | ## Deny an agent request `POST /v1/agent-requests/{request_id}/deny` Turns the agent away. Send the browser to `redirect_url` so the agent hears the answer instead of waiting. | Parameter | Type | Description | | --- | --- | --- | | `request_id` | string, path, required | The request's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agent-requests/areq_7Tc1Pz9M/deny \ -X POST \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const { redirect_url } = await undertext.agentRequests.deny("areq_7Tc1Pz9M"); ``` ```json { "redirect_url": "https://mcp.undertext.sh/acme/authorize/continue?state=pz9Kq2Vn8Lr4" } ``` | Error | When | | --- | --- | | `409 request_expired` | More than 10 minutes have passed. | | `409 request_already_answered` | The request was approved or denied already. | # Agents > List, name, limit and revoke the AI agents your users connected to their documents. An agent is an MCP client, such as Claude Code or Codex, that one of your users approved to work in their documents. It connects to your platform's MCP address at `https://mcp.undertext.sh/acme`, and Undertext issues its tokens; your server never holds them. These endpoints are for your settings screens: show people their agents, let them name each, choose which documents each reaches, and revoke them. Agents are created by approving an [agent request](/reference/api/agent-requests). See [Agents](/concepts/agents). An agent's access is either: - **`all`**: every document its person can open, editing at most. - **`chosen`**: only the documents you give it a role in. Either way, what it may do in a document is the lower of that and its person's current role there, checked on every call. It never owns a document. ## The agent object | Attribute | Type | Description | | --- | --- | --- | | `id` | string | Undertext's id for the agent, starting `agt_`. | | `user` | string | The Undertext id of the person it acts for. | | `name` | string | What its person calls it: at first what its client calls itself, until you name it. Its edits are credited as this name and its person's: "Research (Ada's agent)". | | `client_name` | string | What its client calls itself, such as "Claude Code", as the person saw when approving it. | | `host` | string | The domain the client is published from, checked by Undertext. Two agents can share a name; the host tells them apart. | | `local` | boolean | Whether the client is an app on its person's own device, such as a command-line tool or desktop app, that registered to come back to a loopback address or its own scheme. Its `host` is then that address, which says nothing people can check: show "On your computer" instead. | | `access` | string | `all` or `chosen`. | | `connected_at` | timestamp | When its person approved it. | | `last_used_at` | timestamp or null | When it last called a tool, or `null` if it hasn't yet. | | `expires_at` | timestamp or null | Until when it can renew its access unused: its newest refresh token lapses then, 90 days after it last renewed. Past it, or at `null`, its person approves it again. | ```json { "id": "agt_3Vn8Qx2K", "user": "usr_5Kq2Lm8R", "name": "Research", "client_name": "Claude Code", "host": "claude.ai", "local": false, "access": "all", "connected_at": "2026-10-13T21:30:02Z", "last_used_at": "2026-10-13T22:58:41Z", "expires_at": "2027-01-11T22:58:41Z" } ``` ## List a user's agents `GET /v1/users/{user_id}/agents` The agents a user has connected, newest first. | Parameter | Type | Description | | --- | --- | --- | | `user_id` | string, path, required | The user's Undertext id. | | `document` | string | A document id: each agent then has one more field, `document_role`, the role you gave it there, or `null`. For a document's sharing screen. | | `limit` | integer | 1 to 100. Default 50. | | `after` | string | The `next` cursor from the previous page. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/agents \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const page = await undertext.users.listAgents("usr_5Kq2Lm8R"); ``` ```json { "data": [ { "id": "agt_6Bw4Ys7J", "user": "usr_5Kq2Lm8R", "name": "Codex", "host": "openai.com", "access": "chosen", "connected_at": "2026-10-13T22:31:15Z", "last_used_at": "2026-10-13T22:38:09Z" }, { "id": "agt_3Vn8Qx2K", "user": "usr_5Kq2Lm8R", "name": "Claude Code", "host": "claude.ai", "access": "all", "connected_at": "2026-10-13T21:30:02Z", "last_used_at": "2026-10-13T22:58:41Z" } ], "next": null } ``` ## Retrieve an agent `GET /v1/agents/{agent_id}` | Parameter | Type | Description | | --- | --- | --- | | `agent_id` | string, path, required | The agent's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agents/agt_3Vn8Qx2K \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const agent = await undertext.agents.retrieve("agt_3Vn8Qx2K"); ``` Returns the [agent](#the-agent-object), or `404 agent_not_found` once it has been revoked. ## Update an agent `PATCH /v1/agents/{agent_id}` Names an agent, or switches it between reaching all its person's documents and only the ones you choose, or both. A new name shows at once in the documents open now, and on everything the agent wrote; the access applies to its next tool call. Approving the same client again later keeps the name. Switching to `chosen` keeps any roles you set before. An agent switched to `chosen` with no roles reaches nothing until you [give it a document](#set-an-agents-role-in-a-document). | Parameter | Type | Description | | --- | --- | --- | | `agent_id` | string, path, required | The agent's id. | | `name` | string | What its person calls it: 1 to 48 characters, trimmed, without control or invisible characters. | | `access` | string | `all` or `chosen`. | Give `name`, `access` or both. ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agents/agt_3Vn8Qx2K \ -X PATCH \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"name": "Research", "access": "chosen"}' ``` ```ts tab="Node" const agent = await undertext.agents.update("agt_3Vn8Qx2K", { name: "Research", access: "chosen" }); ``` Returns the updated [agent](#the-agent-object). ## List an agent's documents `GET /v1/agents/{agent_id}/documents` The documents you've given an agent a role in, most recently edited first. These roles apply while its access is `chosen`; with `all`, it reaches every document its person can open and this list is kept for when you switch. | Parameter | Type | Description | | --- | --- | --- | | `agent_id` | string, path, required | The agent's id. | | `limit` | integer | 1 to 100. Default 50. | | `after` | string | The `next` cursor from the previous page. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agents/agt_6Bw4Ys7J/documents \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const page = await undertext.agents.listDocuments("agt_6Bw4Ys7J"); ``` ```json { "data": [ { "agent": "agt_6Bw4Ys7J", "document": "doc_8Hq2Lm4R", "title": "On the Analytical Engine", "role": "suggester", "effective_role": "suggester" }, { "agent": "agt_6Bw4Ys7J", "document": "doc_3Wp7Zc1V", "title": "Notes for Thursday", "role": "editor", "effective_role": "suggester" } ], "next": null } ``` | Attribute | Type | Description | | --- | --- | --- | | `role` | string | The role you gave the agent: `editor`, `suggester` or `viewer`. | | `effective_role` | string or null | What it can do now: the lower of `role` and its person's current role. `null` when its person can no longer open the document. | ## Set an agent's role in a document `PUT /v1/agents/{agent_id}/documents/{document_id}` Gives an agent a role in one document, or changes it. | Parameter | Type | Description | | --- | --- | --- | | `agent_id` | string, path, required | The agent's id. | | `document_id` | string, path, required | The document's id. | | `role` | string, required | `editor`, `suggester` or `viewer`. An agent is never an owner. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agents/agt_6Bw4Ys7J/documents/doc_8Hq2Lm4R \ -X PUT \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"role": "suggester"}' ``` ```ts tab="Node" await undertext.agents.putDocument("agt_6Bw4Ys7J", "doc_8Hq2Lm4R", { role: "suggester" }); ``` ```json { "agent": "agt_6Bw4Ys7J", "document": "doc_8Hq2Lm4R", "title": "On the Analytical Engine", "role": "suggester", "effective_role": "suggester" } ``` | Error | When | | --- | --- | | `400 invalid_parameter` on `role` | `role` is `owner`, or not a role. | | `404 document_not_found` | The document doesn't exist. | ## Remove an agent's role in a document `DELETE /v1/agents/{agent_id}/documents/{document_id}` Takes a document off an agent's list. With `chosen` access, it can no longer reach the document. | Parameter | Type | Description | | --- | --- | --- | | `agent_id` | string, path, required | The agent's id. | | `document_id` | string, path, required | The document's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agents/agt_6Bw4Ys7J/documents/doc_8Hq2Lm4R \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.agents.deleteDocument("agt_6Bw4Ys7J", "doc_8Hq2Lm4R"); ``` ```json { "agent": "agt_6Bw4Ys7J", "document": "doc_8Hq2Lm4R", "removed": true } ``` ## Revoke an agent `DELETE /v1/agents/{agent_id}` Disconnects an agent for good. Its tokens stop working at once, mid-call included, and Undertext sends `agent.revoked`. What it already wrote stays in documents, credited to it. To connect it again, its person approves it again. | Parameter | Type | Description | | --- | --- | --- | | `agent_id` | string, path, required | The agent's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/agents/agt_3Vn8Qx2K \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.agents.revoke("agt_3Vn8Qx2K"); ``` ```json { "id": "agt_3Vn8Qx2K", "revoked": true } ``` # 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](/reference/api/members) or through its link access. See [Documents and access](/concepts/documents-and-access). ## The document object | Attribute | Type | Description | | --- | --- | --- | | `id` | string | Undertext's id for the document, starting `doc_`. | | `name` | string or null | The name an editor gave it, or `null` when it has none. | | `title` | string | What to call it in your lists: its `name`, or its first line when it has no name. | | `owners` | array | The Undertext ids of its owners, in the order they became owners. | | `link_access` | string | What people get by link without being members: `restricted`, `view`, `suggest` or `edit`. | | `created_at` | timestamp | When it was created. | | `edited_at` | timestamp | When its text last changed. | | `trashed_at` | timestamp or null | When it was moved to the trash, or `null`. | ```json { "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`](/reference/webhooks#documentcreated). | Parameter | Type | Description | | --- | --- | --- | | `owner` | string, required | The Undertext id of the user who owns it. The user must exist. | | `name` | string | Up to 120 characters, once trimmed. Without one, the document is called by its first line. | | `reuse_untouched` | boolean | `true` 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. | | `except` | array | With `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](/reference/mcp). ```bash tab="curl" tab-group="lang" 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"}' ``` ```ts tab="Node" const doc = await undertext.documents.create({ owner: "usr_5Kq2Lm8R", name: "On the Analytical Engine", }); ``` Returns the [document](#the-document-object) with `201`, or a reused one with `200`. ```json { "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 } ``` | Error | When | | --- | --- | | `400 invalid_parameter` on `name` | Longer than 120 characters once trimmed. | | `400 invalid_parameter` on `markdown` | Starting text isn't supported yet. | | `404 user_not_found` | `owner` doesn't exist. Create the user first. | ## Retrieve a document `GET /v1/documents/{document_id}` | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const doc = await undertext.documents.retrieve("doc_8Hq2Lm4R"); ``` Returns the [document](#the-document-object), 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. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `name` | string or null | Up to 120 characters, once trimmed. `null` removes the name, so the document is called by its first line again. | | `link_access` | string | `restricted`, `view`, `suggest` or `edit`. See [Share documents](/guides/share-documents). | ```bash tab="curl" tab-group="lang" 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"}' ``` ```ts tab="Node" const doc = await undertext.documents.update("doc_8Hq2Lm4R", { link_access: "suggest", }); ``` Returns the updated [document](#the-document-object). | Error | When | | --- | --- | | `400 invalid_parameter` on `name` | Longer than 120 characters once trimmed. | | `400 invalid_parameter` on `link_access` | Not 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](/reference/api/users#list-a-users-documents). Undertext deletes it 30 days after it was trashed, as if you had called [Delete a document](#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. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user` | string | The Undertext id of the member trashing it. Leave it out to trash it as its first owner, for everyone. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/trash \ -X POST \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const doc = await undertext.documents.trash("doc_8Hq2Lm4R", { user: "usr_5Kq2Lm8R" }); ``` Returns the [document](#the-document-object). 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. ```json { "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. | Error | When | | --- | --- | | `403 not_member` | `user` 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. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user` | string | The Undertext id of the member restoring it. Leave it out to restore it as its first owner. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/restore \ -X POST \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const doc = await undertext.documents.restore("doc_8Hq2Lm4R"); ``` Returns the [document](#the-document-object), with `trash` when you passed `user`, as for [trashing](#move-a-document-to-the-trash). ## 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](#move-a-document-to-the-trash) instead. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.documents.delete("doc_8Hq2Lm4R"); ``` ```json { "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](/reference/embed#methods) for now. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `format` | string, required | `markdown`. Anything else is refused with `400 invalid_parameter`. | ```bash tab="curl" tab-group="lang" curl "https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/export?format=markdown" \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const markdown = await undertext.documents.export("doc_8Hq2Lm4R", { format: "markdown" }); ``` ```markdown # 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](/reference/api/seals) keeps the numbers it was sealed with. See [Provenance](/concepts/provenance) for what each part means. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/provenance \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const reading = await undertext.documents.provenance("doc_8Hq2Lm4R"); ``` ```json { "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 } ``` | Attribute | Type | Description | | --- | --- | --- | | `method` | string | The version of the method that produced these numbers. | | `composition` | object | Percentages 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](/reference/api/seals) rounds them to whole numbers. | | `by_actor` | array | Each 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](/reference/webhooks#the-actor) 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. | | `presence` | object | `share`: 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. | | `prompts` | integer | Rounds of back-and-forth with agents. | | `sittings` | integer | Separate stretches of work on the document. | | `duration` | string | Session 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_minutes` | integer | The same time in minutes; `0` when nothing was measured. | The editor's breakdown (the [`openBreakdown` method](/reference/embed#methods)) and each seal's page show who wrote what too. # Members > Decide who can open a document and with which role, and transfer ownership. Members are the users who can open a document, each with a role. Your sharing screens decide who gets in; these endpoints tell Undertext, which enforces the role in the editor and for each person's agents. People who aren't members can still open a document through its [link access](/reference/api/documents#update-a-document). See [Documents and access](/concepts/documents-and-access). | Role | Can | | --- | --- | | `owner` | Everything an editor can, and seal the document. A document has one or more owners, and always at least one. | | `editor` | Write, accept and reject suggestions, comment. Can turn on suggesting for themselves. | | `suggester` | Propose changes as suggestions and comment. Every edit they make is a suggestion. | | `viewer` | Read, and see comments. | A person's agents never get more than the person's own role, and never ownership. When you lower someone's role, their agents' access drops with it. ## The member object | Attribute | Type | Description | | --- | --- | --- | | `document` | string | The document's id. | | `user` | string | The member's Undertext id. | | `name` | string | The user's current name. | | `role` | string | `owner`, `editor`, `suggester` or `viewer`. | | `added_at` | timestamp | When they became a member. | ```json { "document": "doc_8Hq2Lm4R", "user": "usr_9Tb3Wc1X", "name": "Grace Hopper", "role": "suggester", "added_at": "2026-10-13T22:05:17Z" } ``` ## List members `GET /v1/documents/{document_id}/members` The document's members, owners first, then in the order they were added. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `limit` | integer | 1 to 100. Default 50. | | `after` | string | The `next` cursor from the previous page. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/members \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const page = await undertext.members.list("doc_8Hq2Lm4R"); ``` ```json { "data": [ { "document": "doc_8Hq2Lm4R", "user": "usr_5Kq2Lm8R", "name": "Ada Lovelace", "role": "owner", "added_at": "2026-10-13T21:12:40Z" }, { "document": "doc_8Hq2Lm4R", "user": "usr_9Tb3Wc1X", "name": "Grace Hopper", "role": "suggester", "added_at": "2026-10-13T22:05:17Z" } ], "next": null } ``` ## Add or change a member `PUT /v1/documents/{document_id}/members/{user_id}` Adds the user as a member with `role`, or changes their role if they're one already. The change reaches open editors at once: someone made a suggester mid-sentence carries on writing as suggestions. Setting `role` to `owner` makes them an owner too; the others stay owners. To hand a document over, make the new person an owner, then lower the old owner's role or remove them. A member added again comes out of their own trash. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user_id` | string, path, required | The user's Undertext id. The user must exist. | | `role` | string, required | `owner`, `editor`, `suggester` or `viewer`. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/members/usr_9Tb3Wc1X \ -X PUT \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"role": "suggester"}' ``` ```ts tab="Node" const member = await undertext.members.put("doc_8Hq2Lm4R", "usr_9Tb3Wc1X", { role: "suggester" }); ``` Returns the [member](#the-member-object): `201` when they were added, `200` when their role changed. ```json { "document": "doc_8Hq2Lm4R", "user": "usr_9Tb3Wc1X", "name": "Grace Hopper", "role": "suggester", "added_at": "2026-10-13T22:05:17Z" } ``` | Error | When | | --- | --- | | `404 user_not_found` | The user doesn't exist. Create them with [`PUT /v1/users/external/{external_id}`](/reference/api/users#create-or-update-a-user) first. | | `409 last_owner` | You tried to give the only owner a lower role. Make someone else an owner first. | | `409 document_trashed` | The document is in the trash. | ## Remove a member `DELETE /v1/documents/{document_id}/members/{user_id}` Takes away a member's access. Their open editors close, and their agents lose the document. What they wrote stays credited to them. People can still reach the document through link access afterwards if its `link_access` lets them in and you start a session for them with `via: "link"`. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user_id` | string, path, required | The user's Undertext id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/members/usr_9Tb3Wc1X \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.members.delete("doc_8Hq2Lm4R", "usr_9Tb3Wc1X"); ``` ```json { "document": "doc_8Hq2Lm4R", "user": "usr_9Tb3Wc1X", "removed": true } ``` | Error | When | | --- | --- | | `404 member_not_found` | The user isn't a member. | | `409 last_owner` | The user is the only owner. Make someone else an owner first, or [delete the document](/reference/api/documents#delete-a-document). | # Overview > How the Undertext REST API works, from authentication and errors to pagination, versions and rate limits. The Undertext REST API is how your server tells Undertext who your users are, which documents exist and who may open them, and how it reads back what happened: provenance, seals and agents. Browsers never call it. They get a short-lived [session token](/reference/api/sessions) from your server and talk to Undertext through the [embedded editor](/reference/embed). ## Base URL ``` https://api.undertext.sh/v1 ``` Every request goes over HTTPS. Plain HTTP requests are refused, not redirected. ## Authentication Send your secret key as a bearer token on every request: ```bash curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` In Node, the SDK sends it for you: ```ts import Undertext from "@undertext/sdk"; const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY); ``` Secret keys start with `sk_`. Make them, and revoke them, in the [console](https://undertext.sh/console). Each key also has an id (`key_…`) that is safe to log; seals record the id of the key that started each writing session, so a leaked key can be traced to the sessions it started. See [Platforms and keys](/concepts/platforms-and-keys). A secret key can start a session as any of your users. Keep it on your server, out of your client bundle and out of source control. A request without a key, or with an unknown or revoked one, gets `401` with an error of type `authentication`. ### One platform's data A key sees only its own platform's data. Use a platform of its own in development and CI, apart from the one your users get. ## Requests and responses - Request and response bodies are JSON (`Content-Type: application/json`), except [exports](/reference/api/documents#export-a-document). - Field names are `snake_case`. - Timestamps are ISO 8601 in UTC, such as `2026-10-30T18:20:00Z`. - Fields that have no value are present and `null`, not left out. - Every response carries an `Undertext-Request-Id` header. Include it when you contact us about a request. New fields can appear in any response at any time (see [Versioning](#versioning)), so read the fields you need and ignore the rest. ## IDs Everything Undertext creates has an id with a prefix that says what it is, users included. Your own id for a user is kept on the user as `external_id`, and appears only there: everywhere else, in requests, responses, events and seals, users are named by Undertext id. Store the Undertext id beside your user, or look it up with [`GET /v1/users/external/{external_id}`](/reference/api/users#retrieve-a-user-by-your-id). | Prefix | Object | | --- | --- | | `usr_` | [User](/reference/api/users) | | `doc_` | [Document](/reference/api/documents) | | `est_` | [Session](/reference/api/sessions) token | | `agt_` | [Agent](/reference/api/agents) | | `areq_` | [Agent request](/reference/api/agent-requests) | | `we_` | [Webhook endpoint](/reference/api/webhook-endpoints) | | `whsec_` | Webhook signing secret | | `evt_` | [Webhook event](/reference/webhooks) | | `key_` | Secret key id | Seals are identified by their code: nine capital letters and digits, such as `66G4LF343`. Ids are opaque: don't parse them or rely on their length. ## Errors Undertext uses HTTP status codes, and every error response has the same body: ```json { "error": { "type": "invalid_request", "code": "invalid_parameter", "param": "role", "message": "role must be one of owner, editor, suggester, viewer." } } ``` `type` tells you what kind of problem it is, `code` names the specific one, `param` names the field at fault when there is one, and `message` is for people reading logs, not for your code to match on. | Type | Status | Meaning | | --- | --- | --- | | `invalid_request` | 400 | The request is malformed or a parameter is missing or wrong. | | `authentication` | 401 | No key, or the key is unknown or revoked. | | `permission` | 403 | The key is fine, but the action isn't allowed, such as a session for someone without access. | | `not_found` | 404 | The object doesn't exist on this platform. | | `conflict` | 409 | The object's state doesn't allow it, such as sealing a document in the trash. | | `rate_limited` | 429 | Too many requests. Wait for `Retry-After` seconds. Reserved: the API doesn't limit requests yet. | | `server` | 500 | Something went wrong on our side. Retry. | Codes you'll see most often: | Code | Type | When | | --- | --- | --- | | `missing_parameter` | `invalid_request` | A required field is absent. | | `invalid_parameter` | `invalid_request` | A field has the wrong type or value. | | `invalid_body` | `invalid_request` | The body isn't a JSON object. | | `missing_key` | `authentication` | No `Authorization` header. | | `invalid_key` | `authentication` | The key isn't one of yours, or has been revoked. | | `no_access` | `permission` | The user can't open the document. | | `not_owner` | `permission` | Only the document's owners can do this. | | `user_not_found` | `not_found` | No user with that id. Create it with `PUT /v1/users/external/{external_id}`. | | `document_not_found` | `not_found` | No document with that id, or it was deleted. | | `document_trashed` | `conflict` | The document is in the trash. Restore it first. | Each resource page lists the codes specific to its endpoints. ## Pagination Endpoints that list things return a page: ```json { "data": [ ... ], "next": "c_2Fh8Kq" } ``` Pass `limit` (1 to 100, default 50) to choose the page size and `after` with the previous page's `next` to get the following page. `next` is `null` on the last page. Each endpoint says what order its list is in. ```bash curl "https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/documents?limit=20&after=c_2Fh8Kq" \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` In Node, `await` a list method for one page, or loop over it with `for await` and the SDK follows `next` for you: ```ts for await (const doc of undertext.users.listDocuments("usr_5Kq2Lm8R")) { console.log(doc.title); } ``` ## Idempotency Undertext doesn't take idempotency keys yet, and the Node SDK doesn't retry a `POST` that failed. Retry one that failed without an answer only where doing it twice is harmless, such as starting a session, or sealing: a document that reads exactly as its newest seal returns that seal. `PUT` and `DELETE` are idempotent already. ## Versioning The version is in the path: `/v1`. Within `/v1`, changes are only additive, but for the one break of the move to Undertext (see the [changelog](/changelog)): - new endpoints, and new optional parameters on existing ones - new fields in responses - new error codes and new webhook event types - new values for fields that are documented as open-ended, such as a seal's `method` Anything that would break working code ships as `/v2`, and `/v1` keeps working for at least 12 months after `/v2` is released. The embed script follows the same rule: `v1.js` changes only in compatible ways. The [changelog](/changelog) lists every change. ## Rate limits The API doesn't limit requests yet. When it does, a request over the limit will get `429 rate_limited` with a `Retry-After` header saying how many seconds to wait, which the [Node SDK](/reference/node) already honours, retrying twice by default. Writing in the editor isn't rate limited per request: people's edits always go first, and each agent request gets a short slice of work at a time per document, so a burst of agent edits never holds up someone's typing. ## Resources | Resource | What it's for | | --- | --- | | [Users](/reference/api/users) | Tell Undertext who your users are, merge and delete them, and set their check-ins. | | [Documents](/reference/api/documents) | Create documents, set link access, move them to the trash, export them and read their provenance. | | [Members](/reference/api/members) | Decide who can open a document and with which role. | | [Sessions](/reference/api/sessions) | Start the short-lived tokens the embedded editor runs on. | | [Agents](/reference/api/agents) | List, limit and revoke the agents your users connected. | | [Agent requests](/reference/api/agent-requests) | Approve or deny an agent from your consent page. | | [Seals](/reference/api/seals) | Seal documents, look seals up, and withdraw them. | | [Webhook endpoints](/reference/api/webhook-endpoints) | Choose where Undertext sends events. | | [Platform](/reference/api/platform) | Your consent, document and seal URLs, embed origins, and your own agent tools. | # Platform > Your platform's settings, the agent tools of your own that Undertext's MCP server offers, and its counts. Your platform's settings say where Undertext sends people and calls: the page where they approve agents, where your documents and seals are, which origins may frame the editor, and the tools of your own that agents get beside Undertext's. You can set them here, or all but your tools in the [console](https://undertext.sh/console); a server that sets them on starting keeps them in step with where it runs. ## The platform object | Attribute | Type | Description | | --- | --- | --- | | `id` | string | Your platform's id. | | `slug` | string | Its short name, in your MCP address. | | `name` | string | What Undertext calls your platform: on consent and seal pages, and to agents. | | `icon_url` | string or null | Your icon, which MCP clients may show beside your server: Undertext's MCP server names it in `serverInfo.icons` when an agent connects. | | `embed_origins` | array | The origins that may frame the editor and presence settings. See [Embed origins](/reference/embed#embed-origins). | | `consent_url` | string or null | Where Undertext sends people to approve an agent, with `?request=areq_…`. See [Agent requests](/reference/api/agent-requests). Without one, agents can't connect. | | `document_url` | string or null | Where your product shows a document, with `{document}` for its id. Links between documents in the editor, and agents' answers, use it. | | `seal_url` | string or null | Where your product shows a seal, with `{code}` for its code. Seals' `url` and seal lines name it. Without one, they name the seal's page on `seal.undertext.sh`. See [Seals](/concepts/seals). | | `mcp_url` | string | Your MCP address, for your users' agents. | | `domain` | string or null | Your domain, such as `acme.com`. Seal pages show it beside your name once it's verified, and say "Unverified" until then. See [Verify your domain](#verify-your-domain). | | `domain_verified` | boolean | Whether Undertext found your domain's record, at its last look. | | `domain_record` | object or null | The DNS record that proves `domain` is yours: `type` (`TXT`), `name` and `value`. | | `checkins_required` | boolean | Whether [Verified Presence](/concepts/presence-and-check-ins#check-ins) is required: everyone writing in your documents is asked to check in, and no one can turn it off. `false` unless you set it. | | `checkin_minutes` | integer | About how often your people are asked to check in while they write where Verified Presence is on: `1`, `5`, `10` or `30`. `5` unless you set it. Your default, for anyone who hasn't chosen one of `checkin_choices`. | | `checkin_choices` | array | The intervals your people may choose from in presence settings, `checkin_minutes` among them, sorted. Empty, as unless you set it, everyone is asked at `checkin_minutes`. | ```json { "id": "plt_6Hq2Lm4R", "slug": "acme", "name": "Acme Notes", "icon_url": "https://acme.com/icon.png", "embed_origins": ["https://acme.com"], "consent_url": "https://acme.com/undertext/connect", "document_url": "https://acme.com/docs/{document}", "seal_url": "https://acme.com/seals/{code}", "mcp_url": "https://mcp.undertext.sh/acme", "domain": "acme.com", "domain_verified": true, "domain_record": { "type": "TXT", "name": "_undertext.acme.com", "value": "undertext-verification=Hq2Lm4R8Tb3Wc1X9Kp5Nz7Vd" }, "checkins_required": false, "checkin_minutes": 5, "checkin_choices": [5, 10, 30] } ``` ## Retrieve the platform `GET /v1/platform` ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/platform \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const platform = await undertext.platform.retrieve(); ``` ## Update the platform `PATCH /v1/platform` Only the fields you send change. `null` removes a URL. | Parameter | Type | Description | | --- | --- | --- | | `name` | string | Your platform's name. | | `icon_url` | string or null | A URL of your icon, for MCP clients to show. | | `embed_origins` | array | Origins, such as `https://acme.com`; each is kept as its origin alone. `https`, except `http` on `localhost` and `127.0.0.1`. | | `consent_url` | string or null | | | `document_url` | string or null | With `{document}` where the id goes. | | `seal_url` | string or null | With `{code}` where the code goes. `https`, except `http` on `localhost` and `127.0.0.1`. | | `domain` | string or null | A domain name, such as `acme.com`. A new one gets a new record and is unverified until it's found. | | `checkins_required` | boolean | `true` to require Verified Presence of everyone writing in your documents, even those without a key yet, whom the editor asks to add one. | | `checkin_minutes` | integer | `1`, `5`, `10` or `30`. Shorter asks more often, and each check-in vouches for less writing: about one and a half intervals. A seal's breakdown says how often its check-ins came. | | `checkin_choices` | array | Intervals your people may choose from, each `1`, `5`, `10` or `30`; `checkin_minutes` is added if it's missing. `[]` for no choice. Someone whose choice you stop offering is asked at `checkin_minutes`, and at their choice again if you offer it again. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/platform \ -X PATCH \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"consent_url": "https://acme.com/undertext/connect", "document_url": "https://acme.com/docs/{document}"}' ``` ```ts tab="Node" const platform = await undertext.platform.update({ consent_url: "https://acme.com/undertext/connect", document_url: "https://acme.com/docs/{document}", }); ``` Returns the [platform](#the-platform-object). | Error | When | | --- | --- | | `400 invalid_parameter` | A URL that isn't one, `embed_origins` that aren't `https` origins (or `http` on `localhost`), a `seal_url` without `{code}`, a `domain` that isn't a domain name, `checkins_required` that isn't `true` or `false`, `checkin_minutes` that isn't one of `1`, `5`, `10` or `30`, or `checkin_choices` that isn't a list of them. | ## Verify your domain `POST /v1/platform/verify-domain` Add `domain_record` to your domain's DNS, as a TXT record. Undertext looks for it each day, so a domain is verified within a day of the record appearing, and stops being verified once it's gone; keep the record for as long as you use the domain. This looks now instead. Returns the [platform](#the-platform-object), with `domain_verified` as found. | Error | When | | --- | --- | | `409 no_domain` | The platform has no domain. | ## Set your agent tools `PUT /v1/platform/tools` Gives your users' agents tools of your own, for what your product keeps itself, such as folders and pins. Undertext's MCP server lists them beside its own, and forwards each call to `url`, signed with `secret`. Each call replaces the tools you set before. See [Add your own agent tools](/guides/your-own-agent-tools). | Parameter | Type | Description | | --- | --- | --- | | `url` | string, required | Where Undertext posts tool calls. | | `secret` | string, required | At least 32 characters, which Undertext signs each call with. Choose it yourself and keep it. | | `tools` | array, required | Each `{ name, title?, description, inputSchema }`, as MCP describes a tool. Names are lowercase letters, digits and underscores, and can't be one of Undertext's own. Agents are shown each schema without `additionalProperties` or an empty `properties`, which Gemini can't read. | | `instructions` | string | What agents are told of your tools, after Undertext's own instructions. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/platform/tools \ -X PUT \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://acme.com/undertext/tools", "secret": "'"$ACME_TOOLS_SECRET"'", "instructions": "Folders are the person'\''s own: list_folders shows them, move_document files a document in one.", "tools": [ { "name": "list_folders", "description": "The person'\''s folders, in their order.", "inputSchema": { "type": "object", "properties": {} } } ] }' ``` ```ts tab="Node" await undertext.platform.setTools({ url: "https://acme.com/undertext/tools", secret: process.env.ACME_TOOLS_SECRET!, instructions: "Folders are the person's own: list_folders shows them, move_document files a document in one.", tools: [{ name: "list_folders", description: "The person's folders, in their order.", inputSchema: { type: "object", properties: {} } }], }); ``` ```json { "url": "https://acme.com/undertext/tools", "tools": ["list_folders"] } ``` | Error | When | | --- | --- | | `400 invalid_parameter` on `url` | Not a URL. | | `400 invalid_parameter` on `secret` | Shorter than 32 characters. | | `400 invalid_parameter` on `tools` | A tool lacks a name, description or input schema, or its name is one of Undertext's. | ## Retrieve counts `GET /v1/platform/stats` Counts for your own operations page: all time, and the last 7 days. ```json { "data": [ { "label": "Documents", "total": 1204, "week": 87 }, { "label": "Sealed documents", "total": 312, "week": 19 }, { "label": "Agents", "total": 96, "week": 8 } ] } ``` # Seals > Seal a document, list and look up its seals, and withdraw one. A seal is a snapshot of a document as it stood, with the record of how it was written and the numbers that come from it: where its words came from, when someone was active in the editor, how many prompts and sittings it took. Each seal has a short page at `seal.undertext.sh` that anyone with the link can open, unless its owners [made its seals private](#who-reads-seals), and a seal line people paste wherever the text goes. A seal never changes once it's made; sealing again adds a new version. See [Seals](/concepts/seals). People can also seal from the Seal button in the editor. Either way, Undertext sends `seal.created` to your [webhook endpoints](/reference/webhooks). ## The seal object | Attribute | Type | Description | | --- | --- | --- | | `code` | string | Nine capital letters and digits. | | `url` | string | The seal's page: your [`seal_url`](/reference/api/platform) with the code in it, or, without one, `https://seal.undertext.sh/` and the code. The seal line begins with it. | | `version` | integer | 1 for the document's first seal, then 2, 3 and so on. | | `sealed_at` | timestamp | When it was sealed. | | `sealed_by` | string | The Undertext id of the person who sealed it. | | `document` | string or null | The document's id, or `null` once the document was deleted. | | `method` | string or null | The version of the method its numbers were worked out with. They never change; under a newer method, the seal page shows a labeled reassessment beside them. This and the numbers below are `null` once the seal is withdrawn. | | `line` | string or null | The seal line, ready to paste. | | `composition` | object | Percentages of the document by where its words came from, summing to 100: `typed`, `shaped`, `ai` and `external`. | | `presence` | object | `share`: percent of session time with a person present. `verified_share`: the part vouched for by check-ins. `verified`: `true` when every sitting people wrote in was verified. | | `prompts` | integer | Rounds of back-and-forth with agents. | | `sittings` | integer | Separate stretches of work. The seal line calls them sessions. | | `duration` | string | Session time across those sittings, as the seal line writes it, such as `11hr2min`. | | `attested_by` | object | Who vouches for the people named in it. `platform`: your platform's slug. `key_ids`: the ids of the secret keys that started its writing sessions. | | `withdrawn_at` | timestamp or null | When it was withdrawn, or `null`. | | `preview` | object or null | For your seal page's link-preview tags (`og:title`, `og:description`, `og:image`): `title`, `description`, and `image_url`, a 1200×630 picture of the seal with its title and address. `null` unless anyone may read it: a private or withdrawn seal, or one whose document is in the trash, says nothing of itself. | ```json { "code": "66G4LF343", "url": "https://seal.undertext.sh/66G4LF343", "document": "doc_8Hq2Lm4R", "version": 1, "sealed_at": "2026-10-30T16:31:04Z", "sealed_by": "usr_5Kq2Lm8R", "method": "v0.2", "line": "seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified)", "composition": { "typed": 86, "shaped": 10, "ai": 2, "external": 2 }, "presence": { "share": 99, "verified_share": 98, "verified": false }, "prompts": 101, "sittings": 9, "duration": "11hr2min", "attested_by": { "platform": "acme", "key_ids": ["key_2Lq9Wd4T"] }, "withdrawn_at": null, "preview": { "title": "On the Analytical Engine", "description": "96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified). Sealed with Undertext, written in Acme Notes (acme.com, verified).", "image_url": "https://seal.undertext.sh/api/seals/66G4LF343/preview.png" } } ``` When every sitting people wrote in was verified by check-ins, the line ends `(verified)`; when some were, it ends with the share, such as `(98% verified)`. ## Seal a document `POST /v1/documents/{document_id}/seals` Seals the document as it stands now, as a new version. A document with pending suggestions can't be sealed: a seal says what the document says, so they're accepted or rejected first. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user` | string, required | The Undertext id of the person sealing it. They must be one of the document's owners. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/seals \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"user": "usr_5Kq2Lm8R"}' ``` ```ts tab="Node" const seal = await undertext.seals.create("doc_8Hq2Lm4R", { user: "usr_5Kq2Lm8R" }); console.log(seal.line); ``` Returns the [seal](#the-seal-object) with `201`. If the document reads exactly as its newest seal still up, it returns that seal with `200` instead, makes no new version and sends no `seal.created`, so a form submitted twice doesn't seal twice. | Error | When | | --- | --- | | `403 not_owner` | `user` isn't one of the document's owners. | | `409 document_empty` | Nothing has been written in the document. | | `409 document_trashed` | The document is in the trash. | | `409 open_suggestions` | The document has pending suggestions. | ## List a document's seals `GET /v1/documents/{document_id}/seals` Every seal made from a document, newest first, withdrawn ones included. | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `limit` | integer | 1 to 100. Default 50. | | `after` | string | The `next` cursor from the previous page. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/seals \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const page = await undertext.seals.list("doc_8Hq2Lm4R"); ``` ```json { "data": [ { "code": "66G4LF343", "url": "https://seal.undertext.sh/66G4LF343", "document": "doc_8Hq2Lm4R", "version": 1, "sealed_at": "2026-10-30T16:31:04Z", "sealed_by": "usr_5Kq2Lm8R", "method": "v0.2", "line": "seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified)", "composition": { "typed": 86, "shaped": 10, "ai": 2, "external": 2 }, "presence": { "share": 99, "verified_share": 98, "verified": false }, "prompts": 101, "sittings": 9, "duration": "11hr2min", "attested_by": { "platform": "acme", "key_ids": ["key_2Lq9Wd4T"] }, "withdrawn_at": null, "preview": { "title": "On the Analytical Engine", "description": "96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified). Sealed with Undertext, written in Acme Notes (acme.com, verified).", "image_url": "https://seal.undertext.sh/api/seals/66G4LF343/preview.png" } } ], "next": null } ``` ## Retrieve a seal `GET /v1/seals/{code}` Looks a seal up by its code, such as one a reader pasted into your product. You can only retrieve seals made on your platform; anyone can open a public seal's page at `seal.undertext.sh`. | Parameter | Type | Description | | --- | --- | --- | | `code` | string, path, required | The seal's code. Case doesn't matter. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/seals/66G4LF343 \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const seal = await undertext.seals.retrieve("66G4LF343"); ``` Returns the [seal](#the-seal-object), or `404 seal_not_found`. ## Withdraw a seal `DELETE /v1/seals/{code}` Takes a seal down. Its page then says it was withdrawn, and when, instead of showing the text. A withdrawn seal can't be brought back, and other versions of the same document stay up. Seals can be withdrawn but never changed. | Parameter | Type | Description | | --- | --- | --- | | `code` | string, path, required | The seal's code. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/seals/66G4LF343 \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const seal = await undertext.seals.withdraw("66G4LF343"); ``` Returns the [seal](#the-seal-object) with `withdrawn_at` set, and Undertext sends `seal.withdrawn`. Withdrawing a seal that's already withdrawn returns it unchanged. While a document is in its owners' trash, its seals are down: their pages show nothing until it's restored. ## Who reads seals A document's owners choose who reads its seals, every version alike, in the editor's seal dialog (the [`openSeal` method](/reference/embed#methods) opens it): - **Anyone with the link**, the default. Only these seals have a link preview. - **Private**: whoever can open the document, which is its members and, while its link lets anyone in, anyone with a seal session; readers its owners list by email, or `*@domain` for everyone at a domain; and, if they set one, whoever has its password. A private seal's page asks the reader for its password, or, on your seal page, for a [seal session](/reference/api/sessions#for-seals) your server starts for the person signed in with you, saying which email you've verified for them. A session opens the seal for its document's members, for anyone while the document's link lets people in, and for the readers its owners listed. A private seal's page on `seal.undertext.sh` offers the password, and sends readers to sign in on your seal page if you've set a [`seal_url`](/reference/api/platform). On your seal page, someone signed in whose email you vouched for, and whom it doesn't let in, can ask its owners to let them read it. The owners answer in the seal dialog: letting them in adds their email to the readers. See the [`seal_request` events](/reference/webhooks#seal_requestcreated). # Sessions > Start the short-lived tokens the embedded editor, presence settings and private seals run on. A session is a short-lived token that lets one of your users into one document in the [embedded editor](/reference/embed), into presence settings, or into the private seals they may read. Your server starts it with your secret key and hands the token to your page; the page passes it to Undertext and never sees your key. Tokens last 15 minutes, and the embed asks your `getToken` function for a new one before the old one runs out, so an open editor keeps working for as long as the person is allowed in. A seal reads with its token once, and asks for no more. See [Embed the editor](/guides/embed-the-editor). A session token only opens what its `purpose` says: the editor, presence settings or seals. It can't call the REST API. ## The session object | Attribute | Type | Description | | --- | --- | --- | | `token` | string | The token to pass to the page, starting `est_`. | | `user` | string | The user's Undertext id. | | `document` | string or null | The document it opens, or `null` for a presence session. | | `purpose` | string | `editor`, `presence` or `seal`. | | `role` | string or null | The role the user has in the document for this session: `owner`, `editor`, `suggester` or `viewer`. `null` for a presence or seal session. | | `via` | string or null | `member` when the role comes from membership, `link` when it comes from the document's link access. `null` for a presence or seal session. | | `expires_at` | timestamp | When the token stops being accepted, 15 minutes after it was started. | ```json { "token": "est_q7Lr2VkX9pN4sT8wY3mB6cZ1", "user": "usr_5Kq2Lm8R", "document": "doc_8Hq2Lm4R", "purpose": "editor", "role": "owner", "via": "member", "expires_at": "2026-10-30T18:35:00Z" } ``` ## Create a session `POST /v1/sessions` Starts a session for the editor, for presence settings when you pass `purpose: "presence"`, or for reading seals when you pass `purpose: "seal"`. | Parameter | Type | Description | | --- | --- | --- | | `user` | string, required | The user's Undertext id. The user must exist. | | `document` | string | The document to open. Required when `purpose` is `editor`. | | `via` | string | `link` to let in someone who isn't a member, with the document's link access as their role. Leave it out for members. | | `purpose` | string | `editor` (the default), `presence` or `seal`. | | `email` | string or null | For a seal session: the person's email, only if you've verified it. A private seal's readers are listed by email. | | `group` | string | Up to 200 characters of yours that the session belongs to, such as the id of the person's own sign-in session with you, so you can [end them together](#end-a-users-sessions). | ### For the editor Undertext works out the user's role when it starts the session: their member role, or with `via: "link"`, the document's `link_access`. A member who comes by link keeps whichever role is higher. The role is checked again on every edit, so lowering it or removing the member takes effect in an open editor at once, whatever the token says. ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/sessions \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"user": "usr_5Kq2Lm8R", "document": "doc_8Hq2Lm4R"}' ``` ```ts tab="Node" const session = await undertext.sessions.create({ user: "usr_5Kq2Lm8R", document: "doc_8Hq2Lm4R", }); ``` ```json { "token": "est_q7Lr2VkX9pN4sT8wY3mB6cZ1", "user": "usr_5Kq2Lm8R", "document": "doc_8Hq2Lm4R", "purpose": "editor", "role": "owner", "via": "member", "expires_at": "2026-10-30T18:35:00Z" } ``` For someone who followed a shared link: ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/sessions \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"user": "usr_9Tb3Wc1X", "document": "doc_8Hq2Lm4R", "via": "link"}' ``` ```ts tab="Node" const session = await undertext.sessions.create({ user: "usr_9Tb3Wc1X", document: "doc_8Hq2Lm4R", via: "link", }); ``` ```json { "token": "est_d2Hs9QmW4kR7xV1nJ6pL8tF3", "user": "usr_9Tb3Wc1X", "document": "doc_8Hq2Lm4R", "purpose": "editor", "role": "suggester", "via": "link", "expires_at": "2026-10-30T18:35:00Z" } ``` A document in the trash still opens, only to read: for its owners when it's in the trash for everyone, and for a member who put it in their own. The session's `role` is then `viewer`. People who come by link aren't added as members. Their writing is credited to them like anyone else's, and they appear in the document's mention list while they have it open. ### For presence settings A presence session opens the window where a user adds security keys. It isn't tied to a document. Pass its token to `mountPresenceSettings` or `openPresenceSettings` in the [embed API](/reference/embed#presence-settings). See [Set up check-ins](/guides/set-up-check-ins). ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/sessions \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"user": "usr_5Kq2Lm8R", "purpose": "presence"}' ``` ```ts tab="Node" const session = await undertext.sessions.create({ user: "usr_5Kq2Lm8R", purpose: "presence", }); ``` ```json { "token": "est_m5Tc8Wq1Zr6Kv3Np9Ys2Bx7H", "user": "usr_5Kq2Lm8R", "document": null, "purpose": "presence", "role": null, "via": null, "expires_at": "2026-10-30T18:35:00Z" } ``` ### For seals A seal session lets a person read the private seals shared with them, on your seal page. It isn't tied to a seal or a document: Undertext lets them read a private seal if they're one of its document's members, if the document's link lets anyone open it, or if the `email` you vouch for is one its owners listed, by itself or as `*@` and its domain. Pass only an email you've verified, as anyone who has it reads what's shared with it. Public seals need no session. ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/sessions \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"user": "usr_9Tb3Wc1X", "purpose": "seal", "email": "grace@acme.com"}' ``` ```ts tab="Node" const session = await undertext.sessions.create({ user: "usr_9Tb3Wc1X", purpose: "seal", email: "grace@acme.com", }); ``` ```json { "token": "est_r4Wd7Kp2Nx9Lq5Tz1Hm8Bc6V", "user": "usr_9Tb3Wc1X", "document": null, "purpose": "seal", "role": null, "via": null, "expires_at": "2026-10-30T18:35:00Z" } ``` ### Errors | Error | When | | --- | --- | | `400 missing_parameter` on `document` | `purpose` is `editor` and there's no `document`. | | `400 invalid_parameter` on `group` | Empty, or longer than 200 characters. | | `400 invalid_parameter` on `email` | Not an email address. | | `403 no_access` | The user isn't a member, and either you didn't pass `via: "link"` or the document's link access is `restricted`. | | `404 user_not_found` | The user doesn't exist. | | `404 document_not_found` | The document doesn't exist. | | `409 document_trashed` | The document is in its owners' trash, and the user isn't one of its owners. | ## End a user's sessions `DELETE /v1/users/{user_id}/sessions` Ends a user's sessions at once: all of them, or with `group`, only those started in that group. Call it when someone signs out of your product, or is signed out everywhere. Their open editors lose their connection within moments and ask your page for a new token, which your server refuses once they're signed out. | Parameter | Type | Description | | --- | --- | --- | | `user_id` | string, path, required | The user's Undertext id. | | `group` | string, query | Only the sessions started with this `group`. | ```bash tab="curl" tab-group="lang" curl "https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/sessions?group=sess_42" \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.users.endSessions("usr_5Kq2Lm8R", { group: "sess_42" }); ``` ```json { "deleted": 2 } ``` A session token lets whoever holds it write as that user until it expires. Send it only to the person it's for, over HTTPS, and don't log it. Start sessions only after your own sign-in has checked who is asking. # Users > Create users under your own ids, look them up, merge and delete them, list their documents, and set Verified Presence for them. A user is one of your people. Undertext gives each user its own id, `usr_…`, and keeps your id for them beside it as `external_id`. Every other endpoint, event and seal names users by Undertext id. Undertext has no accounts and no sign-in: you create a user with a name, and from then on Undertext credits what that user writes in the editor to that name. See [Users](/concepts/users) for how the two ids, names, pictures and deletion work. ## The user object | Attribute | Type | Description | | --- | --- | --- | | `id` | string | Undertext's id for this user, `usr_` and 8 characters. It never changes. | | `external_id` | string | Your id for this user, 1 to 128 characters, unique on your platform. | | `name` | string | The name Undertext shows on their writing, comments, cursors and seals. Up to 48 characters. | | `avatar_url` | string or null | Undertext's copy of their picture, or `null` for initials. | | `detail` | string or null | A second line shown under their name where people pick someone to mention, such as an email address or a team. | | `created_at` | timestamp | When you first created the user. | ```json { "id": "usr_5Kq2Lm8R", "external_id": "u_42", "name": "Ada Lovelace", "avatar_url": "https://api.undertext.sh/v1/avatars/av_9Rk3Tq", "detail": "ada@acme.com", "created_at": "2026-10-12T09:14:03Z" } ``` ## Create or update a user `PUT /v1/users/external/{external_id}` Creates a user for your id if there isn't one, and replaces their name, picture and detail if there is. Call it when someone signs up, and again whenever their profile changes in your product. Keep the `id` it returns beside your user. A new name shows everywhere at once, in every document and open editor, because documents name people by Undertext id. Seals already made keep the name they were sealed with. | Parameter | Type | Description | | --- | --- | --- | | `external_id` | string, path, required | Your id for this user. URL-encode it. | | `name` | string, required | Up to 48 characters, without control or invisible characters. | | `avatar_url` | string | An `https` URL of a PNG, JPEG or WebP picture of at most 1 MB, on a public address. Undertext fetches it once and keeps its own copy; send the same URL again and it isn't fetched again. `null` removes the picture. Leave it out to keep the current one. | | `detail` | string | Up to 128 characters. `null` removes it. Leave it out to keep the current one. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/external/u_42 \ -X PUT \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Ada Lovelace", "avatar_url": "https://acme.com/avatars/42.png", "detail": "ada@acme.com" }' ``` ```ts tab="Node" const user = await undertext.users.upsert("u_42", { name: "Ada Lovelace", avatar_url: "https://acme.com/avatars/42.png", detail: "ada@acme.com", }); await db.users.update("u_42", { undertext_user_id: user.id }); ``` Returns the user: `201` when it was created, `200` when it was updated. ```json { "id": "usr_5Kq2Lm8R", "external_id": "u_42", "name": "Ada Lovelace", "avatar_url": "https://api.undertext.sh/v1/avatars/av_9Rk3Tq", "detail": "ada@acme.com", "created_at": "2026-10-12T09:14:03Z" } ``` | Error | When | | --- | --- | | `400 invalid_parameter` on `name` | The name is empty, longer than 48 characters, or has control or invisible characters. | | `400 invalid_parameter` on `external_id` | Empty, or longer than 128 characters. | | `400 avatar_unreadable` | Undertext couldn't fetch the picture, or it isn't a PNG, JPEG or WebP of at most 1 MB. | ## Retrieve a user `GET /v1/users/{id}` | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user's Undertext id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const user = await undertext.users.retrieve("usr_5Kq2Lm8R"); ``` Returns the [user](#the-user-object), or `404 user_not_found`. ## Retrieve a user by your id `GET /v1/users/external/{external_id}` For when you have only your own id, for example before you've stored the Undertext id. | Parameter | Type | Description | | --- | --- | --- | | `external_id` | string, path, required | Your id for this user. URL-encode it. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/external/u_42 \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const user = await undertext.users.retrieveByExternalId("u_42"); ``` Returns the [user](#the-user-object), or `404 user_not_found`. ## Update a user `PATCH /v1/users/{id}` Changes any of a user's fields by Undertext id, including `external_id`: use it when your ids change, in a migration or when someone switches login method. Documents, seals and agents follow the Undertext id, so nothing else moves. | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user's Undertext id. | | `external_id` | string | A new id of yours for this user. It must not belong to another user. | | `name` | string | As in [Create or update a user](#create-or-update-a-user). | | `avatar_url` | string or null | As above. | | `detail` | string or null | As above. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R \ -X PATCH \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"external_id": "2f6c1e0a-7b1d-4c55-9e0f-3a8d2b6c9e41"}' ``` ```ts tab="Node" await undertext.users.update("usr_5Kq2Lm8R", { external_id: "2f6c1e0a-7b1d-4c55-9e0f-3a8d2b6c9e41" }); ``` Returns the [user](#the-user-object). | Error | When | | --- | --- | | `409 external_id_taken` | Another user already has that `external_id`. Merge the two first if they're the same person. | | `404 user_not_found` | No user with that id. | ## Delete a user `DELETE /v1/users/{id}` Removes the user from Undertext. Call it when someone deletes their account in your product. Their `external_id` is free again afterwards; using it again creates a new person. - Documents they wrote in keep the last name they had, without their picture, so the record of who wrote what stays readable. - Documents they owned pass to their other members: those with the highest role become owners. A document with no other member passes to someone else who wrote in it, if anyone did, and is otherwise deleted, with its seals. One in the trash with no owner left is deleted. - Their agents are revoked, and their open editors close. - Their security keys and check-in history are deleted. | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user's Undertext id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.users.delete("usr_5Kq2Lm8R"); ``` ```json { "id": "usr_5Kq2Lm8R", "deleted": true } ``` A document that still has other members isn't deleted when its owner is. Make someone an owner first with [`PUT /v1/documents/{document_id}/members/{user_id}`](/reference/api/members#add-or-change-a-member) if you want a particular person to own it; otherwise every member with the highest role becomes an owner. ## Merge users `POST /v1/users/{id}/merge` Moves everything from one user to another, then deletes the first. Use it when someone who started without an account signs up or signs in, so their work comes with them. See [Anonymous users](/guides/anonymous-users). What moves: - their documents and memberships (where both users were members, the higher role is kept), and documents in their own trash - the credit for everything they and their agents wrote, typed, shaped or accepted, in every document - their security keys (after `into`'s own), their check-ins, their presence signals, and the documents they turned Verified Presence on in - their agents. An agent for a client `into` already has an agent for joins that one, keeping the higher role in each document and its tokens, so it needn't be approved again. Open editors of the user merged from lose their sessions: start new ones as `into`. | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user to merge from. It's deleted afterwards. | | `into` | string, required | The Undertext id of the user to merge into. It must exist. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_2Hd7Np4Q/merge \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"into": "usr_5Kq2Lm8R"}' ``` ```ts tab="Node" const user = await undertext.users.merge("usr_2Hd7Np4Q", { into: "usr_5Kq2Lm8R" }); ``` Returns the user merged into. ```json { "id": "usr_5Kq2Lm8R", "external_id": "u_42", "name": "Ada Lovelace", "avatar_url": null, "detail": "ada@acme.com", "created_at": "2026-10-30T18:20:00Z" } ``` | Error | When | | --- | --- | | `400 invalid_parameter` on `into` | `into` is the same user. | | `404 user_not_found` | Either user doesn't exist. | ## List a user's documents `GET /v1/users/{id}/documents` The documents a user is a member of, most recently edited or shared with them first, leaving out those in the trash. Use it to build your document list; keep your own folders and pins beside it, keyed by document id. | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user's Undertext id. | | `ids` | string | Comma-separated document ids: only those of them the user may open now, as a member or by link access. For titles and access of documents you keep elsewhere, such as in a notification list. | | `trashed` | boolean | `true` lists what's in their trash instead, most recently trashed first: documents an owner trashed for everyone, where they're an owner, and documents they put in their own. Default `false`. | | `limit` | integer | 1 to 100. Default 50. | | `after` | string | The `next` cursor from the previous page. | ```bash tab="curl" tab-group="lang" curl "https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/documents?limit=2" \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const page = await undertext.users.listDocuments("usr_5Kq2Lm8R", { limit: 2 }); ``` Each item is a [document](/reference/api/documents#the-document-object) with two more fields: `role`, this user's role in it (the higher of their member role and the link's), and `added_at`, when they became a member, or `null` for one they reach by link. With `trashed=true`, each has instead `everyone`, `true` when it's in the trash for everyone and `false` when only in theirs, and `in_trash_since`. ```json { "data": [ { "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, "role": "owner", "added_at": "2026-10-13T21:12:40Z" }, { "id": "doc_3Wp7Zc1V", "name": null, "title": "Notes for Thursday", "owners": ["usr_9Tb3Wc1X"], "link_access": "suggest", "created_at": "2026-10-11T15:02:11Z", "edited_at": "2026-10-12T08:47:30Z", "trashed_at": null, "role": "suggester", "added_at": "2026-10-11T15:40:02Z" } ], "next": "c_2Fh8Kq" } ``` ## Empty a user's trash `DELETE /v1/users/{id}/trash` `DELETE /v1/users/{id}/trash/{document_id}` Deletes for good everything in a user's trash, or one document there. A document in the trash for everyone, where they're an owner, is [deleted](/reference/api/documents#delete-a-document) for everyone; one in their own trash they leave, as a member, and it stays for the others. | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user's Undertext id. | | `document_id` | string, path | One document in their trash. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/trash \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.users.emptyTrash("usr_5Kq2Lm8R"); await undertext.users.deleteFromTrash("usr_5Kq2Lm8R", "doc_8Hq2Lm4R"); ``` ```json { "user": "usr_5Kq2Lm8R", "deleted": 3 } ``` For one document, `{ "user": …, "document": …, "deleted": true }`, or `404 document_not_found` when it isn't in their trash. ## End a user's sessions `DELETE /v1/users/{id}/sessions` Ends a user's editor and presence sessions, all of them or one `group`'s, as when they sign out. Described with the other session endpoints: see [End a user's sessions](/reference/api/sessions#end-a-users-sessions). ## List a user's agents `GET /v1/users/{id}/agents` The agents a user has connected, newest first. This endpoint is described with the other agent endpoints: see [List a user's agents](/reference/api/agents#list-a-users-agents). ## Retrieve a user's security keys `GET /v1/users/{id}/checkins` How many security keys a user has. Turning [Verified Presence](#turn-verified-presence-on-or-off-in-a-document) on needs one, and people add them only in presence settings, on Undertext's own domain. See [Presence and check-ins](/concepts/presence-and-check-ins). | Parameter | Type | Description | | --- | --- | --- | | `id` | string, path, required | The user's Undertext id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/users/usr_5Kq2Lm8R/checkins \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const { security_keys } = await undertext.users.retrieveCheckins("usr_5Kq2Lm8R"); ``` ```json { "user": "usr_5Kq2Lm8R", "security_keys": 2 } ``` | Attribute | Type | Description | | --- | --- | --- | | `user` | string | The user's Undertext id. | | `security_keys` | integer | How many security keys they've added. | ## Retrieve Verified Presence in a document `GET /v1/documents/{document_id}/checkins/{user_id}` Whether Verified Presence is on for a user in a document: whether they're asked to check in while they write there. It's their own switch, so each person in a document has one, unless your platform [requires it](/reference/api/platform#update-the-platform). | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user_id` | string, path, required | The user's Undertext id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/checkins/usr_5Kq2Lm8R \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const { enabled } = await undertext.documents.retrieveCheckins("doc_8Hq2Lm4R", "usr_5Kq2Lm8R"); ``` ```json { "document": "doc_8Hq2Lm4R", "user": "usr_5Kq2Lm8R", "enabled": true, "required": false } ``` | Attribute | Type | Description | | --- | --- | --- | | `document` | string | The document's id. | | `user` | string | The user's Undertext id. | | `enabled` | boolean | Whether they're asked to check in while they write in the document. | | `required` | boolean | Whether your platform requires Verified Presence, so it's on and can't be turned off. | ## Turn Verified Presence on or off in a document `PUT /v1/documents/{document_id}/checkins/{user_id}` Turns Verified Presence on or off for a user in one document. On, they're asked to check in while they write there, as often as your platform has check-ins come; in documents where it's off, they aren't asked. People can also turn it on themselves in the editor, and your page can with [`editor.setVerifiedPresence()`](/reference/embed#methods). | Parameter | Type | Description | | --- | --- | --- | | `document_id` | string, path, required | The document's id. | | `user_id` | string, path, required | The user's Undertext id. | | `enabled` | boolean, required | `true` to turn it on, `false` to turn it off. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/documents/doc_8Hq2Lm4R/checkins/usr_5Kq2Lm8R \ -X PUT \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{"enabled": true}' ``` ```ts tab="Node" await undertext.documents.updateCheckins("doc_8Hq2Lm4R", "usr_5Kq2Lm8R", { enabled: true }); ``` Returns the same object as [retrieving it](#retrieve-verified-presence-in-a-document). | Error | When | | --- | --- | | `400 invalid_parameter` on `enabled` | Not `true` or `false`. | | `409 no_security_keys` | Turning it on for a user with no security keys yet. Open presence settings for them to add one. | | `409 checkins_required` | Turning it off where your platform requires it. | # Webhook endpoints > Choose where Undertext sends events, and get the secret to check they came from Undertext. A webhook endpoint is a URL on your server where Undertext sends events: a comment, a mention, a suggestion accepted, a document an agent created, a seal. You turn them into notifications, emails and updates in your own lists. You can manage endpoints here or in the [console](https://undertext.sh/console). See [Send notifications](/guides/notifications) for a worked example and [Webhook events](/reference/webhooks) for every event and its payload. Each platform has its own endpoints, and hears only its own events. ## The webhook endpoint object | Attribute | Type | Description | | --- | --- | --- | | `id` | string | The endpoint's id, starting `we_`. | | `url` | string | Where Undertext posts events. | | `events` | array | The event types it receives, or `["*"]` for all of them, including types added later. | | `created_at` | timestamp | When it was created. | | `secret` | string | The signing secret, starting `whsec_`. Returned only when you create the endpoint or roll its secret. | ```json { "id": "we_5Kd2Hs8N", "url": "https://acme.com/undertext/events", "events": ["thread.created", "thread.replied", "mention.created", "seal.created"], "created_at": "2026-10-30T18:20:00Z" } ``` ## Create a webhook endpoint `POST /v1/webhook-endpoints` | Parameter | Type | Description | | --- | --- | --- | | `url` | string, required | An `https` URL. For your machine, use a tunnel. | | `events` | array, required | Event types, such as `["mention.created", "seal.created"]`, or `["*"]` for all. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/webhook-endpoints \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://acme.com/undertext/events", "events": ["thread.created", "thread.replied", "mention.created", "seal.created"] }' ``` ```ts tab="Node" const endpoint = await undertext.webhookEndpoints.create({ url: "https://acme.com/undertext/events", events: ["thread.created", "thread.replied", "mention.created", "seal.created"], }); // Store endpoint.secret now: it isn't shown again. ``` Returns the [endpoint](#the-webhook-endpoint-object) with its `secret`, with `201`. ```json { "id": "we_5Kd2Hs8N", "url": "https://acme.com/undertext/events", "events": ["thread.created", "thread.replied", "mention.created", "seal.created"], "created_at": "2026-10-30T18:20:00Z", "secret": "whsec_R4n8Vq2Lk7Tz1Mx9Pw3Hc6Bs" } ``` | Error | When | | --- | --- | | `400 invalid_parameter` on `url` | Not a URL, or not `https`. | | `400 invalid_parameter` on `events` | An event type doesn't exist. | ## List webhook endpoints `GET /v1/webhook-endpoints` Your endpoints, newest first. Secrets aren't included. | Parameter | Type | Description | | --- | --- | --- | | `limit` | integer | 1 to 100. Default 50. | | `after` | string | The `next` cursor from the previous page. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/webhook-endpoints \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const page = await undertext.webhookEndpoints.list(); ``` ```json { "data": [ { "id": "we_5Kd2Hs8N", "url": "https://acme.com/undertext/events", "events": ["thread.created", "thread.replied", "mention.created", "seal.created"], "created_at": "2026-10-30T18:20:00Z" } ], "next": null } ``` ## Roll a signing secret `POST /v1/webhook-endpoints/{endpoint_id}/roll-secret` Issues a new signing secret. For the next 24 hours Undertext signs each event with both the old and the new secret, so you can deploy the new one without dropping events. See [Verifying signatures](/reference/webhooks). | Parameter | Type | Description | | --- | --- | --- | | `endpoint_id` | string, path, required | The endpoint's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/webhook-endpoints/we_5Kd2Hs8N/roll-secret \ -X POST \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" const { secret } = await undertext.webhookEndpoints.rollSecret("we_5Kd2Hs8N"); ``` Returns the [endpoint](#the-webhook-endpoint-object) with its new `secret`. ## Delete a webhook endpoint `DELETE /v1/webhook-endpoints/{endpoint_id}` Stops sending events to the endpoint. Events already on their way, including retries, are dropped. | Parameter | Type | Description | | --- | --- | --- | | `endpoint_id` | string, path, required | The endpoint's id. | ```bash tab="curl" tab-group="lang" curl https://api.undertext.sh/v1/webhook-endpoints/we_5Kd2Hs8N \ -X DELETE \ -H "Authorization: Bearer $UNDERTEXT_SECRET_KEY" ``` ```ts tab="Node" await undertext.webhookEndpoints.delete("we_5Kd2Hs8N"); ``` ```json { "id": "we_5Kd2Hs8N", "deleted": true } ``` ## Delivery Each event is a `POST` with a JSON body and an `Undertext-Signature` header. Check the signature before you trust the body: `undertext.webhooks.verify(rawBody, header, secret)` does it in Node. Answer with any `2xx` within 10 seconds; anything else, or no answer, is retried with backoff for 3 days. Events can arrive more than once or out of order, so skip ids you've already handled. The [webhook events reference](/reference/webhooks) has the signature format and every event's payload. # Embed API > Every option, event and method of the editor and seals you embed with @undertext/embed, and what your page needs to allow it. The embed puts the Undertext editor in your page as an iframe served from `embed.undertext.sh`. Your page passes it a document id and a way to get session tokens; everything the person does inside it goes straight to Undertext. For a walkthrough, see [Embed the editor](/guides/embed-the-editor). ## Install From npm, for pages you bundle: ```bash npm install @undertext/embed ``` ```ts import { mountEditor, mountPresenceSettings, mountSeal, openPresenceSettings } from "@undertext/embed"; ``` Or with a script tag, which defines `window.Undertext` with the same four functions: ```html ``` The package is a few kilobytes: it creates the iframe and passes messages to it. The editor itself always loads from `embed.undertext.sh`, so it stays current without a new release of your page. `v1.js` only changes in ways that keep your code working. ## mountEditor ```ts const editor = mountEditor(element, options); ``` `element` is the container the iframe goes in; it replaces anything inside it. `mountEditor` returns the editor at once and loads it in the background: wait for the [`ready` event](#events) before calling methods that need the document. ```ts title="page.ts" const editor = mountEditor(document.querySelector("#editor")!, { document: "doc_8Hq2Lm4R", getToken: async (doc) => { const response = await fetch(`/undertext/session?doc=${doc}`, { method: "POST" }); return (await response.json()).token; }, comments: "right", colorScheme: "auto", }); ``` ### Options | Option | Type | Default | What it does | | --- | --- | --- | --- | | `document` | `string` | required | The document to open. | | `getToken` | `(document: string) => Promise` | required | Returns a fresh [session token](/reference/api/sessions) for `document` and the person viewing it: the one open, or one [`open`](#opening-another-document) opens. The embed asks for no other, whatever the frame says. | | `mode` | `"edit"` or `"suggest"` | `"edit"` where the role allows | Whether the person's changes are made or proposed. A suggester always suggests and a viewer only reads, whatever you pass. | | `colorScheme` | `"light"`, `"dark"` or `"auto"` | `"light"` | `"auto"` follows the person's system setting. | | `toolbar` | `"header"`, `"floating"` or `"none"` | `"header"` | Where the format bar goes: along the top, floating at the bottom, or nowhere (Markdown shortcuts and the ⌘K palette still work). Along the top it keeps to one row, with the buttons there isn't room for under » at its end. | | `chrome` | `"full"` or `"compact"` | `"full"` | Use `"compact"` when your host provides navigation, save status, authorship, and sealing actions. It removes duplicate status and the floating seal, keeps collaborators and role notices, and offers touch-sized formatting buttons with the other tools under More. Use it with `toolbar: "floating"`. | | `comments` | `"right"`, `"left"` or `"hidden"` | `"right"` | Where comment and suggestion cards go. Where the frame is too narrow, they go in a panel. `"hidden"` hides comments but not suggestions. | | `highlight` | `boolean` | `false` | Tint text by who wrote it, and show the attribution rail beside each line. | | `height` | `"auto"` or `"fill"` | `"auto"` | See [Sizing](#sizing). | | `target` | `{ kind, id }` | none | A comment (`kind: "comment"`, a thread id) or suggestion to open once the document has loaded, as from a notification or a [link](#links-to-comments-and-suggestions). | | `autofocus` | `boolean` | `true` | Put the caret in the text once it loads. Pass `false` when your page shows something first, and call `focus()` when it's ready. | | `origin` | `string` | where `v1.js` came from, or `https://embed.undertext.sh` (also for your own bundle of the package) | Where Undertext serves the editor. | These shape the editor around your own page's controls: | Option | Type | What it does | | --- | --- | --- | | `headerItems` | `{ id, icon, label, badge?, side?, popup?, expanded? }[]` | Buttons of your own in the editor's header, such as a menu or a notification bell: at its end, after who's here (`side: "end"`, the default), or at its start, before the format bar (`"start"`). `icon` is `"bell"`, `"more"` or `"sidebar"`; `label` names it to screen readers and is its tooltip; `badge` is a short count shown on it, such as `"3"` or `"9+"`. A click sends a [`command` event](#events) with its `id` and where the button is, for your page to open its menu or panel there. For a button that opens something, set `popup` (`"menu"` or `"dialog"`), and keep `expanded` current as what it opens opens and closes. | | `pageLeft` | `number` | How far, in pixels, the frame's left edge is from your page's, as beside a sidebar. The editor's dialogs then centre on your page rather than the frame, as far as the frame allows. Update it with `setOptions` when the sidebar resizes. | | `commentPane` | `{ axis: "horizontal" or "vertical", start: number, end: number }` or `null` | Give comments their own pane after a gutter, measured in the frame's CSS pixels. Writing sits before `start`, discussion after `end`. Use the gutter for a fold or other reserved area. Each pane needs at least 280px horizontally or 160px vertically; otherwise the normal margin is used. `null` restores the normal margin. | | `commands` | `{ title, items }[]` | Groups of your own items for the editor's ⌘K palette. Each item is `{ id, label, hint?, checked?, disabled? }`; choosing one sends a [`command` event](#events) with its `id`. | | `shortcuts` | `string[]` | Keys your page listens for, such as `"mod+k"`, that the editor passes on as a `shortcut` event while it has focus. | | `trashActions` | `boolean` | For a document in the person's trash, the card at the foot offers Restore and Delete forever, sending `command` events `restore` and `delete`. | Change any of these after mounting with `editor.setOptions({ ... })`. What you set is kept if the frame reloads, as it does when the person's access changes. ### Tokens The editor calls `getToken` when it mounts, and again two minutes before each token lapses (tokens last 15 minutes), so a page left open keeps working; an open connection carries on with the new token. If a call fails, the editor keeps the person's changes and the embed tries again after 1, 2, 5, 10 and 30 seconds; while the browser is offline, it waits until it's back online instead. If it still fails, as when your server refuses because the person lost access, the editor emits an `error` event with code `token_rejected` and stops asking. Your server makes the token with [`POST /v1/sessions`](/reference/api/sessions). Check that the signed-in person may open the document before you do: the token is how Undertext knows who is writing. ## Events ```ts const stop = editor.on("title", ({ title }) => (document.title = `${title} · Acme Notes`)); stop(); // stops listening ``` `on` returns a function that removes the handler. | Event | Payload | When | | --- | --- | --- | | `ready` | `{ document, role, mode, user }` | The document has loaded. `role` is `"owner"`, `"editor"`, `"suggester"` or `"viewer"`; `user` is the person's Undertext id. | | `title` | `{ title, name }` | The document's title changed: `name` is the name an editor gave it, or `null`; `title` is that, or its first line. Also sent once after `ready`. | | `save-state` | `{ state, unsaved }` | `"saving"` while changes are on their way, `"saved"` once Undertext has them, `"offline"` while the connection is down. `unsaved` is `true` while some change hasn't reached Undertext, for warning before the page closes. Changes made offline are kept and sent on reconnecting. | | `focus` | `{ focused }` | Whether the writing surface has keyboard focus. A surrounding app can use this to make more room for writing. | | `status` | `{ mode, comments, openComments, sealed, role, trashed, verifiedPresence }` | What your own controls show of the editor, whenever it changes: its mode, whether comments are shown and how many are open, whether it has a seal, the person's role, whether it's in their trash, and [Verified Presence](/concepts/presence-and-check-ins#check-ins) for them, `{ on, required }`: whether it's on, and whether your platform requires it, so it can't be turned off. `null` for someone who can't write in the document, who has no Verified Presence there. | | `seal` | `{ code, url, line }` | The person sealed the document with the editor's Seal button. The [`seal.created` webhook](/reference/webhooks#sealcreated) follows. | | `open-document` | `{ document, href }` | The person followed a link to another document of yours. Navigate to it in your own way; the editor doesn't. | | `thread-read` | `{ thread }` | The person read a thread, by opening it or writing in it: clear your notifications of it. | | `target` | `{ target }` | A comment's or suggestion's card opened (`{ kind, id }`), or closed (`null`). Name it in your page's address with `targetHash`, so the address links to it. | | `command` | `{ id, anchor?, expanded? }` | The person chose one of your [`commands`](#options) or [`headerItems`](#options), or a trash action. From a header button, `anchor` is where the button is in your page's window, as `{ left, top, right, bottom }`, and `expanded` is whether what it opens was open as it was pressed. Close what a header button opens when your page loses focus, as it does to any click in the frame; a press with `expanded: true` was one of those, so don't open it again. When what it opened closes and you give focus back to the frame, the editor puts it on the button. | | `shortcut` | `{ key }` | The person pressed one of your `shortcuts` in the editor. | | `presence-settings` | `{}` | The person needs presence settings, to add a key: from a check-in, or turning Verified Presence on without a key. Open them, framed or in their window. | | `overlay` | `{ open }` | A dialog opened in the frame, or closed: dim your page around it, which its backdrop can't reach, and close it with `closeDialog()` on a click there. | | `settings` | options | The person changed a display setting from inside the editor, such as the theme or where comments go: keep it, and pass it back next time. | | `height` | `{ height }` | The document's height changed. With `height: "auto"`, the embed resizes the frame itself. | | `error` | `{ code, message }` | Something stopped the editor. See below. | ### Error codes | Code | What happened | | --- | --- | | `token_rejected` | `getToken` failed for good, or returned a token Undertext doesn't accept. | | `no_access` | The token's person can no longer open the document. | | `document_deleted` | The document was deleted while it was open. | Handle the event to show your own message, or to send the person elsewhere. On a page whose origin isn't one of your [embed origins](#embed-origins), the browser refuses to show the frame at all, and no event comes. ## Methods | Method | What it does | | --- | --- | | `editor.focus()` | Puts the caret back where it was in the document. | | `editor.setMode(mode)` | Switches between `"edit"` and `"suggest"`, within what the role allows. | | `editor.print(options?)` | Prints the document, typeset, without the editor around it. `{ sealLine: true }` ends it with the document's seal line, as `export` does. | | `editor.export(format, options?)` | Resolves to the document as `"markdown"` or `"html"` text, or as a `Blob` for `"docx"`. Pending suggestions are left out. The HTML is sanitized: nothing in it runs. With `{ sealLine: true }`, it ends with the [seal line](/concepts/seals#the-seal-line) of the document's newest seal, its address linking to the seal's page. That needs the newest seal to read as the document does now: otherwise it rejects with an error whose `code` is `seal_changed`, or `not_sealed` when the document has no seal, so that a seal never vouches for words it doesn't say. | | `editor.openBreakdown()` | Opens the breakdown behind the live seal: where the words came from, presence, prompts and sittings. | | `editor.openSeal()` | Opens the seal dialog. Anyone who can open the document sees its seals, their links and who reads them; its editors also see the readers listed; its owners also seal, choose who reads its seals, answer people asking to read them, and withdraw versions. | | `editor.openPalette()` | Opens the ⌘K palette. | | `editor.showTarget({ kind, id })` | Scrolls to a comment or suggestion and opens its card. | | `editor.comment()` | Starts a comment on the selection. | | `editor.toggleComments()` | Shows comments beside the text or hides them; in the narrow panel, opens or closes it. | | `editor.setVerifiedPresence(on)` | Turns Verified Presence on or off for the person in this document, for those who can write in it: on, they're asked to check in as they write here. Resolves to whether it's on. Without a key it stays off and the editor sends `presence-settings`; it turns on once they come back to the editor with a key. Where your platform requires it, it stays on. See [Set up check-ins](/guides/set-up-check-ins#turn-verified-presence-on-in-a-document). | | `editor.closeDialog()` | Closes the dialog the editor has open, as for a click on your page where you dim it during [`overlay`](#events). | | `editor.open(document, { target })` | Opens another document in place of the one open. See [Opening another document](#opening-another-document). | | `editor.setOptions(options)` | Changes [options](#options) after mounting. | | `editor.destroy()` | Removes the iframe and its listeners. Changes already made are kept. | Methods return promises, which resolve once the editor has done it. ### Opening another document Where people move between documents, as from a list beside the editor, open each in the same editor rather than mounting another: the editor isn't loaded again, and the next document loads while the one before stays in view. ```ts await editor.open("doc_3Fw9Kp2T", { target: null }); ``` It asks `getToken` for the next document's token. The one open stays in view, unusable, until the next has loaded, or for a second at most; it then shows how far it has got. The promise resolves once the next is in view, and rejects if it can't be opened, which leaves the one before, or if another is opened first. From the call on, events are the next document's: `ready` once it has loaded. `editor.role` and `editor.mode` hold the current role and mode once `ready` has fired. ## Links to comments and suggestions A link to a document can open a comment's or suggestion's card: the links Undertext's agents give to a comment or suggestion, and the editor's own **Copy link** on a card, are your [`document_url`](/reference/api/platform) followed by `#comment-` or `#suggestion-`. Without a `document_url`, cards offer no link. Read the target from your page's address and pass it on, and keep the address naming the open card as cards open and close: ```ts import { mountEditor, parseTarget, targetHash } from "@undertext/embed"; const editor = mountEditor(element, { document, getToken, target: parseTarget(location.hash) }); editor.on("target", ({ target }) => history.replaceState(null, "", location.pathname + location.search + (target ? targetHash(target) : ""))); ``` | Name | What it does | | --- | --- | | `parseTarget(hash)` | The `{ kind, id }` a link's hash names, or `null`. | | `targetHash(target)` | The hash that opens `target`'s card, for links you make yourself. | Both are also at `@undertext/embed/links`, which needs no browser, for links your server builds, and on `window.Undertext` from `v1.js`. ## Presence settings Security keys must be added on Undertext's own domain, so people add them in Undertext's presence settings: framed in your own settings page, or in a small window of their own. Both take a token from [`POST /v1/sessions`](/reference/api/sessions) with `purpose: "presence"`. ### mountPresenceSettings ```ts const presence = mountPresenceSettings(element, { getToken: () => fetch("/undertext/presence-session", { method: "POST" }).then((r) => r.json()).then((r) => r.token), platform: "acme", colorScheme: "auto", }, (choice) => console.log(choice)); // { keys: 1 } ``` `platform` is your platform's slug: framed, presence settings load only on your embed origins. `colorScheme` is as the editor's; framed, the settings have no background of their own, so your page shows through. The callback hears each change. `presence.setOptions({ colorScheme: "dark" })` changes the colour scheme, and `presence.destroy()` removes the frame. Browsers that won't create a security key in a frame need the window instead. ### openPresenceSettings ```ts button.addEventListener("click", async () => { const result = await openPresenceSettings({ getToken: () => fetch("/undertext/presence-session", { method: "POST" }).then((r) => r.json()).then((r) => r.token), }); console.log(result); // { keys: 1 } }); ``` It takes a `colorScheme` too. Call it from a click or key press, or the browser blocks the window. The promise resolves when the person closes the window, with how many keys they have. See [Set up check-ins](/guides/set-up-check-ins). ## Seals ### mountSeal A seal on your own seal page, at your [`seal_url`](/reference/api/platform): the sealed text, the seal and its breakdown, drawn by Undertext in an iframe from `embed.undertext.sh`, so what it shows is Undertext's whatever your page does. It fills its element: give the element a height, such as the whole window. See [Show seals on your site](/guides/seal-and-verify#show-seals-on-your-site). ```ts const seal = mountSeal(element, { code: "66G4LF343", getToken: () => fetch("/undertext/seal-session", { method: "POST" }).then((r) => (r.ok ? r.json().then((r) => r.token) : null)), onSignIn: () => location.assign(`/sign-in?next=${encodeURIComponent(location.pathname)}`), colorScheme: "auto", }); seal.on("ready", ({ state, title }) => (document.title = title ?? "Undertext")); ``` | Option | Type | Description | | --- | --- | --- | | `code` | string, required | The seal's code, from your page's address. | | `getToken` | `(code) => Promise` | A token from [`POST /v1/sessions`](/reference/api/sessions#for-seals) with `purpose: "seal"`, for the person signed in with you, or `null` when nobody is. Called only when the seal is private, once; if it throws, the seal is shown as to someone with no session. | | `onSignIn` | `(reader) => void` | When given, a private seal's page offers to sign in, and calls this. `reader` is `{ email }` when your session's person isn't among its readers, so you can offer another account; `null` when you gave no session. | | `origin` | string | Where Undertext serves its frames. Defaults to `https://embed.undertext.sh`. | | `colorScheme` | `"light"`, `"dark"` or `"auto"` | As the editor's. | | Event | Payload | When | | --- | --- | --- | | `ready` | `{ state, title }` | It has shown the seal (`state: "sealed"`, with its title), that it was withdrawn (`"withdrawn"`), or that it's private to this reader (`"private"`). | | `sign-in` | `{ reader }` | The reader asked to sign in, as `onSignIn` hears. | Someone signed in whose email your session vouched for, and whom a private seal doesn't let in, can ask its owners to let them read it, with a message, in the frame; it says so when they come back. See [Private seals](/guides/seal-and-verify#private-seals). `seal.setOptions({ colorScheme })` changes the colour scheme, and `seal.destroy()` removes the frame. Links to the seal's other versions open your seal page for them, in place of the page around the frame. A private seal's password is typed in the frame and goes to Undertext alone; what it earns is kept in the frame, for 30 days. ## Embed origins The editor loads only on the origins you list under **Embed origins** in the [console](https://undertext.sh/console). Undertext serves it with a `Content-Security-Policy: frame-ancestors` header naming exactly those origins, and the editor framed there opens only your platform's documents, taking messages only from the page that frames it, so another site can't frame your users' documents, even with a token of yours. List each origin in full, for example `https://acme.com` and `https://www.acme.com`. Plain `http` is allowed only for `localhost` and `127.0.0.1`, such as `http://localhost:5173`, for development. Set them with [`PATCH /v1/platform`](/reference/api/platform) too. If your own page sends a Content Security Policy, it needs: | Directive | Value | For | | --- | --- | --- | | `frame-src` | `https://embed.undertext.sh` | The editor, seals and the presence window. | | `script-src` | `https://embed.undertext.sh` | Only with the `v1.js` script tag. | The iframe asks for two permissions: `publickey-credentials-get`, for check-ins with a security key, and `clipboard-write`, for copying a seal line; framed presence settings ask for `publickey-credentials-create` too, to add a key. If your page sends a `Permissions-Policy` header, it must not deny them to `https://embed.undertext.sh`, or check-ins can't run. ## Sizing With `height: "auto"`, the iframe grows and shrinks with the document, and your page scrolls as it would with any long content. Use it when the document sits in the flow of a page. With `height: "fill"`, the iframe fills its container and the document scrolls inside it. Give the container a height, for example with flex or grid. Use it for a full-window editor beside your own sidebar. The editor is at least 320 pixels tall either way, and needs 720 pixels of width to put comments beside the text. ## Keyboard and focus While the editor has focus, keys go to it: ⌘K (Ctrl+K) opens its palette for this document, ⌘P prints the document, and Tab indents list items. Press Esc, then Tab, to move focus out of the editor to the next control on your page. Shortcuts your page listens for on `window` don't fire while the editor has focus, unless you list them in `shortcuts`. ## Appearance You choose the colour scheme, full or compact controls, where the toolbar and comments go, whether authorship is highlighted, and buttons of your own in the header. Compact controls reduce space around the document for native hosts; the document itself is fixed, so every Undertext editor reads the same way to the people who verify what was written in it: - The document's typefaces and paragraph spacing. - The seal's colours, which stand for where words came from. - The blocks people can write: headings, lists, checklists, quotes, code, links, images and tables. You can't add your own. There is no custom CSS. If your page needs something the options don't give, [tell us](mailto:undertext@exalto.ai). ## Storage and cookies The editor and seals set no cookies and need none: everything rides on the session token. Browsers keep a framed site's storage apart from the same site opened directly, so the editor doesn't rely on it; a seal keeps what its password earned there, per site that frames it, and asks for the password again where it can't. Display settings a person changes in the editor come to your page as a `settings` event, for you to keep with your other preferences and pass back as options. ## Browsers The editor supports the two latest versions of Chrome, Edge, Firefox and Safari, on desktop and on iOS and Android. Check-ins with a security key need a browser that allows WebAuthn in a frame, which those versions do. Older browsers aren't supported. # MCP tools > The MCP server your users' agents connect to, how agents are authorised, and every tool they can call. Your users' agents (Claude, Codex, or any client that speaks the Model Context Protocol) reach their documents through one MCP server per platform, run by Undertext. Agents talk to Undertext directly: your server approves each agent once, and never relays its edits or holds its tokens. For the approval step, see [Connect agents](/guides/connect-agents). ## Your platform's server ```text https://mcp.undertext.sh/acme ``` The last part is your platform's slug, from the [console](https://undertext.sh/console). Show the address wherever your users connect agents; [`GET /v1/platform`](/reference/api/platform) gives it as `mcp_url`. An agent's tokens work only on the platform that issued them, so someone who uses two Undertext platforms connects their agent to each, and the agent keeps the two apart by server name (`acme`'s `read_document`, say, beside another platform's). The server names itself to agents by your slug and platform name, with your icon if you set `icon_url` on the [platform](/reference/api/platform). It speaks Streamable HTTP, statelessly, with JSON responses. It supports MCP protocol versions `2025-11-25`, `2025-06-18`, `2025-03-26` and `2024-11-05`, and answers a client asking for another with the newest. A request may batch up to 20 messages. ## How an agent is authorised An agent needs nothing but the address. The rest follows the MCP authorization spec, with OAuth 2.1: 1. The agent calls the server without a token and gets `401` with a `WWW-Authenticate` header pointing at the protected resource metadata, `https://mcp.undertext.sh/.well-known/oauth-protected-resource/acme`. 2. That names the authorization server, whose issuer is the same address as the MCP server. Its metadata is at `https://mcp.undertext.sh/.well-known/oauth-authorization-server/acme`. 3. The agent identifies itself in one of two ways. Most use a client ID metadata document: its `client_id` is the https address of a JSON document describing it, of at most 64 kB, which Undertext fetches (from public addresses only). Others register with dynamic client registration and get a `client_id` back; one that asks for `client_secret_basic` or `client_secret_post`, as Gemini's connected apps do, gets a `client_secret` too, and gives it with its `client_id` at the token endpoint, by HTTP Basic or in the form. Either way, it gives at most 10 redirect URIs of up to 2,000 characters, each over https, on a loopback address or in an app's own scheme, and the name it gives is the name people see, with the domain it comes from shown beside it. 4. The agent opens the person's browser at the authorize endpoint, with PKCE (`S256`; plain is refused). Its redirect URI must be one it registered, or for one on a loopback address, the same on any port. 5. Undertext has no sign-in of its own, so it sends the browser to your consent page with an [agent request](/reference/api/agent-requests). You sign the person in, ask them, and approve or deny from your server. 6. Undertext sends the browser back to the agent with an authorization code, and the agent exchanges it for tokens. One address (an IPv6 one by its /64) can register 100 clients, and start 100 authorizations, an hour. Access tokens last an hour, and work only at the address that issued them. Refresh tokens change each time they are used, and lapse after 90 days without use. A client with a secret keeps its refresh token instead, each use giving it another 90 days. One used again within a minute of its first use, as by two requests at once, gets new tokens too; used again after that, it ends all the agent's tokens, as someone else may hold a copy. Revoking the agent, through [`DELETE /v1/agents/:agent_id`](/reference/api/agents) or by deleting its person, ends both at once. ## What an agent may do An agent acts for one person, and can never do more than they can: - With `access: "all"`, it reaches every document its person can open, editing at most. - With `access: "chosen"`, it reaches only the documents its person, or your server, gave it a role in: `editor`, `suggester` or `viewer`. What it may do in a document is the lower of that and its person's role there now, checked on every call. If Ada becomes a viewer of a document, Ada's agent can only read it from that moment. An agent never owns a document, though it can start one for its person with `create_document`. A document the agent may not open answers as if it didn't exist: "You have no access to document doc_8Hq2Lm4R." ### Credit Everything an agent writes, suggests or comments is credited to it, under the name its person gave it (at first, what its client calls itself) and its person's current name: **Claude Code (Ada Lovelace's agent)**. Its words count as AI on the seal until a person shapes them. See [Provenance](/concepts/provenance). Writing tools take an optional `instruction`: what the person asked for, in their words where the agent has them. It is shown beside the text the agent wrote, labelled as reported by the agent. ### Suggest by default The server's instructions tell agents to propose their changes, with `suggest: true`, unless their person asked them to edit the document directly. Each suggestion shows in the editor for people to accept or reject, and its optional `comment` starts the suggestion's discussion. Where the agent may only suggest, every edit is a suggestion whatever it passes. ## Tools Every tool that works on one document takes its `document_id`. Every tool that writes to a document also takes these optional arguments: | Argument | Type | What it does | | --- | --- | --- | | `instruction` | string | What the person asked for, shown beside the text written. | | `suggest` | boolean | Propose the change instead of making it. | | `comment` | string | With `suggest`, a note for whoever reviews the suggestion. | Blocks are addressed by the ids `read_document` gives them, such as `1234:5`. Content goes in and comes out as GitHub-flavoured Markdown, with a person mentioned in the text written as a comment writes them, `@[Grace Hopper](user:usr_9Tb3Wc1X)`, and an agent as `@[Research](agent:agt_4Rk8Vn2Lp7Qs)`. ### Inbox | Tool | Arguments | What it does | | --- | --- | --- | | `list_inbox` | none | What the agent's person, or another of their agents, asked of it by [mentioning it](#mentioning-agents) and it hasn't dealt with yet, oldest first, 20 at a time: each item with its document, who mentioned it, and the whole comment thread as it is now, or the block and the words around a mention in the text. | | `mark_inbox_read` | `item_ids` | Takes items out of the inbox once the agent has dealt with them. | An MCP server can't call an agent, so the agent looks: the server's instructions tell it to check `list_inbox` when it starts working and whenever its person asks what's waiting, and `list_documents` and `read_document` add a line when its inbox holds something. Replying in or resolving a comment's thread takes that item out too. An item leaves on its own once its message is deleted or no longer mentions the agent, its thread is resolved or gone with its text or suggestion, or the agent may no longer open the document. Items are kept 90 days. ### Finding documents | Tool | Arguments | What it does | | --- | --- | --- | | `list_documents` | `cursor` | The documents the agent may open, newest first, 100 at a time, with what it may do in each: its person's documents with `access: "all"`, or those it was given. Pass the `next_cursor` it returns for more. | | `search_documents` | `query` | Blocks matching words across those documents, best first, at most 20, each with its `document_id`, block id and the text around the match. `"quotes"` match a phrase, `or` goes between alternatives, and `-word` excludes. | ### Managing documents | Tool | Arguments | What it does | | --- | --- | --- | | `create_document` | `markdown`, `instruction` | Starts a document owned by the agent's person, with the agent as an editor. Its first line is its title. Returns its `document_id` and link. | | `rename_document` | `document_id`, `name` | Names the document for everyone; an empty name calls it by its first line again. Needs edit access. | | `list_trash` | none | The documents in its person's trash that the agent may restore. | | `trash_document` | `document_id` | Moves a document to its person's trash: for everyone if they own it, from their own list if it was shared with them. Deleted for good after 30 days. | | `restore_document` | `document_id` | Brings a document back from its person's trash, as it was. | The three trash tools work only on documents the agent was given edit access to, or with `access: "all"`, and agents are told to use them only when their person asks. So are `rename_document` and `create_document`. ### Reading | Tool | Arguments | What it does | | --- | --- | --- | | `read_document` | `document_id`, `from_block_id` | The document as Markdown, each block with its id, and its pending suggestions with theirs. About 40,000 characters at a time: each part says the `from_block_id` to continue from, and the first part has the outline. | ### Editing | Tool | Arguments | What it does | | --- | --- | --- | | `replace_text` | `document_id`, `find`, `replace`, `block_id`, `all` | Replaces plain text inside blocks, keeping its formatting. Matches within one run of text. `block_id` limits it to one block; `all` replaces every match instead of the first. | | `insert_markdown` | `document_id`, `after_block_id`, `markdown` | Inserts Markdown after a block, or at the top with `"start"`. | | `replace_block` | `document_id`, `block_id`, `markdown` | Replaces one block with Markdown, which may be several blocks. | | `delete_block` | `document_id`, `block_id` | Deletes one block, images included. | | `append_markdown` | `document_id`, `markdown` | Adds Markdown at the end. | All five also take `instruction`, `suggest` and `comment`, and answer with the blocks they changed. ### Suggestions | Tool | Arguments | What it does | | --- | --- | --- | | `accept_suggestion` | `document_id`, `suggestion_id` | Makes a pending suggestion part of the document. Needs edit access. | | `reject_suggestion` | `document_id`, `suggestion_id` | Rejects a pending suggestion. Needs edit access, except to withdraw the agent's own. | ### Comments | Tool | Arguments | What it does | | --- | --- | --- | | `list_comments` | `document_id`, `include_resolved`, `from_thread_id` | The document's threads, oldest first: the block each is on, the text or suggestion it's about, and every message with its author. About 40,000 characters at a time. | | `add_comment` | `document_id`, `block_id`, `quote`, `suggestion_id`, `comment` | Starts a thread on the first `quote` in a block, or on a suggestion with `suggestion_id`. A suggestion has one thread, so commenting on one that has it adds a reply. | | `reply_to_comment` | `document_id`, `thread_id`, `comment` | Replies in a thread. Replying to a resolved thread reopens it. | | `resolve_comment` | `document_id`, `thread_id`, `resolved` | Resolves a thread, or reopens it with `resolved: false`. | | `edit_comment` | `document_id`, `thread_id`, `message_id`, `comment` | Rewrites one of the agent's own messages. | | `delete_comment` | `document_id`, `thread_id`, `message_id` | Deletes one of the agent's own messages. Deleting a thread's first message deletes the thread, which it may do only while nobody else has replied. | Agents may comment wherever they may suggest. To mention someone, which [notifies them through your webhook](/reference/webhooks#mentioncreated), an agent writes `@[Grace Hopper](user:usr_9Tb3Wc1X)` with an id from `list_people`, in a comment or in the Markdown it writes into the document, as a suggestion or not. ### Mentioning agents A person can mention their own agents, and only theirs, as they mention people: by typing `@` in a comment or the text, where the list shows their agents after the people, or as `@[Research](agent:agt_4Rk8Vn2Lp7Qs)` in Markdown. The agent finds it in its inbox: at once from a comment, or a minute after it's written in the text, as the text reads then. Only agents that may open the document can be mentioned, and an agent can mention its person's other agents the same way. An agent can mention its person too, to tell them what it did, which [notifies them](/reference/webhooks#mentioncreated) as anyone's mention does. A mention of someone else's agent is only its name: no inbox hears of it, and none of your webhooks do. ### People | Tool | Arguments | What it does | | --- | --- | --- | | `list_people` | `document_id` | Whom the agent may mention here: the document's members, and others who wrote in it or its comments and can still open it, its person among them, then its person's other agents that may open it. Each person comes with their Undertext user id, their name, the `detail` you gave them (such as an email address), and how to write their mention; each agent with its id, its name and its mention. | ### Images | Tool | Arguments | What it does | | --- | --- | --- | | `read_image` | `document_id`, `src` | Returns an image stored with the document, as `read_document` shows its address, for the agent to see. | | `add_image` | `document_id`, `after_block_id`, `url` or `data`, `alt` | Adds a PNG, JPEG, GIF or WebP image after a block, from an https address or base64 data, stored with the document. `alt` describes it for people who can't see it. | ## Links in answers Several tools answer with a link to the document, so the agent can hand it to its person. The link follows the **Document URL** pattern you set in the console or as `document_url` with [`PATCH /v1/platform`](/reference/api/platform), such as `https://acme.com/docs/{document}`. Without one, answers give the document's id alone. ## Limits | What | Limit | | --- | --- | | One part of `read_document` or `list_comments` | About 40,000 characters | | `list_documents` | 100 documents a call | | `search_documents` | 20 results | | `list_inbox` | 20 items a call | | One image | 1,900,000 bytes | | Images in one document | 100 MB, shared with people's uploads | | Messages in one request | 20 | Agents share the editor with people, and people come first. Their edits go ahead of agents' in every document, and each agent request gets a short slice of work at a time, so a burst from an agent never holds typing back by more than a moment. ## Your own tools Undertext's server has the tools for documents: their text, suggestions, comments, people and images, and an agent's inbox. Folders, pins, workspaces and anything else your product keeps for itself aren't Undertext's. To give agents those, [register tools of your own](/reference/api/platform#set-your-agent-tools): the server lists them after its own, adds your instructions to its own, and forwards each call to your server. See [Add your own agent tools](/guides/your-own-agent-tools). # Node SDK > The @undertext/sdk package for calling the Undertext API from your server, with typed methods for every endpoint. `@undertext/sdk` wraps the [REST API](/reference/api/overview) for Node.js servers. Every method maps to one endpoint, takes the same fields and returns the same objects, so the REST reference describes the SDK too. Use the client only on your server: it holds your secret key. [Its roles](#roles) and [people](#people) work in your pages too. ## Install ```bash npm install @undertext/sdk ``` It needs Node.js 20 or later and has no dependencies. ## Create a client ```ts title="undertext.ts" import Undertext from "@undertext/sdk"; export const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY); ``` The key decides the platform: everything the client does is on the platform it belongs to. [`undertext.platform.retrieve()`](#platform) says which. The second argument takes options: | Option | Default | What it does | | --- | --- | --- | | `maxRetries` | `2` | How many times a request answered with `429` or `5xx` is tried again. | | `baseUrl` | `https://api.undertext.sh/v1` | Where requests go. Change it only for a proxy, or an Undertext you run yourself. | ```ts const undertext = new Undertext(process.env.UNDERTEXT_SECRET_KEY, { maxRetries: 4 }); ``` ## Field names The SDK uses the API's own field names, in snake_case, in both directions. What you send to `undertext.documents.update` is the body of `PATCH /v1/documents/:id`, and what comes back is the document object as the REST reference shows it. ```ts await undertext.documents.update("doc_8Hq2Lm4R", { link_access: "suggest" }); ``` ## Methods Each resource is a property of the client. Path parameters come first, then the body or query as one object. ### Users See [Users](/reference/api/users). | Method | Endpoint | | --- | --- | | `undertext.users.upsert(externalId, params)` | `PUT /v1/users/external/:external_id` | | `undertext.users.retrieve(userId)` | `GET /v1/users/:user_id` | | `undertext.users.retrieveByExternalId(externalId)` | `GET /v1/users/external/:external_id` | | `undertext.users.update(userId, params)` | `PATCH /v1/users/:user_id` | | `undertext.users.delete(userId)` | `DELETE /v1/users/:user_id` | | `undertext.users.merge(userId, { into })` | `POST /v1/users/:user_id/merge` | | `undertext.users.listDocuments(userId, { limit?, ids? })` | `GET /v1/users/:user_id/documents` | | `undertext.users.listTrash(userId)` | `GET /v1/users/:user_id/documents?trashed=true` | | `undertext.users.emptyTrash(userId)` | `DELETE /v1/users/:user_id/trash` | | `undertext.users.deleteFromTrash(userId, documentId)` | `DELETE /v1/users/:user_id/trash/:document_id` | | `undertext.users.listAgents(userId, { document? })` | `GET /v1/users/:user_id/agents` | | `undertext.users.endSessions(userId, { group? })` | `DELETE /v1/users/:user_id/sessions` | | `undertext.users.retrieveCheckins(userId)` | `GET /v1/users/:user_id/checkins` | | `undertext.documents.retrieveCheckins(documentId, userId)` | `GET /v1/documents/:document_id/checkins/:user_id` | | `undertext.documents.updateCheckins(documentId, userId, { enabled })` | `PUT /v1/documents/:document_id/checkins/:user_id` | ### Documents See [Documents](/reference/api/documents). | Method | Endpoint | | --- | --- | | `undertext.documents.create(params)` | `POST /v1/documents` | | `undertext.documents.retrieve(documentId)` | `GET /v1/documents/:id` | | `undertext.documents.update(documentId, params)` | `PATCH /v1/documents/:id` | | `undertext.documents.trash(documentId, { user? })` | `POST /v1/documents/:id/trash` | | `undertext.documents.restore(documentId, { user? })` | `POST /v1/documents/:id/restore` | | `undertext.documents.delete(documentId)` | `DELETE /v1/documents/:id` | | `undertext.documents.export(documentId, { format })` | `GET /v1/documents/:id/export` | | `undertext.documents.provenance(documentId)` | `GET /v1/documents/:id/provenance` | `export` resolves to the Markdown as a string. ### Members See [Members](/reference/api/members). | Method | Endpoint | | --- | --- | | `undertext.members.list(documentId)` | `GET /v1/documents/:id/members` | | `undertext.members.put(documentId, userId, { role })` | `PUT /v1/documents/:id/members/:user_id` | | `undertext.members.delete(documentId, userId)` | `DELETE /v1/documents/:id/members/:user_id` | ### Sessions See [Sessions](/reference/api/sessions). | Method | Endpoint | | --- | --- | | `undertext.sessions.create({ user, document, via?, group? })` | `POST /v1/sessions` | | `undertext.sessions.create({ user, purpose: "presence", group? })` | `POST /v1/sessions` | | `undertext.sessions.create({ user, purpose: "seal", email?, group? })` | `POST /v1/sessions` | ### Agents See [Agents](/reference/api/agents). | Method | Endpoint | | --- | --- | | `undertext.agents.retrieve(agentId)` | `GET /v1/agents/:agent_id` | | `undertext.agents.update(agentId, { access })` | `PATCH /v1/agents/:agent_id` | | `undertext.agents.listDocuments(agentId)` | `GET /v1/agents/:agent_id/documents` | | `undertext.agents.putDocument(agentId, documentId, { role })` | `PUT /v1/agents/:agent_id/documents/:document_id` | | `undertext.agents.deleteDocument(agentId, documentId)` | `DELETE /v1/agents/:agent_id/documents/:document_id` | | `undertext.agents.revoke(agentId)` | `DELETE /v1/agents/:agent_id` | ### Agent requests See [Agent requests](/reference/api/agent-requests). | Method | Endpoint | | --- | --- | | `undertext.agentRequests.retrieve(requestId)` | `GET /v1/agent-requests/:id` | | `undertext.agentRequests.approve(requestId, params)` | `POST /v1/agent-requests/:id/approve` | | `undertext.agentRequests.deny(requestId)` | `POST /v1/agent-requests/:id/deny` | ### Seals See [Seals](/reference/api/seals). | Method | Endpoint | | --- | --- | | `undertext.seals.create(documentId, { user })` | `POST /v1/documents/:id/seals` | | `undertext.seals.list(documentId)` | `GET /v1/documents/:id/seals` | | `undertext.seals.retrieve(code)` | `GET /v1/seals/:code` | | `undertext.seals.withdraw(code)` | `DELETE /v1/seals/:code` | ### Webhook endpoints See [Webhook endpoints](/reference/api/webhook-endpoints). | Method | Endpoint | | --- | --- | | `undertext.webhookEndpoints.create({ url, events })` | `POST /v1/webhook-endpoints` | | `undertext.webhookEndpoints.list()` | `GET /v1/webhook-endpoints` | | `undertext.webhookEndpoints.rollSecret(endpointId)` | `POST /v1/webhook-endpoints/:id/roll-secret` | | `undertext.webhookEndpoints.delete(endpointId)` | `DELETE /v1/webhook-endpoints/:id` | ### Platform See [Platform](/reference/api/platform). | Method | Endpoint | | --- | --- | | `undertext.platform.retrieve()` | `GET /v1/platform` | | `undertext.platform.update(params)` | `PATCH /v1/platform` | | `undertext.platform.verifyDomain()` | `POST /v1/platform/verify-domain` | | `undertext.platform.setTools({ url, secret, tools, instructions? })` | `PUT /v1/platform/tools` | | `undertext.platform.stats()` | `GET /v1/platform/stats` | ## Lists and paging Methods that list things return a page you can either await or iterate. Awaiting it gives you one page, as the API returns it: ```ts const page = await undertext.users.listDocuments("usr_5Kq2Lm8R", { limit: 20 }); page.data; // up to 20 documents, newest edited first page.next; // a cursor, or null on the last page ``` Iterating it with `for await` fetches the following pages as you go, so you see every item once: ```ts for await (const doc of undertext.users.listDocuments("usr_5Kq2Lm8R")) { console.log(doc.title); } ``` Stop the loop with `break` whenever you have what you need; no further pages are fetched. ## Errors A request the API refuses throws an `UndertextError`. It carries the API's error fields and the HTTP status: | Property | Example | What it is | | --- | --- | --- | | `type` | `"permission"` | The kind of error, as listed in [Errors](/reference/api/overview). | | `code` | `"no_access"` | A specific reason you can branch on. | | `message` | `"usr_9Tb3Wc1X can't open doc_8Hq2Lm4R."` | A sentence for your logs, not for your users. | | `param` | `"role"` | The field at fault, for `invalid_request` errors. | | `status` | `403` | The HTTP status. | ```ts import Undertext, { UndertextError } from "@undertext/sdk"; try { const session = await undertext.sessions.create({ user: "usr_9Tb3Wc1X", document: "doc_8Hq2Lm4R" }); } catch (error) { if (error instanceof UndertextError && error.code === "no_access") { // Grace isn't a member, and the document's link access doesn't let Grace in. } else { throw error; } } ``` Network failures throw the error `fetch` threw. ## Retries The client retries a request that was rate limited (429), and one other than a `POST` that failed on our side (500 and above), `maxRetries` times. It waits longer before each try, and as long as `Retry-After` asks when the API sends it. A `POST` that failed may have been carried out, so it isn't sent again: see [Idempotency](/reference/api/overview#idempotency). Every id the client puts in a path is encoded as one segment, and an id of `.` or `..` throws a `TypeError`: an id that came from your users can't name another endpoint. ## Webhooks `undertext.webhooks.verify` checks a delivery's signature and returns the event, or throws an `Error`. Give it the body exactly as it arrived, before any JSON parsing: ```ts title="webhooks.ts" import express from "express"; import { undertext } from "./undertext"; const app = express(); app.post("/undertext/webhooks", express.raw({ type: "application/json" }), (req, res) => { const event = undertext.webhooks.verify(req.body, req.get("Undertext-Signature") ?? "", process.env.UNDERTEXT_WEBHOOK_SECRET!); if (event.type === "mention.created") notifyMention(event.data); res.sendStatus(204); }); ``` It also refuses a delivery whose timestamp is more than five minutes from your clock. [Webhook events](/reference/webhooks) lists every event and its payload. Calls to [your own agent tools](/guides/your-own-agent-tools) are signed the same way. `verifySignature(rawBody, header, secret)` checks one and says whether it matched: ```ts import { verifySignature } from "@undertext/sdk"; if (!verifySignature(rawBody, req.get("Undertext-Signature"), process.env.ACME_TOOLS_SECRET!)) return res.sendStatus(401); ``` ## Roles `@undertext/sdk/roles` holds the roles and link access and how they rank, for your sharing screens and your own checks. It holds no key and needs nothing from Node, so your pages can import it too; the package's root exports the same names. ```ts import { atLeast, LINK_ACCESS, ROLES, writes } from "@undertext/sdk/roles"; atLeast("editor", "suggester"); // true: an editor may do all a suggester may writes("suggester"); // "suggest": a suggester changes the document only by suggesting ``` | Name | What it is | | --- | --- | | `ROLES` | `owner`, `editor`, `suggester` and `viewer`, from the most a member may do to the least. Type `Role`. | | `LINK_ACCESS` | `restricted`, `view`, `suggest` and `edit`: what a document's link gives anyone who opens it. Type `LinkAccess`. | | `AGENT_ROLES` | The roles a person may give their agents: all but `owner`. Type `AgentRole`. | | `atLeast(role, needed)` | Whether `role` may do all that `needed` may. `false` for `null`, no role. | | `writes(role)` | How `role` changes a document: `"edit"`, `"suggest"`, or `null` for not at all. | Undertext decides what each person may do in a document; these only mirror its rules. ## People `@undertext/sdk/people` shows people and agents as the editor does, for your own lists: a bell, mentions, sharing. It also checks a person's name as Undertext takes it. Like the roles, it holds no key, so your pages can import it too; the package's root exports the same names. ```ts import { colorOf, credit } from "@undertext/sdk/people"; const { author } = event.data.message; // { type: "agent", agent: "agt_…", user: "usr_…", name: "Codex" } colorOf(author); // the agent's own colour credit({ name: author.name, person: { name: "Ada" } }); // "Codex (Ada's agent)" if (event.actor.type !== "platform") colorOf(event.actor); // an event's actor may be your platform itself ``` | Name | What it is | | --- | --- | | `colorOf(actor)` | A person's colour, from `{ user }`, or an agent's own, from `{ agent }`: the shapes webhooks name people and agents by (not your platform, `{ type: "platform" }`). A document shows someone in another colour when someone else there already has theirs. | | `COLORS` | The colours `colorOf` picks from. | | `credit(actor)` | A name, and whose agent it is: `"Codex (Ada's agent)"`. Takes `{ name, person? }`. | | `whose(actor)` | `"Ada's agent"` for an agent with a `person`, or `null`. | | `NO_NAME` | `"Someone"`: what anyone known by no name is called. | | `NAME_CHARS` | `48`: how long a person's name may be. | | `validName(name, clip?)` | A person's name as [`users.upsert`](/reference/api/users) takes it: trimmed and in NFC, or `null` when it's empty, longer than `NAME_CHARS` (48) or holds control or invisible characters. With `clip`, a long name is shortened instead. | ## TypeScript The package ships its own types. Each object the API returns has a type of the same name: ```ts import type { Agent, Document, Event, Member, Platform, Provenance, Role, Seal, Session, User } from "@undertext/sdk"; ``` `Event` is the webhook envelope, with `data` typed as `T`; pass the payload type of the events you handle: ```ts const event = undertext.webhooks.verify<{ seal: Seal }>(rawBody, header, secret); if (event.type === "seal.created") await saveSeal(event.data.seal.code, event.data.seal.url); ``` # Webhook events > Every event Undertext sends to your webhook endpoints, how deliveries are signed, and how they are retried. Undertext tells your server what happened in the editor by posting events to the endpoints you register in the [console](https://undertext.sh/console) or with [`POST /v1/webhook-endpoints`](/reference/api/webhook-endpoints). Use them for what Undertext leaves to you: notifications, emails, activity feeds and your own document lists. For a walkthrough, see [Send notifications](/guides/notifications). ## The event Every delivery is one event, posted as JSON: ```json { "id": "evt_4Rk9Tn2Wq8Lm", "type": "mention.created", "created_at": "2026-10-30T14:02:11.482Z", "actor": { "type": "person", "user": "usr_5Kq2Lm8R" }, "data": { "document": "doc_8Hq2Lm4R", "mentioned": "usr_9Tb3Wc1X", "author": { "type": "person", "user": "usr_5Kq2Lm8R", "name": "Ada Lovelace" }, "thread_id": "thr_6Pz3", "message_id": "msg_9Xc1", "block_id": null, "excerpt": "@Grace Hopper could you check the second table?" } } ``` | Field | What it is | | --- | --- | | `id` | The event's id. A retried delivery has the same id. | | `type` | One of the [event types](#event-types) below. | | `created_at` | When it happened, in UTC, to the millisecond. | | `actor` | Who did it. See below. | | `data` | What happened. Its shape depends on `type`. | ### The actor | `actor.type` | Fields | Who | | --- | --- | --- | | `person` | `user` | One of your users, writing in the editor. | | `agent` | `agent`, `user` | An agent, with `user` the person it acts for. | | `platform` | none | Your own server, through the API. | ## Verify the signature Each delivery carries an `Undertext-Signature` header: ```http Undertext-Signature: t=1793455331,v1=5f1c0b8a9e3d4f27c6a1e0b9d8c7f6a5e4d3c2b1a0f9e8d7c6b5a4f3e2d1c0b9 ``` `t` is when it was sent, in seconds since 1970. `v1` is an HMAC-SHA256, in hex, of the timestamp, a full stop and the raw request body, keyed with the endpoint's signing secret (`whsec_…`). To check a delivery: 1. Read the raw body as bytes, before any JSON parsing; parsing and re-encoding changes it. 2. Compute the HMAC of `` `${t}.${body}` `` with your secret. 3. Compare it with each `v1` in the header, in constant time. One must match. 4. Refuse the delivery if `t` is more than five minutes from your clock. The [Node SDK](/reference/node#webhooks) does this for you with `undertext.webhooks.verify`. By hand, in Node: ```ts title="verify.ts" import { createHmac, timingSafeEqual } from "node:crypto"; export function verifyUndertextSignature(rawBody: Buffer, header: string, secret: string): boolean { const pairs = header.split(",").map((part) => part.split("=") as [string, string]); const t = Number(pairs.find(([key]) => key === "t")?.[1]); if (!Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > 300) return false; const expected = createHmac("sha256", secret).update(`${t}.`).update(rawBody).digest(); return pairs .filter(([key]) => key === "v1") .some(([, hex]) => { const given = Buffer.from(hex, "hex"); return given.length === expected.length && timingSafeEqual(given, expected); }); } ``` When you roll an endpoint's secret ([`POST /v1/webhook-endpoints/{id}/roll-secret`](/reference/api/webhook-endpoints)), deliveries carry two `v1` signatures, one for each secret, for 24 hours. Code that accepts any matching `v1` keeps working through the change. ## Delivery - Undertext posts each event with `Content-Type: application/json` and `User-Agent: Undertext-Webhooks/1`. - Answer with any 2xx status within 10 seconds. Do slow work after you answer, from a queue. - Anything else, or no answer, counts as a failure. Undertext tries again after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours, then every 12 hours, for 3 days in all. - An event can arrive more than once. Keep the ids you've handled and skip repeats. - Events can arrive out of order, especially after a retry. Where order matters, compare `created_at`, or read the current state from the API: [`GET /v1/documents/:id`](/reference/api/documents) rather than the last `document.renamed` you saw. An endpoint receives the types it was registered for, or all of them with `["*"]`. New event types may be added to `/v1` at any time, so ignore types you don't know. ## Event types | Type | When | | --- | --- | | [`thread.created`](#threadcreated) | Someone started a comment thread. | | [`thread.replied`](#threadreplied) | Someone replied in a thread. | | [`thread.resolved`](#threadresolved) | A thread was resolved, or ended with its text or suggestion. | | [`thread.reopened`](#threadreopened) | A resolved thread was reopened, or its suggestion came back. | | [`thread.message_edited`](#threadmessage_edited) | Someone changed a message they wrote. | | [`thread.message_deleted`](#threadmessage_deleted) | Someone deleted a message, or a whole thread. | | [`mention.created`](#mentioncreated) | Someone was mentioned in a comment, or in a document's text. | | [`document.created`](#documentcreated) | A document was created by an agent or through the API. | | [`document.renamed`](#documentrenamed) | A document's name changed. | | [`document.trashed`](#documenttrashed) | A document went to the trash. | | [`document.restored`](#documentrestored) | A document came back from the trash. | | [`document.deleted`](#documentdeleted) | A document was deleted for good. | | [`seal.created`](#sealcreated) | A document was sealed. | | [`seal.withdrawn`](#sealwithdrawn) | A seal was withdrawn. | | [`seal_request.created`](#seal_requestcreated) | Someone a private seal turned away asked its owners to let them read it. | | [`seal_request.accepted`](#seal_requestaccepted) | An owner let them read the document's seals. | | [`seal_request.declined`](#seal_requestdeclined) | An owner declined. | | [`agent.connected`](#agentconnected) | A person approved an agent. | | [`agent.revoked`](#agentrevoked) | An agent was removed. | `suggestion.created`, `suggestion.accepted`, `suggestion.rejected` and `checkin.missed` are reserved: an endpoint may name them, but Undertext doesn't send them yet. The examples below show `data` only; every event has the envelope above around it. ### Who to tell The thread events carry what you need to decide whom to notify without asking the API: | Field | What it is | | --- | --- | | `owners` | The document's owners, by Undertext id. | | `participants` | Everyone who wrote in the thread before this message, by Undertext id; an agent's messages count for its person. | | `suggestion_author` | For a thread on a suggestion, the person who proposed it (an agent's person, even once the agent was removed), or `null`. | | `mentions` | The people this message mentions, but its author; an agent's mention of its own person counts. | Each message carries its `author` as an actor, with the `name` it was written under (an agent's own), its plain-text `body`, and an `excerpt` of it cut to about 200 characters. ### thread.created A comment thread started, on a stretch of text (`quote`) or on a suggestion (`suggestion_id`). Mentions in its first message also send [`mention.created`](#mentioncreated). ```json { "document": "doc_8Hq2Lm4R", "thread": { "id": "thr_6Pz3", "quote": "the engine might compose elaborate pieces of music", "suggestion_id": null, "messages": [ { "id": "msg_9Xc1", "author": { "type": "person", "user": "usr_5Kq2Lm8R", "name": "Ada Lovelace" }, "body": "Is there a source for this? @Grace Hopper", "excerpt": "Is there a source for this? @Grace Hopper", "created_at": "2026-10-30T14:02:11Z" } ] }, "participants": [], "suggestion_author": null, "owners": ["usr_5Kq2Lm8R"], "mentions": ["usr_9Tb3Wc1X"] } ``` ### thread.replied `participants` is everyone who wrote in the thread before this reply. See [Who to tell](#who-to-tell). ```json { "document": "doc_8Hq2Lm4R", "thread_id": "thr_6Pz3", "message": { "id": "msg_2Vb7", "author": { "type": "agent", "agent": "agt_3Hs8", "user": "usr_5Kq2Lm8R", "name": "Claude Code" }, "body": "Menabrea's notes, 1842. I added the citation.", "excerpt": "Menabrea's notes, 1842. I added the citation.", "created_at": "2026-10-30T14:05:40Z" }, "participants": ["usr_5Kq2Lm8R", "usr_9Tb3Wc1X"], "suggestion_author": null, "owners": ["usr_5Kq2Lm8R"], "mentions": [] } ``` ### thread.resolved Sent when a thread is over, as the editor shows it among the resolved ones. `reason` says why: | `reason` | What happened | | --- | --- | | `resolved` | Someone resolved it. | | `text_deleted` | Someone deleted all of the text it was on. | | `suggestion_decided` | The suggestion it was about was accepted or rejected. | `actor` is who resolved it, or whose edit ended it. ```json { "document": "doc_8Hq2Lm4R", "thread_id": "thr_6Pz3", "reason": "resolved" } ``` ### thread.reopened Sent when someone reopens a resolved thread, including by replying in it, or when undoing brings back the suggestion a thread was about. ```json { "document": "doc_8Hq2Lm4R", "thread_id": "thr_6Pz3" } ``` ### thread.message_edited A message says something new. It carries the message as it is now, with the [fields above](#who-to-tell), `kind` (`comment` for a thread's first message, `reply` otherwise), and `newly_mentioned`: the people it mentions now and didn't before, who also get [`mention.created`](#mentioncreated). ```json { "document": "doc_8Hq2Lm4R", "thread_id": "thr_6Pz3", "message": { "id": "msg_9Xc1", "author": { "type": "person", "user": "usr_5Kq2Lm8R", "name": "Ada Lovelace" }, "body": "Is there a source for this? @Grace Hopper @Charles Babbage", "excerpt": "Is there a source for this? @Grace Hopper @Charles Babbage", "created_at": "2026-10-30T14:02:11Z" }, "kind": "comment", "participants": [], "suggestion_author": null, "owners": ["usr_5Kq2Lm8R"], "mentions": ["usr_9Tb3Wc1X", "usr_2Hd7Np4Q"], "newly_mentioned": ["usr_2Hd7Np4Q"] } ``` ### thread.message_deleted `thread_deleted` is `true` when the thread went with it, as when its first message is deleted. Remove any notification you made of it. ```json { "document": "doc_8Hq2Lm4R", "thread_id": "thr_6Pz3", "message_id": "msg_2Vb7", "thread_deleted": false } ``` ### mention.created One event per person mentioned, whether in a new thread, a reply, an edited message that newly mentions them, or the document's text. Notify `mentioned`; the actor is who wrote the mention, and `author` names them as they wrote it, an agent by its own name. Only people who may open the document are mentioned, and nobody hears of mentioning themselves, though a person hears of their own agent mentioning them. A mention of an agent sends nothing: it goes to that agent's [inbox](/reference/mcp#inbox). ```json { "document": "doc_8Hq2Lm4R", "mentioned": "usr_9Tb3Wc1X", "author": { "type": "person", "user": "usr_5Kq2Lm8R", "name": "Ada Lovelace" }, "thread_id": "thr_6Pz3", "message_id": "msg_9Xc1", "block_id": null, "excerpt": "@Grace Hopper could you check the second table?" } ``` A mention in a message has its `thread_id` and `message_id`, and its `excerpt` is the message's opening words. A mention in the text has neither, but `block_id`, the [block](/reference/mcp) it's in, and its `excerpt` is the words around it. A mention in the text is sent a minute after it's written, as the text reads then: the excerpt is the sentence as its writer finished it, and a mention taken out within that minute isn't sent at all. Mentioning someone a paragraph already mentions, or splitting, joining or moving the paragraph, sends nothing new; pasting a mention sends one. ```json { "document": "doc_8Hq2Lm4R", "mentioned": "usr_9Tb3Wc1X", "author": { "type": "agent", "agent": "agt_3Fq8Zp1L", "user": "usr_5Kq2Lm8R", "name": "Claude Code" }, "thread_id": null, "message_id": null, "block_id": "1234:5", "excerpt": "@Grace Hopper to check the second table by Friday." } ``` ### document.created Sent for documents an agent starts with `create_document`, and for those you create through the API, so your document lists stay complete either way. `data.document` is the [document object](/reference/api/documents). ```json { "document": { "id": "doc_2Mw5Rt9K", "name": null, "title": "Reading notes: Menabrea", "owners": ["usr_5Kq2Lm8R"], "link_access": "restricted", "created_at": "2026-10-30T15:11:02Z", "edited_at": "2026-10-30T15:11:02Z", "trashed_at": null } } ``` ### document.renamed `name` is `null` when someone cleared the name and the document is called by its first line again. `title` is what to show either way. ```json { "document": "doc_8Hq2Lm4R", "name": "On the Analytical Engine", "title": "On the Analytical Engine" } ``` ### document.trashed Sent when an owner moves it to the trash for everyone. A member putting it in their own trash sends nothing. ```json { "document": "doc_8Hq2Lm4R", "delete_at": "2026-11-29T15:20:00Z" } ``` ### document.restored ```json { "document": "doc_8Hq2Lm4R" } ``` ### document.deleted The document is gone for everyone, its seals are withdrawn, and no further events will name it. ```json { "document": "doc_8Hq2Lm4R" } ``` ### seal.created Sent whether the document was sealed through the API or with the editor's Seal button. `data.seal` is the [seal object](/reference/api/seals). ```json { "seal": { "code": "66G4LF343", "url": "https://seal.undertext.sh/66G4LF343", "document": "doc_8Hq2Lm4R", "version": 1, "sealed_at": "2026-10-30T16:31:00Z", "sealed_by": "usr_5Kq2Lm8R", "method": "v0.2", "line": "seal.undertext.sh/66G4LF343 · 96% typed/shaped · 2% AI · 2% external · 101 prompts · 9 sessions, 11hr2min (98% verified)", "composition": { "typed": 86, "shaped": 10, "ai": 2, "external": 2 }, "presence": { "share": 99, "verified_share": 98, "verified": false }, "prompts": 101, "sittings": 9, "duration": "11hr2min", "attested_by": { "platform": "acme", "key_ids": ["key_5Jd8Wq"] }, "withdrawn_at": null } } ``` ### seal.withdrawn The seal's page now says it was withdrawn. ```json { "code": "66G4LF343", "document": "doc_8Hq2Lm4R" } ``` ### seal_request.created Someone signed in on your seal page, whose email your [seal session](/reference/api/sessions#for-seals) vouched for, asked a private seal's owners to let them read it. The actor is the person asking. `request` says who, by that email, what they wrote (which may be empty), and the seal they asked from; `owners` are the document's owners, by Undertext id, to tell. Asking again changes the message without a new event. ```json { "document": "doc_8Hq2Lm4R", "request": { "user": "usr_7Tq4Pd2M", "email": "ben@example.com", "message": "I'm on the committee.", "seal": { "code": "66G4LF343", "url": "https://acme.com/seals/66G4LF343" }, "requested_at": "2026-11-16T10:02:00Z" }, "owners": ["usr_5Kq2Lm8R"] } ``` ### seal_request.accepted An owner, the actor, let them read the document's seals: their email is now among its readers. Tell them, with `request.seal.url`. `data` is as for `seal_request.created`, without `owners`. ### seal_request.declined An owner, the actor, declined. `data` is as for `seal_request.accepted`. The person asking isn't told, and may ask again. ### agent.connected Sent when a person approves a client they hadn't connected before; approving the same one again changes its access and sends nothing. `data.agent` is the [agent object](/reference/api/agents). ```json { "agent": { "id": "agt_3Hs8", "user": "usr_5Kq2Lm8R", "name": "Claude Code", "host": "claude.ai", "connected_at": "2026-10-30T13:40:12Z", "last_used_at": null, "access": "all" } } ``` ### agent.revoked Sent when the agent's person or your server removes it, and when its person is deleted. Its tokens no longer work. ```json { "agent_id": "agt_3Hs8", "user": "usr_5Kq2Lm8R" } ```