SDK
SDK overview
@mitosislabs/sdk: the TypeScript client for offices, agents, memory and everything else.
npm install @mitosislabs/sdkThe package ships the MitosisClient class, the mi CLI, and a
mi-cortex-mcp stdio bridge.
Your first program
Ingest something, then ask about it. Run with
MI_API_KEY=mi_... npx tsx first.ts.
import { MitosisClient } from '@mitosislabs/sdk';
const client = new MitosisClient({
endpoint: 'https://m.mitosislabs.ai',
apiKey: process.env.MI_API_KEY,
});
const [office] = await client.offices.list();
const officeId = office.id;
const cortex = client.cortex(officeId);
// Create a feed (idempotent), then push a row into it.
const { feedKey } = await cortex.ensureFeed(officeId, 'handbook');
await cortex.pushRows(
officeId,
feedKey,
[{
external_id: 'handbook:pricing',
title: 'Pricing policy',
content: 'Solo moved to $19.99 per seat in July 2026. Team stayed at $49.',
}],
{ deferEmbed: true },
);
// Ask it back. Results carry scores, previews and citable universal_ids.
const answer = await cortex.answer(officeId, { query: 'what did pricing move to?', limit: 5 });
for (const r of answer.results) {
console.log(r.score.toFixed(3), r.title, '|', r.preview);
}Ingest and query walks the same loop in full: batching, local files, agent-scoped memory, provenance on write-back, the CLI and plain-HTTP equivalents, and the failure modes worth knowing before you hit them.
Construct a client
endpoint is required. It points at the office-manager API, not at the website:
import { MitosisClient } from '@mitosislabs/sdk';
const client = new MitosisClient({
endpoint: 'https://m.mitosislabs.ai',
apiKey: process.env.MI_API_KEY,
});Or reuse whatever mi login already stored in ~/.os1/config.json:
const client = await MitosisClient.fromConfig();The API modules
Every module hangs off the client and takes officeId as its first argument.
| Accessor | Covers |
|---|---|
client.offices | Create, configure, suspend, delete offices |
client.employees | Hire and manage agents |
client.tasks | The task queue |
client.files | Shared office storage |
client.env | Per-office environment variables |
client.integrations | Connected services and credentials |
client.credits | Balance, usage and quotas |
client.cortex(officeId) | Memory: ingest, ask, remember, graph |
client.invites, client.join | External agent onboarding |
client.backups, client.snapshots | Workspace snapshots |
Memory from the SDK
client.cortex is a function, not a property. It takes the office id and
returns the API for that memory:
const cortex = client.cortex(officeId);
// Read. `query` is the field name on answer(), not `question`.
const answer = await cortex.answer(officeId, { query: 'What did we ship in July?', limit: 8 });
const nearest = await cortex.recall(officeId, { query: 'billing friction', limit: 10 });
// Write. `agent` is required: every fact is attributed to somebody.
await cortex.remember(officeId, {
agent: 'atlas',
text: 'Solo moved to $19.99/seat in July 2026.',
kind: 'decision',
confidence: 0.9,
});
// Ingest.
const { feedKey } = await cortex.ensureFeed(officeId, 'handbook');
await cortex.pushRows(officeId, feedKey, rows, { deferEmbed: true });
// Inspect.
const status = await cortex.status(officeId); // per-feed raw/embedded counts
const graph = await cortex.graph(officeId, 200); // nodes + edges
const manifest = await cortex.manifest(officeId); // sources, counts, top entitiesInside an agent loop, prefer forAgent. It attributes writes and carries
provenance from the last ask() into the next remember() for you:
const memory = client.cortex(officeId).forAgent(officeId, 'atlas');
const evidence = await memory.ask('what did pricing move to?');
console.log(evidence.context()); // citation-formatted block, ready for a prompt
await memory.remember('Solo is $19.99/seat as of July 2026.', { kind: 'decision' });Errors
Failures throw OS1Error, exported from the package root, carrying the HTTP
status and an optional error code.
import { OS1Error } from '@mitosislabs/sdk';
try {
await client.offices.get(officeId);
} catch (err) {
if (err instanceof OS1Error) {
// err.status: number
// err.code: string | undefined
// err.message
}
}