You will learn#
- where the API is and how to authenticate in local mode and in network mode
- the conventions every operation shares: revisions, pages, retries and errors
- how to read an operation page and run its request in your language
The idea#
The HTTP API is the editor's own interface. The browser editor, the CLI and the MCP server call the same service, so a request here does exactly what the same action does in the editor. Every operation has a page in this section, grouped by resource in the sidebar, with its parameters, its body, its responses and a request you can copy in eight languages.
The pages are generated from the OpenAPI document that the server itself serves, so a route, a field or a status never drifts from the program. The document is at GET /openapi.json while stuarty serve runs. Like every other route it needs the Authorization: Bearer <token> header; without it the answer is 401 E_UNAUTHORIZED. It has no servers member: the paths resolve against the address the document was fetched from.
Quick start#
Start the server
stuarty serveThe server listens on 127.0.0.1:7878 unless STUARTY_ADDR says otherwise. The API lives under /api/v1.
Read the token
In local mode the server creates a random token in the workspace, in the file token. Put it in a variable:
export STUARTY_KEY="$(cat ~/.stuarty/token)"Make a request
curl -X POST "http://127.0.0.1:7878/api/v1/projects" \
-H "Authorization: Bearer $STUARTY_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Launch teaser",
"description": "A 30 second vertical video for the people who follow the channel.",
"goal": {"specific": "Publish one video that explains the idea",
"measurable": "One hundred views in the first week",
"achievable": "The footage and the script exist",
"relevant": "It brings the first audience",
"time_bound": "Edit on Monday, publish on Tuesday",
"due": "2027-03-31"}}'The answer is 201 Created with the id of the new project. A project has a name, a description and a goal, and no timeline yet: add one with POST /api/v1/projects/{id}/items (Projects). Open the same project in the editor to see it.
Authentication#
Every operation takes the secret in one header:
Authorization: Bearer <secret>| Mode | The secret | Where it comes from |
|---|---|---|
| Local | the local token | the file token in the workspace |
| Network | an API key | created in the editor or with POST /api/v1/keys; see API keys and scopes |
A request with a header that is not valid is refused with 401; it never falls back to a session cookie. The browser editor uses a cookie, which scripts do not need. A token or key is accepted only in a header, never in a URL.
An API key has scopes (read, edit, media, render, admin, and posts:read, which reads the posts of the read API of the blog and nothing else) and each operation page says which one it needs. The local token has every scope, with one exception: emptying the trash for good (POST /trash/empty) and installing the transcription helper (POST /system/tools/install) answer 403 E_FORBIDDEN to it, because only a person in the browser or an admin key may do them. The local and network mode page explains the two modes.
Name your client#
The optional header Stuarty-Client names the actor of your edits, so the history shows who did what. It takes 1 to 32 characters from a-z, 0-9 and -, and not ui. The actor is then local:<label>; without the header it is local:api.
Conventions#
- Revisions. A project has a revision that grows with every committed batch. An edit sends the
base_revisionit was planned against. If the project moved on, the batch is replayed on the newer revision unless it touches objects another actor changed; then it fails withE_REVISION_CONFLICTand changes nothing, so read again and retry. See Batches, revisions and idempotency. - Retries. An edit may carry an
idempotency_key(8 to 64 characters), or the same value in theIdempotency-Keyheader. A repeated key with the same batch returns the first result. - Dry runs. Operations that change something accept
dry_run: trueand check without changing. - Pages. A list takes
cursorandlimitand answers withnext_cursor; pass it back ascursorfor the next page. It isnullon the last page. - Times. A time is a string with a unit, such as
12.5s,375for00:00:12.500. - Long work. Imports, exports and transcriptions are jobs. The call returns
202 Acceptedwith the job; read it with the jobs operations or follow the events stream.
Errors#
An error is application/problem+json with code, message, hint and retryable, and the HTTP status of the code:
{
"status": 401,
"code": "E_UNAUTHORIZED",
"message": "the request carries no credentials.",
"hint": "send the local token as Authorization: Bearer <token>, or run `stuarty open` to open the editor in a browser",
"retryable": false
}When retryable is true, a later retry can succeed. The error codes page lists every code and its status.
Read an operation page#
Each page has two columns. On the left: what the operation does, the authentication, the parameters, the request body and the responses. On the right: the same request in curl, Python, JavaScript, Go, PHP, Java, C# and Ruby, and an example of each response.
The samples read the secret from the environment variable STUARTY_KEY and use the default address. Replace placeholders such as PROJECT_ID with real ids. The response examples are built from the schemas, so a value is a placeholder of its type; the tables hold the real fields.
Common mistakes#
- Sending the token as a query parameter or in a cookie from a script: only the
Authorizationheader works for scripts. - Editing with a stale
base_revision: read the project first withGET /api/v1/projects/{id}and use its revision. - Reading a
202as done: the work runs in a job; wait for it before you use the result.
Next steps#
- All endpoints
- The schemas
- The MCP server, for agents
- Error codes