Realtime in ten lines
Kumo is a realtime messaging SDK. Open a channel, publish a message, and every connected client gets it in under 50 milliseconds, anywhere on earth.
Installation #
Kumo works in the browser, Node 18+, Bun, Deno and React Native. Pick your package manager.
$ npm install @kumo/sdk
TipThe SDK is 9.4 kB gzipped and has zero dependencies. It will not slow your bundle down.
Quickstart #
- Create a client
Grab a publishable key from the dashboard. It is safe to ship in frontend code.
- Join a channel
Channels are created on first use. Name them anything, like
room:lobby. - Publish and subscribe
Every subscriber receives the message, including the sender.
import { Kumo } from '@kumo/sdk' const kumo = new Kumo({ key: 'pk_live_7c1e...', region: 'auto' })const room = kumo.channel('room:lobby') room.subscribe('message', (msg) => { console.log(msg.data.text, 'from', msg.clientId)}) await room.publish('message', { text: 'Hello from Rajshahi' })// latency p50: 38 ms, p99: 91 ms
NoteHighlighted lines are the only ones you need. The rest is your app.
Authentication #
Publishable keys can subscribe. To publish from untrusted clients, mint a short-lived token on your server with the scopes the user needs.
const token = await kumo.auth.createToken({ clientId: user.id, scopes: ['room:*:publish', 'room:*:presence'], ttl: 3600 // seconds})
WarningNever ship a secret key (sk_) to the browser. Anyone could publish as you.
Channels #
A channel is a named stream of messages. Names use colons for namespaces, and scopes can match with wildcards like room:*.
Presence #
Presence tells you who is in a channel right now. Use it for online dots, live cursors and "typing" hints.
Message history #
Channels keep the last 24 hours of messages by default. Call room.history({ limit: 50 }) to backfill a chat window.
Edge regions #
Kumo runs in 41 regions. With region: 'auto', each client connects to the closest one and messages cross the backbone, not the public internet.
publish() #
Sends a message to every subscriber of the channel. Returns when the message is stored in at least two regions.
| Parameter | Type | Description |
|---|---|---|
eventrequired | string | Event name. Subscribers filter by it. |
datarequired | object | Any JSON value up to 64 kB. |
ttl | number | Seconds to keep in history. Default 86400. |
echo | boolean | Deliver to the sender too. Default true. |
subscribe() #
Registers a listener. Returns an unsubscribe function. Reconnects and replays missed messages for you.
Try it live #
This runs against a simulated sandbox right in your browser. Change the fields and press Send.
// Response appears hereErrors #
| Code | Meaning | What to do |
|---|---|---|
401 | Missing or expired token | Mint a fresh token on your server. |
403 | Token lacks the scope | Add channel:publish to scopes. |
413 | Message over 64 kB | Send a URL to the blob instead. |
429 | Rate limit hit | Back off. The SDK retries with jitter. |