OnlyWorlds is an open standard for worldbuilding data: 22 element types (characters, locations, events, laws and the rest) that any tool can read and write. This is a typed client for its API, with the schema's constants (element types, icons, colour groups, field metadata) generated from the published schema distribution. It runs in Node 18+ and in the browser through a bundler (ESM only).
npm install @onlyworlds/sdkMoppetopia is a public demo world. Its read-only key, 0000000001, needs no account:
import { OwV2Client } from '@onlyworlds/sdk';
const client = new OwV2Client({ apiKey: '0000000001' });
console.log((await client.getWorld()).name);
const { data } = await client.list('character', { filter: { name__icontains: 'fluffington' } });
for (const c of data) console.log(' ', c.name);Moppetopia
Admiral Fluffington
Create a world at onlyworlds.com; its keys are on its world page. A new key is shown once, so copy it then.
- An
ow_r_key reads, with no PIN. It is the key to give to players or a public site. - An
ow_w_key reads and writes. Writes also send a PIN asapiPin. - Anyone who loads a web page can read the keys in its code. Ship only an
ow_r_key to a browser, and keep write keys and seat secrets on a server. - For code that writes, give it its own AI seat, a key for one tool or script. The seat's key and its
ow_s_secret (sent asapiPin) work in one world, and you can remove them without touching your account PIN.
const writer = new OwV2Client({ apiKey: 'ow_w_…', apiPin: 'ow_s_…' });const location = await writer.create('location', {
name: 'Dragon Peak',
description: 'A mountain peak where dragons nest',
}); // the id is minted client-side when omitted, so a retry creates nothing twice
const dragon = await writer.create('creature', {
name: 'Vorrath the Ember-Scaled',
location: location.id, // a single link: a UUID or null
});
const fetched = await writer.get('creature', dragon.id);
// fetched.location === location.id: a field reads the way it writes
// PATCH replaces the fields it sends; an array is replaced whole
await writer.patch('location', location.id, { supertype: 'Mountain' });
// For links, the atomic merge; it returns the updated element
const breath = await writer.create('ability', { name: 'Ember Breath' });
await writer.editLinks('creature', dragon.id, 'abilities', { add: [breath.id], remove: [] });
// Every page of a type
for await (const character of writer.listAll('character')) { /* ... */ }A link field has one name in both directions (location, not location_id). Only name is required, and an empty name is stored as ''. A world field in a payload is ignored: the key decides the world, and the client strips it anyway.
The rest of the package is below, one line each, with a link to the page that holds it in full. Every method, with the route it calls and what it returns, is in the reference.
- Bulk writes.
writer.bulk(items, { idempotencyKey })answers 200 even when some items fail, so checkres.errorsand each slot'sstatus;{ atomic: true }makes the batch all or nothing. Bulk writes - Only if unchanged. Pass the
change_seqyou read asifMatchtopatch,editLinksordelete: if someone changed the element since, nothing is written andOwPreconditionFailedErrorcarries it ascurrent. The server never merges, so send again or ask the user which to keep. Only if unchanged - Errors. Every non-2xx answer throws
OwApiError(status,code,paramanddocUrl, which is worth showing your users), and a transport failure throwsOwNetworkError. Errors
const image = await writer.uploadImage(file); // a Blob, File, ArrayBuffer or Uint8Array
await writer.patch('character', id, { image_url: image.url });- Images.
uploadImagetakes webp, png, jpeg or avif up to 15 MB and sends it straight to the upload host, which never sees your key; in a browser,preparePhoto(file)shrinks a phone photo first. Images - Removing an image.
writer.removeImage(image.url)works for the image's uploader or the world's owner; the elements that show it keep theirimage_urluntil you clear it. Removing an image - Files on elements.
uploadFile(type, id, file, { label, name, onProgress })attaches a File, Blob, ArrayBuffer or Uint8Array (a pdf, a text file, an image or a world bundle) besidelistFiles,fileDownloadLink,removeFileandworldFiles. Its refusals read aserr.isFileTooLarge,err.isFilesFullanderr.isQuotaExceeded. Files
- Sync. Poll
client.changesHead(), which reads no element, and walkclient.changesAll(cursor)from your saved cursor (opaque, and it never expires) whenheadorepochmoved. Edits to the world itself are not in the feed: comparegetWorld()'supdated_at. Follow changes - The world's own settings.
client.patchWorld(partial)writes them and takes agetWorld()body back, leaving out the keys the API does not take;originis sent assourceandproducer. The world
- Signing in.
new OwV2Client().signInWithPassword({ email, password, tokenName })turns an OnlyWorlds email (or username) and password into anow_a_account token for the device; a refusal is anOwSignInErrorwith areason. Sign in with a password - A world on the account. The account token lists the account's worlds (
listAccountWorlds()), mints keys (mintWorldKey) and makes a world with its one write key (createAccountWorld, the key shown once); an account's first world sendspin, which becomes the account PIN. A world on the account - Invite links. The owner makes, lists and revokes links with the account token (
createWorldLink,listWorldLinks,revokeWorldLink); the invited person previews the code withpreviewJoinand accepts it withacceptJoin. Invite links - Who is in a world.
client.me()says who a key is (itsmembershipis whatcreated_byholds on what it creates, andreading_aids.charteris the house rules, to read first), andclient.members()lists the roster, the owner's row with idnull. Who is in a world - Proposals. A member can
proposea change for the owner or a co-builder to accept or decline fromworldProposals(). Under the world's switch an AI seat's edit throwsOwProposedError(202) instead of writing; a person's key is never held. Proposed changes
- Search.
client.search(q, { limit })finds the elements whose name or text holds every word ofqas a whole word (APP-142is two words). There are no pages:truncatedmeans more matched thanlimit(at most 200). Search - Lookup in memory. With a world's elements in hand,
buildWorldIndex(elements)andlookupWorld(index, question)find the ones a plain question is about, with no model and no network;renderElementwrites a short text card. Find elements in a world - Ask and sort. A signed-in account can have the OnlyWorlds AI proxy answer from the elements you found (
buildAskContext, thenaccount.ai('ask', …)), or sort loose notes into rows for the user to review (account.ai('sort', …)). Proposed, hidden and room elements stay out unless you ask. Find elements in a world - The token rating. Asking and sorting spend the account's daily token rating, the same meter the Council uses;
account.allowance()reads it without spending anything, andaiUses()lists the uses the proxy runs. Ask your world - A Character's context as text.
draughtText(await client.draught(characterId))gives one Character's context packet as plain text for a prompt, the same bytes as the Python package'sdraught_text. As text
- World files.
readWorldFile(bytes)opens an.owworldfile (a zip of a world folder) in the browser or in Node, and refuses an unsafe file before returning anything, witherr.reasonon anOwWorldFileError.writeWorldFile(files, topDir)gives the same bytes for the same files; neither carries the world'sapikey. World files - What a world file leaves out. By default the writer leaves out author fields and private records and keeps hidden elements: pass
includeHidden: falsefor a share,includeAuthorFields: trueorincludePrivateRecords: truefor your own archive. Writing a world file - A folder as the source.
folderFetch(entries)from@onlyworlds/sdk/folderlets the same client read a world folder or a world file, with no account and no key. A world folder as the source - The MCP tools on a folder.
folderMcpToolsfrom@onlyworlds/sdk/mcpanswers the MCP server's read tools from a world folder, for your own MCP server to carry. The MCP tools on a world folder - A Kanka export.
convertKanka(bytes)from@onlyworlds/sdk/convertturns a Kanka JSON export into a world folder's files and a report, in memory, the same folder as the Python package's Kanka import. Kanka - A world as a folder.
worldFolderFiles(world, elements)from@onlyworlds/sdk/convertwrites a world you hold as plain objects (its record, and a list of element bodies per type) as a world folder's files, in memory, the same bytes as the Python package'swrite_folder;writeWorldFilepacks them into a world file.
These readers take a world you have read, as its viewer is served it, and give back what a tool shows.
- World calendars.
worldCalendars,resolveCalendar,formatStepandparseDateread the calendars Atlas keeps in an element'satlas_calendar(read it, never write it); with no calendar, show the bare number.@onlyworlds/sdk/calendarloads in a page with no build step. World calendars - The room.
isRoomElement(el)is true for an element of a world's chat room (one of theROOM_PAIRS, markedx_room_of); a lore view leaves those out unless the person asks. Schema constants - Reading aids.
charterOf(world, reader)reads a world's charter (its house rules), guide and domains as one reader sees them, the packetme()serves asreading_aids. Reading aids - Messages.
isMessage,senderStatus,readMarkOf,unreadForandthreadOfread a world's messages (Narratives with supertypeMessage). A sender is a claim until the server'screated_byproves it. Messages - Lenses.
resolveLens(world, lens, reader)reads a world through a saved lens (a Construct with supertypeLens) for one reader, and returns the kept ids and what was cut. Lenses - A world as a graph.
worldGraph(world, reader, options)gives one reader's nodes and edges, with room, hidden and proposed elements, map space and reading aids left out unless an option brings them back. A world as a graph - A world's own words for the types.
typeWord(world, type, { supertype, many })gives the word a world prints for a type (Employee for Character in a work world), ornullfor the standard's name. Schema constants - Addresses.
parseOwLink(text)reads an element's address in any of its three spellings andelementAddresswrites one;findOwLinksfinds every address in a text. Addresses - Names in prose.
nameFinder(elements, { case })finds a world's element names in any text, whole names only, and never writes. Names in prose - Open with.
openersFor(TOOLS, kind, address, surface)gives the rows of an Open with menu: the site first, then each listed tool, each with the words it shows when it cannot open now. Open with - The Waymark.
mountWaymarkfrom@onlyworlds/sdk/waymark, withwaymark.css, draws that menu beside a name on a web page.npm run demoin this repository serves a demo page. The Open with menu, drawn - More readers. Landing, map space, layouts, records, report threads, work items and proposed elements are on the same page. Reading worlds as a tool
- Schema constants.
ELEMENT_TYPES,ELEMENT_ICONS,FIELD_SCHEMA,elementColor,dragFieldand the rest come from the schema distribution; show a type's colour with its icon and label, never alone.SCHEMA.mdin the package describes every field, and AI agents should readAGENTS.mdfirst. Schema constants - Hidden elements. The world's owner and co-builders can
hide(type, id)an element andunhideit; only they and its creator still see it. Hidden elements - Tokens.
TokenResourcekeepsgetStatus()andgetEncryptionInfo(); itsconsume(),getAccessKey()and two session revokes are deprecated and leave in 5.0. Deprecated names - SDK or MCP. Use this SDK for known operations in your own code. To let an AI assistant that speaks MCP (the Model Context Protocol) explore a world in a chat, connect it to
https://www.onlyworlds.com/mcpwith the same key and PIN asAPI-KeyandAPI-Pinheaders. SDK or MCP? - Version 3 and the old API. 4.x speaks the current (v2) API only; the v1 client (
OnlyWorldsClient) and CommonJSrequire()stay on 3.x, which remains published. TypeScript SDK
Docs · Accounts, members and sharing · Reading worlds as a tool · Games · API reference · Migrating from 3.x · Issues · Changelog
The code is MIT (LICENSE). Issues are welcome: a bug, a wrong word, a thing you could not do. Pull requests are read; a small fix is usually taken as is, and a change to what the package does is better opened as an issue first, since it may already be built or ruled out. A reply can take a few days. A vulnerability goes privately, never in an issue: SECURITY.md. What we ask at the door, and what you can expect: the code of conduct.
Maintained by Kael, an AI agent working for Titus. Issues and pull requests are read and answered here.