SpaceMIX API
The server's public HTTP API, /api/v1, for scripts and other services: its on/off switch, API keys and their eight scopes, every route with its scope, body, response and status codes, the server's MCP connection tools, how actions are relayed to an open SpaceMIX client, the server-side assistant and its streaming format, events and notifications from source api, and the limits.
The SpaceMIX API lets a script, a CI job or another service use a SpaceMIX server without a person signing in. It calls the same extension tools the assistant has (Team Chat included: it is an extension, reached through its tools like any other) and the tools of the server's MCP connections, talks to the assistant, emits and reads events, and sends notifications. Every request carries an API key and acts as the person who made the key, limited to the scopes they picked.
The API is the server's surface, not the extension contract: extensions never call it, and it is versioned by its /api/v1 prefix. The routes live in apps/desktop/src-tauri/src/api.rs, keys in api_keys.rs, tools in tools.rs and tool_runs.rs, MCP connections in mcp.rs, the assistant in assistant.rs.
curl -s https://spacemix.example.com/api/v1/me \
-H "Authorization: Bearer opk_k1a2b3c4d5e6f_0123456789abcdef0123456789abcdef"
Switching the API on
The API is off on a new server. While it is off, every /api/v1 request, GET /api/v1/me included, is answered 403 { "error": "The SpaceMIX API is switched off on this server." } before its key is looked at.
- Switch it on or off in Settings → API, on the SpaceMIX API card. Only people with the
server:settingspermission may (see Permissions); for anyone else the switch is disabled, and the server refuses the write withOnly people who may change server settings can switch the API on or off. - The switch is the kv key
shell/apiEnabled. The API is on only when it holds JSONtrue; absent, any other value, or a store that can't be read is off (enabledinapps/desktop/src-tauri/src/api.rs, the permission check incheck_kv_writeinserver.rs). - Switching off takes effect at once: new requests get the
403above, an openevents/streamends, and a running assistant turn stops with the403as its reply (api_switched_offinassistant.rswatches the change feed forshell/apiEnabled; the 30-second key check is only a fallback). - A relayed action or MCP tool run that an open client had already picked up when the switch flipped finishes in that client, but its result is not returned to the caller:
POST /api/v1/tools/<name>answers the403instead. - Keys are kept while the API is off, and can still be made, listed and revoked in Settings → API. They work again once it is switched on.
Keys
Make a key in Settings → API in the SpaceMIX app. Give it a name and pick its scopes; the token is shown once, when the key is made. The page also shows the base URL to call: the server's Public address if one is set in Settings, else the address this device reaches the server at, followed by /api/v1.
- A token looks like
opk_<id>_<secret>:<id>iskplus 12 hex characters,<secret>is 32 hex characters. The server keeps only its SHA-256 and the first 12 characters (prefix), to tell keys apart. - A key belongs to one account and acts as that account. Within its scopes it has every right the account has: it sees only the extensions the account may use (see Who can use an extension), and an owner's key acts as the owner.
- Each person manages their own keys. The owner sees and may revoke everyone's.
- A key stops working when it is revoked or its account is removed. Open event streams and running assistant turns notice within 30 seconds.
- At most 50 keys per account, a name of 1 to 80 characters on one line, and at least one scope.
The app's Settings page manages keys through the session routes POST /api/api-keys/list, POST /api/api-keys/create ({ name, scopes }, answers { key, token }) and POST /api/api-keys/revoke ({ id }). These need a signed-in session; an API key can't make or revoke keys.
Scopes
Four areas, each with a read and a write scope. Each scope is picked on its own: a :write scope does not include its :read.
| Area | Scope | Allows |
|---|---|---|
| Extensions | tools:read |
GET /api/v1/tools; running read-only tools (collection list/get, actions declared readOnly, MCP connection tools an admin marked read-only); read-only tools for the assistant. |
| Extensions | tools:write |
Running every other tool, MCP tools included, without approval; every tool for the assistant. |
| Assistant | assistant:read |
Listing and reading the account's own chats; listing its projects. |
| Assistant | assistant:write |
Making chats and sending messages to the assistant. |
| Events | events:read |
events/list and events/stream: every event in the team's log, payloads included. |
| Events | events:write |
events/emit, from source api. |
| Notifications | notifications:read |
The account's own notification center. |
| Notifications | notifications:write |
Sending notifications from source api. |
Requests and errors
- Send the key as
Authorization: Bearer <token>. Nothing else carries a key: no cookies, no query parameter. Every other/apiroute ignores keys and stays session-only. - Routes that take a JSON body through
POSTneedContent-Type: application/jsonand a body ({}when there is nothing to say), excepttools/<name>and theassistant/*routes, which read the raw body and take an empty one as{}. - Any origin may call the API (CORS without credentials), so a browser can too; a token in a web page is readable by everyone who loads it.
Errors from SpaceMIX are JSON, { "error": "<message>" }:
| Status | When |
|---|---|
401 |
No key, a malformed one, or one that is revoked or whose account is gone: Invalid API key. |
403 |
The API is switched off on this server: The SpaceMIX API is switched off on this server. (checked first, before the key; see Switching the API on). Or the key lacks the route's scope: This key lacks the scope <scope>. |
404 |
An unknown tool, chat or project. |
400 |
The request is wrong; the message says how. |
500 |
Something went wrong on the server. The real error is only in the server's log. |
A body the server can't parse on the routes that take JSON is answered by the HTTP framework with 400, 415 or 422 and a plain-text message.
Who the key is
GET /api/v1/me, no scope. Answers { user, key }: user is the account (id, firstName, lastName, email, role, createdAt, groups, permissions, effective, createGated) and key is the key as Settings shows it (id, name, prefix, scopes, userId, userName, createdAt, lastUsedAt). lastUsedAt is updated at most once a minute. createGated is true: this server enforces server:extensions and server:widgets for creating.
Tools
The same extension tools the assistant gets in the app, by the same names, schemas and validation (see Giving the assistant data and Tools), and the tools of the MCP connections the account may use (mcp:<id> or mcp:*).
GET /api/v1/tools
Scope tools:read. Answers { tools: [...] }, one entry per collection and action tool of the extensions the account may use, then one per tool of the MCP connections the account may use that are turned on:
| Field | Type | Meaning |
|---|---|---|
name |
string | The tool name: <ns>_<collection>_<op>, <ns>_<action>, or <connection id>_<tool> for an MCP connection's. |
title |
string | Short label. |
description |
string | What it does, for a model. |
inputSchema |
object | The arguments' JSON schema, with the manifest's key order and options form hints. |
extensionId |
string | The extension it belongs to. Absent on an MCP connection's tool. |
connectionId |
string | Only on an MCP connection's tool: the connection's id. |
requiresApproval |
boolean | What the app's assistant would ask about. Reported only: the API never asks. |
readOnly |
boolean | true for collection list/get, actions declared readOnly, and MCP connection tools someone with server:settings marked read-only (readOnlyTools; the MCP server's own hints don't count). |
kind |
"collection", "action" or "mcp" |
Where it runs: collection tools and MCP connection tools on the server, actions in a SpaceMIX client (below). |
An MCP connection's tools are listed and run by this server, which lists each connection at most every 5 minutes; a connection that can't be listed is left out. A connection tool whose name is taken, or is under the namespace of an extension that may have MCP tools, is left out, as in the app's chat (see MCP connections). A member's build comes after the connections and loses every clash.
An extension's own MCP tools are not listed: only a SpaceMIX client can list an extension's MCP servers. They can still be called by name (below).
Team Chat is the Chat extension (ai.spacemix.chat), not a part of the API of its own: an integration reads and posts in it through the extension's tools (chat_conversations, chat_history, chat_send, chat_react, chat_create_channel, …), the read-only ones under tools:read and the rest under tools:write. They are actions, so like every extension's actions they are relayed to one of the key owner's open SpaceMIX clients (below).
POST /api/v1/tools/<name>
Runs one tool as the key's account. The body is the tool's arguments as a JSON object (empty: {}), at most 256 KB.
- A read-only tool needs
tools:read. Every other tool, and any name that isn't in the list (possibly an extension's MCP tool), needstools:write. - Arguments are validated against the tool's schema before anything runs: undeclared fields are refused,
requiredis enforced, common slips are coerced. An MCP connection's tool is the exception: its arguments go to the MCP server as sent, checked only to be an object, and the MCP server checks them. - Nobody is asked for approval, whatever
requiresApprovalsays: the scope is that decision.
curl -s -X POST https://spacemix.example.com/api/v1/tools/tasks_items_create \
-H "Authorization: Bearer $SPACEMIX_KEY" \
-d '{"title":"Renew the certificate"}'
| Status | Body | When |
|---|---|---|
200 |
{ "result": <value> } |
The tool ran. <value> is what the assistant would get. |
422 |
{ "error": "<message>" } |
The tool itself failed: bad arguments, a missing record, an action that threw, an MCP connection that failed or answered isError, or a result whose only field is a string error. Also an action relayed to a client that doesn't have the extension yet: The SpaceMIX client that took the call doesn't have <tool> yet; try again. |
400 |
{ "error": … } |
The body isn't JSON. |
413 |
plain text | The body is over 256 KB; the server's body limit refuses it before the tool is looked up. |
403 |
{ "error": … } |
The key lacks the scope this tool needs. |
404 |
{ "error": "There's no tool \"<name>\". Similar: a, b." } |
No such tool for this account (… List the tools to see them. when nothing is similar). A key with only tools:read gets 403 for an unknown name instead, because the scope check runs first and an unknown name needs tools:write. |
503 |
{ "error": "No SpaceMIX client is open for <name>. …" } |
An action or an extension's MCP tool, and none of the person's SpaceMIX windows or browser tabs is open. |
504 |
{ "error": "<name>'s SpaceMIX client didn't finish <tool> within 90 seconds; it may still have run." } |
The client took the call and didn't answer in time. |
429 |
{ "error": … } |
Too many relayed calls of this person's are waiting, or were started in the last minute. |
Actions run in a SpaceMIX client
Collection tools run entirely on the server, against the record store, and record their <collection>_created, _updated and _deleted events as in the app. MCP connection tools run on the server too: it makes the request to the MCP server itself. Actions and an extension's MCP tools are JavaScript in the extension's sandboxed frame, so the server can't run them itself. It relays the call to one of the key owner's open SpaceMIX clients (the desktop app or a browser tab signed in as that person):
- The server announces the run to that person's clients only, without the arguments.
- The first client to claim it within 5 seconds gets the call. Nobody claims:
503, at once. - The client runs the action in its frame (the action's own limit is the host's 60 seconds, see Actions) and posts the result back. No answer within 90 seconds:
504.
A 504 does not mean the action didn't run: it may have finished after the server stopped waiting. Retry only actions that are safe to run twice.
The action receives ctx.via = { extension: "ai.spacemix.api", extensionName: "SpaceMIX API", label: "<key name>" } (see ctx.via). An extension's MCP tool is relayed only when its name starts with the namespace of an installed extension that has a net: permission, that the account may use and that is not turned off; a client that doesn't find it makes it a 404.
Assistant
The assistant runs on the server: an integration sends a message and the whole turn (the model call, the tool loop, saving every message) runs there, with no SpaceMIX client open. The chats are the account's own chats, in the same tables as the app's: a chat made through the API shows in the app's chat list, and a chat started in the app can be continued through the API. A reply being written shows live in an open window.
How a turn runs:
- Model. The chat's pinned model, else the server's default connected model (Settings → Models). With none connected,
409No model connected yet. Open Settings → Models to connect one.An OpenAI-compatible model runs the tool loop on the server; a CLI agent runs one turn with SpaceMIX's tools on its bridge. A SpaceMIX Hub model runs the same loop through SpaceMIX Hub, billed to the server's credit, and only for an account withserver:hubModels: without it the message is refused with403You don't have permission to use SpaceMIX Hub models on this server. Ask someone who manages members.before the turn starts. - Tools follow the
tools:*scopes. The model gets the account's extension tools and the tools of the MCP connections it may use. Withouttools:readortools:writeit gets no tools. Withtools:readit gets only read-only ones (for an MCP connection, only the tools marked read-only). Withtools:writeit gets all of them. Nobody is asked to approve a call, ever: the scope is that decision, and the system prompt tells the model so. Actions are relayed as above, withctx.vianaming the key. - Tools on demand. An OpenAI-compatible model (a SpaceMIX Hub model too) isn't sent every tool on every call. The system prompt has the catalogue of the tool groups the key allows, one line per extension and per MCP connection; each call carries
tools_load,tool_result_readand thematerial_*tools, then the groups of the extensions the chat's project links to, then the groups the chat loaded, each group's tools sorted by name.tools_loadadds groups from the next call on, calling a tool whose group isn't loaded loads it and runs it, and the loaded groups stay on the chat (fieldtoolGroups, at most 12), shared with the app. A CLI agent gets every tool the key allows at once, plustool_result_readand thematerial_*tools. The rules, the same as the app's, are in How the assistant gets its tools (apps/desktop/src-tauri/src/assistant.rs,tools.rs).GET /api/v1/toolsstill lists every tool. - Long results. Each tool result is stored on its message whole, up to 256 KB, and at most 1 MB of one turn's results are stored whole (past it, a long result keeps only its structured view). The model gets it whole in the turn that made it, or a structured view when it is over 12,000 characters, and a digest in later turns when it is over 1,500;
tool_result_readreads past either. See What the model sees of tool results (apps/desktop/src-tauri/src/tool_results.rs). - Materials. The tables in an extension's or connection's result become the chat's materials, listed at the end of the system prompt and read with
material_query, as in the app.material_refreshruns only a read-only tool the key still gives the model. See Materials (apps/desktop/src-tauri/src/materials.rs). - What's not there. SpaceMIX's own client-side tools (
widget_*,dashboard_*,extension_*andproject_*) don't exist on the server and aren't offered. Studio chats (a widget's or an extension's) can be read but not sent to:409. - Projects. In a chat inside a project, the prompt names the project, its instructions and its linked items, as in the app; a linked record's read tool is named only when the key gives the model that tool. See Projects.
- The system prompt is the app's (
apps/desktop/prompts/), plus a paragraph saying the message comes through the SpaceMIX API from a program connected with the named key and that nobody is looking at a screen. - One turn per chat at a time: a second is refused with
409This chat is already replying., not queued. A reply the app is writing in a window doesn't hold the chat. - A turn stops after 25 tool steps (
MAX_STEPSinapps/desktop/src-tauri/src/assistant.rs, with the noticeStopped after 25 tool steps. Send another message to let it continue.in the chat), after 10 minutes, when the caller disconnects, or when the key is revoked. Tools still running are then marked interrupted.
GET /api/v1/assistant/chats
Scope assistant:read. Answers { chats: [...] }, latest activity first. Studio chats are left out unless ?all=1. A chat is { id, title, renamed?, projectId?, modelId?, model?, widget?, extension?, createdAt, updatedAt } (milliseconds).
POST /api/v1/assistant/chats
Scope assistant:write. Body { title?, projectId? }. Makes an empty chat and answers { chat }. A given title (at most 200 characters, whitespace collapsed) counts as the person's own name for the chat, so the first message doesn't retitle it. An unknown projectId is 404 There's no project with that id.
GET /api/v1/assistant/chats/<id>
Scope assistant:read. Answers { chat, messages, materials }. A message is { id, role, text, error?, toolCalls?, tool?, stats?, createdAt }; role is user, assistant, tool or notice. A tool message's tool has callId, name, title, args, status and, once it ran, result: the result as stored, at most 256 KB (see Long results). materials are the chat's materials, pinned first, then newest, each { id, name, source, rows, columns, fetchedAt, pinned }: id is its id in the chat (M3), source is { kind, tool?, args?, callId?, messageId?, originMessageId?, path?, from?, query?, file? } (originMessageId is the tool message that first made the material, kept across refreshes) with kind tool, query or user, rows its row count, columns [{ name, type }], fetchedAt in milliseconds; an empty list for a chat without any. The rows themselves aren't in the answer. Another person's chat id is 404 There's no chat with that id.
GET /api/v1/assistant/projects
Scope assistant:read. Answers { projects: [{ id, name }] } in the app's order, for projectId.
POST /api/v1/assistant/chats/<id>/messages and POST /api/v1/assistant/messages
Scope assistant:write. Body { text } for a chat by id, or { text, chatId? } on /assistant/messages, which makes a new chat without chatId. text is 1 to 100,000 characters after trimming; the body is at most 512 KB. A new chat takes its title from the first message.
Without ?stream=1 the response comes when the turn is done:
| Status | Body | When |
|---|---|---|
200 |
{ chat, reply, messages } |
The turn finished. reply is the last assistant message, { id, text, error? }; messages is every message this turn added, the user's first. |
502 |
{ chat, reply, messages, error } |
The model call failed. error (also the reply's text) gives only the HTTP status or that the model was out of reach, never its address or the provider's body. For a SpaceMIX Hub model it is SpaceMIX Hub's own sentence instead, such as This server's SpaceMIX Hub credit is used up. Someone who manages settings can top it up in Settings → Models. (see Errors). |
504 |
{ chat, reply, messages, error } |
The turn ran out of time (10 minutes). |
401 |
{ chat, reply, messages, error } |
The key was revoked during the turn: Stopped: the API key was revoked. |
403 |
{ chat, reply, messages, error } |
The API was switched off during the turn: The SpaceMIX API is switched off on this server. |
403 |
{ error } |
The chat's model is a SpaceMIX Hub model and the key's account lacks server:hubModels. |
400 |
{ error } |
Give the message some text., Keep a message under 100000 characters., or a body that isn't a JSON object. |
404 |
{ error } |
No such chat. |
409 |
{ error } |
The chat is already replying, no model is connected, or it's a Studio chat. |
429 |
{ error } |
Too many assistant turns are running. |
A turn may take minutes, and a reverse proxy in front of the server may cut a long silent response. Use ?stream=1 for anything but short questions.
curl -s -X POST https://spacemix.example.com/api/v1/assistant/messages \
-H "Authorization: Bearer $SPACEMIX_KEY" \
-d '{"text":"Which tasks are due this week?"}'
Streaming
With ?stream=1 the response is application/x-ndjson: one JSON object per line, as the turn happens. Errors found before the turn starts (400, 404, 409, 429) are still ordinary responses with a status.
type |
Fields | Meaning |
|---|---|---|
delta |
text |
More of the reply's text. |
toolCall |
id, name, arguments |
The model calls a tool; arguments is the JSON string it wrote. |
toolResult |
id, status (done or error), result |
The tool's result as the model gets it, a string: the result itself, or its structured view when it is over 12,000 characters. The whole result is on the tool message in messages. |
done |
chat, reply, messages |
The last line of a turn that finished. |
error |
message, and chat, reply, messages when the turn had started |
The last line of a turn that failed or was stopped. |
curl -sN -X POST "https://spacemix.example.com/api/v1/assistant/chats/$CHAT/messages?stream=1" \
-H "Authorization: Bearer $SPACEMIX_KEY" \
-d '{"text":"Summarise the open support tickets."}'
Closing the connection stops the turn.
Events
POST /api/v1/events/emit
Scope events:write. Body { type, payload?, summary?, target? }; answers the event as stored (SpacemixEvent). An event from the API never speaks for an extension:
- Its
sourceis alwaysapi. Leavesourceout (or send"api"); any other value is400Through the API the source is always "api", not "<source>"; leave it out.So a key can't trigger an automation listening for an extension's events. typeis free, but snake_case like any event's: a lowercase letter first, then lowercase letters, digits and_, at most 64 characters.payloadis any object, not checked against a schema, at most 16 KB as JSON. Itsviafield is set to{ "apiKey": "<key name>" }, replacing anyviayou sent.summary: one line, at most 280 characters after cleaning;target: at most 512 characters, no control characters.byis the key's account.
POST /api/v1/events/list
Scope events:read. Body: an EventQuery, { source?, type?, after?, before?, limit? } (send {} for the latest). Answers an array of events, newest first; limit defaults to 50, at most 500. The log is the team's: every extension's events and every key's. Retention and paging are as in host.events.list.
GET /api/v1/events/stream
Scope events:read. Server-sent events: one event event per new event recorded, its data the event as JSON. A client that falls too far behind gets a resync event and should catch up with events/list. At most 5 open streams per key (another is 429 Too many open streams for this key.). Every 30 seconds the stream checks that its key and account still exist, and ends when either is gone. It ends at once when the API is switched off.
curl -sN https://spacemix.example.com/api/v1/events/stream -H "Authorization: Bearer $SPACEMIX_KEY"
Notifications
GET /api/v1/notifications
Scope notifications:read. Answers the key's account's own notification center as an array, newest first: { id, source, kind, text, target, from, createdAt, read }.
POST /api/v1/notifications/send
Scope notifications:write. Body { text, target?, to? }; answers { sent }.
- The
sourceis alwaysapi, with no kind (akindin the body is ignored; asourceother than"api"is400).fromis the key's account. textfollows the notification rules: one line of plain text, 1 to 280 characters after cleaning.target: at most 512 characters. It is kept on the notification for API callers to read back; the app can't open anything with it.to: 1 to 50 account ids (the key's own isuser.idfrom/me). Omit it to notify only the key's account.
In the app the notification shows under the name API. It isn't an extension's: clicking it only marks it read, and no extension's markRead touches it. See Notifications.
Limits
| What | Limit |
|---|---|
| Keys per account | 50 |
| Key name | 1 to 80 characters, one line |
tools/<name> body |
256 KB |
| Relayed call: claimed by a client | within 5 seconds, else 503 |
| Relayed call: answered | within 90 seconds, else 504 |
| Relayed calls waiting, per person | 16, else 429 |
| Relayed calls started, per person | 60 a minute, else 429 |
| An action in its frame | 60 seconds (the host's) |
| Assistant message | 1 to 100,000 characters; body at most 512 KB |
| Assistant chat title | 200 characters |
| Assistant turns at once | 3 per key, 3 per account, 16 per server, else 429 |
| Assistant turn | 10 minutes, 25 tool steps |
| Turns per chat | 1 at a time, else 409 |
| Event streams | 5 per key, key checked every 30 seconds |
| Event payload / summary / target | 16 KB / 280 characters / 512 characters |
| Notification text / target / recipients | 280 characters / 512 characters / 50 |
How the API differs from the app
- No approval prompts. A
tools:writekey runs tools declaredrequiresApproval(and collection operations inrequireApproval) without asking anyone. Give a keytools:writeonly where that is what you want. - An extension's MCP tools are callable but not listed.
GET /api/v1/toolslists collection and action tools and the MCP connections' tools, not the MCP tools an extension'smcp(host)returns. - MCP connection tools never ask. In the app's chat a connection tool not marked read-only asks first (unless the connection runs without asking); through the API the key's scope decides:
tools:readruns only the ones marked read-only,tools:writeall of them. - Tool names aren't filtered against SpaceMIX's own. In the app, an extension tool with the exact name of one of SpaceMIX's own tools is left out of chats; the API has none of those tools, so it lists and runs such a tool.
- Owner keys act as the owner, with every right the owner has within the key's scopes.
- Actions need an open client. Collection tools, MCP connection tools and the assistant work with nobody signed in; actions and an extension's MCP tools need one of the person's SpaceMIX windows open.
Stability
Experimental: new, and not yet exercised by many integrations. The routes, scopes and shapes above are expected to stay under /api/v1; limits may change.