Integration guide

Everything you need to deliver your first event: create an app, sign tokens on your server, connect clients, publish.

Concepts

  • App: your project on Columba. It has an id, an API key and a signing secret.
  • Topic: a name you choose, such as user:123; 1 to 128 characters of letters, digits and : _ - .. Apps never see each other's topics. Tokens and publish calls use the bare name (user:123); only a client's join adds the channel prefix (topic:user:123).
  • Client token: a short-lived JWT your server signs for one client, listing the topics it may join.
  • Event: one publish call: topics, an event name, a JSON payload and an optional id. Columba stores nothing; clients that are not connected miss it.

Columba stores nothing, so an event never reaches a client when its publish fails (429, 5xx or a timeout) or when the client is disconnected. Keep your own source of truth, and have clients fetch what they missed after they join or rejoin, or after a burst of events, for example with an HTTP catch-up call to your server.

Create an app

Register, confirm your email, then create an app. Columba shows the API key and the signing secret once. Store them as server-side secrets, for example COLUMBA_API_KEY and SIGNING_SECRET; never ship them to clients.

Mint client tokens

HS256 JWT signed with the signing secret. Claims: app (your app id), sub (your id for the client, 1 to 255 characters), topics (1 to 50 bare topic names, such as user:123, not topic:user:123), exp (at most 24 hours after iat, or after now when iat is absent; a token with a later exp is refused) and optional iat. Clocks may differ by up to 60 seconds.

The signing secret is the HMAC key exactly as Columba shows it: pass the string to your JWT library as is, without base64-decoding it.

Tokens are checked only when the client connects: an open socket stays connected after its token expires, and a reconnect needs a fresh token. Serve tokens from an endpoint of your server that checks its own session, and give them a short life, 5 to 15 minutes: the token travels in the WebSocket URL's query string, so proxies and CDNs may write it to their access logs.

Python
import os, time
import jwt  # pip install pyjwt

token = jwt.encode(
    {"app": "YOUR_APP_ID", "sub": "user-123", "topics": ["user:123"],
     "exp": int(time.time()) + 600},  # 10 minutes
    os.environ["SIGNING_SECRET"],
    algorithm="HS256",
)
Node
// npm install jsonwebtoken
const jwt = require("jsonwebtoken")

const token = jwt.sign(
  {app: "YOUR_APP_ID", sub: "user-123", topics: ["user:123"]},
  process.env.SIGNING_SECRET,
  {algorithm: "HS256", expiresIn: "10m"}
)
Elixir
# {:joken, "~> 2.6"}
signer = Joken.Signer.create("HS256", System.fetch_env!("SIGNING_SECRET"))
exp = System.os_time(:second) + 600  # 10 minutes

{:ok, token, _claims} =
  Joken.encode_and_sign(
    %{"app" => "YOUR_APP_ID", "sub" => "user-123", "topics" => ["user:123"], "exp" => exp},
    signer
  )

Connect

Use the Phoenix JavaScript client (npm install phoenix). The same code runs in React Native, which provides WebSocket natively. Join topic: followed by a topic listed in the token; any other join is refused with unauthorized. Clients only receive; pushes from them are refused with read_only.

Browser or React Native
import {Socket} from "phoenix"

// Your server's endpoint: checks its own session and answers {"token": "<short-lived JWT>"}.
// In React Native, use your API's full URL and send your app's own auth header instead.
async function fetchToken() {
  const res = await fetch("/columba-token", {credentials: "include"})
  if (res.status === 401) { signedOut = true; socket.disconnect() } // stop reconnecting
  if (!res.ok) throw new Error(`token endpoint answered ${res.status}`)
  return (await res.json()).token
}

let token = null
let signedOut = false
let refreshing = null
const refreshToken = () =>
  (refreshing ||= fetchToken()
    .then((fresh) => { token = fresh })
    .finally(() => { refreshing = null }))

// A function, so every connect and reconnect sends the latest token.
const socket = new Socket("wss://columba.velzmith.com/socket", {params: () => ({token})})
// A refused connect (expired token, rotated secret) is an error like a network drop:
// fetch a fresh token while the client retries with backoff.
socket.onError(() => refreshToken().catch(() => {}))
// Connect even if this first fetch failed (offline, server error): onError retries it.
refreshToken().catch(() => {}).then(() => signedOut || socket.connect())

const channel = socket.channel("topic:user:123")
channel.on("event", (event) => console.log(event.name, event.payload))
channel.join()
  .receive("ok", () => console.log("joined"))
  .receive("error", (reply) => console.error("join refused", reply))

In React Native, install the same phoenix package; it needs no polyfill. Open one socket for the whole app, for example in a module or a context provider, rather than one per screen, and call socket.disconnect() when the user signs out.

Pass params as a function, not an object: the client calls it on every connect and reconnect, so it always sends the latest token. A fixed token works until it expires, then every reconnect is refused and the client retries the same token forever.

A refused connection (expired or malformed token, rotated signing secret, disabled or deleted app, or over a socket limit) is a plain HTTP 403 with no body. Browsers and React Native do not expose the status of a failed WebSocket handshake, so the client sees it as socket.onError, the same as a network drop. Fetch a fresh token on each error; the client keeps retrying with its built-in backoff (10 ms at first, growing to every 5 seconds), and the first attempt after the fetch completes uses the new token. When your own endpoint says the user is signed out, call socket.disconnect() to stop the retries. Your account's connection limit is the one refusal you can see: the socket opens, then closes with code 4029 (connection_limit_reached).

Each event message carries id, name, payload and published_at. Deduplicate by id.

Publish

POST /api/v1/publish with Authorization: Bearer and your API key. Body: topics (1 to 100 bare topic names), event (1 to 64 characters, same alphabet as topics), payload (any JSON up to 64 KB) and optional id (a non-empty string of up to 128 bytes; Columba generates one otherwise).

Publish to the bare name, user:123, that clients join as topic:user:123. A topic starting with topic: would reach nobody, so the whole publish is refused with 400 invalid_request and fields.topics names the topic and the bare name to send.

curl
curl -X POST https://columba.velzmith.com/api/v1/publish \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"topics": ["user:123"], "event": "message.new", "payload": {"text": "hello"}}'

Errors and limits

Errors from the publish API share one JSON shape: an error object with a code to branch on, a message for people (its wording may change) and, for some codes, more fields.

429 response body
{"error": {"code": "rate_limited", "message": "over this app's publish limit; retry after retry_after seconds", "retry_after": 12}}
  • 202: accepted; the body has the event id and the number of topics.
  • 400 invalid_request: malformed JSON or an invalid field; for invalid fields, fields names each one. A topic starting with topic: is invalid: publish the bare name (Publish).
  • 401 unauthorized: missing or unknown key, or the app is disabled. A disabled app also refuses new client connections and closes its open sockets; deleting an app does the same.
  • 413 payload_too_large: payload over 64 KB.
  • 429 rate_limited: over your app's per-minute limit (600 by default, editable up to 6000), or your server's IP sent 60 requests that got a 401 in the last minute (then even a valid key gets 429 until the minute passes); wait retry_after seconds, also sent as Retry-After.

Limits on client sockets:

  • 1000 open sockets per app, and 20 per client (the token's sub). A socket counts once however many topics it joins.
  • 300 connection attempts per minute from one IP address, successful or not.
  • 4096 bytes per message a client sends; the Phoenix client's joins and heartbeats are far smaller. A larger message closes the socket.

A connection over a socket limit is refused like any other, with a plain 403 that the client sees only as socket.onError; its built-in backoff retries.

Plans and account limits

Two limits apply to your whole account, summed over all its apps: concurrent connections (open client sockets) and messages delivered per day. Apps are unlimited. Every account starts on Free; apply for Pro or Enterprise from the Plans page.

Plan Concurrent connections Messages per day
Free 200 500,000
Pro 2,000 10,000,000
Enterprise custom custom

A message is one event delivered to one connected client: 1 publish × 100 subscribers = 100 messages. A publish nobody receives counts 0, and a client subscribed to two of the topics you publish to receives the event twice and counts 2.

The message count is per UTC day and resets at 00:00 UTC for everyone. Connections are counted as they are open, at any moment.

429 daily_limit_reached: your account has delivered its daily message limit. The publish is refused before anything is sent, so nobody receives it; a publish accepted below the limit is always delivered in full, even if it takes the account past the limit. The body adds limit, used, resets_at (the next 00:00 UTC) and retry_after (seconds until then), also sent as Retry-After. Unlike rate_limited, retrying sooner does not help.

429 daily_limit_reached body
{"error": {"code": "daily_limit_reached", "message": "the account's daily message limit is reached; it resets at resets_at", "limit": 500000, "used": 500000, "resets_at": "2026-11-09T00:00:00Z", "retry_after": 3600}}

connection_limit_reached: at your account's connection limit, a new client socket opens and is then closed by the server with WebSocket close code 4029 and reason connection_limit_reached. It never joins a topic (a join sent meanwhile is answered with connection_limit_reached), receives nothing and does not count. Sockets already open stay open; new ones get in as others disconnect.

Read it in socket.onClose, as below. That is how to tell it from a bad token: a refused token, a disabled app, or a per-app, per-client or per-IP limit is still a plain 403 with no close code, seen only as socket.onError. The server holds a refused socket for about 5 seconds before closing it, and the Phoenix client then reconnects on its own, so a client at the limit retries about every 5 seconds until a place frees up. Call socket.disconnect() on 4029 if you would rather retry later yourself.

Detect the connection limit
socket.onClose(e => {
  if (e.code === 4029) {
    // connection_limit_reached: the account is at its connection limit
    showBanner("Too many connections right now; retrying")
  }
})

When your account reaches 80 % of either limit, its owner gets one email for that limit that UTC day, with the usage, when messages reset and a link to apply for more. Nothing is refused until 100 %.

Rotating keys

On the app page, rotate the API key or the signing secret. Both need a recent login and email you a notice. A rotated API key stops working at once. A rotated signing secret leaves open sockets connected and refuses new connections that use tokens signed with the old secret.

Security FAQ

What does Columba store?
A SHA-256 hash of your API key plus its first 12 characters for display, and your signing secret encrypted with AES-256-GCM. Events are never stored.
What if Columba lost its encryption key?
Signing secrets are encrypted with a key that lives only in the server's environment. If that key were lost, every app would have to rotate its signing secret; API keys would keep working. Replacing the key on purpose changes nothing for your app.
Can a client join topics it was not given?
No. Joins are checked against the token's topics, and tokens are verified with your app's secret.
How long can a token live?
Up to 24 hours from iat (or from when it is presented, without iat); a longer one is refused. For browsers and apps, mint tokens that live 5 to 15 minutes and fetch a fresh one on every reconnect, as the connect example does.
Why do browsers from any origin connect?
Mobile clients send no origin, so the socket relies on tokens instead of origin checks.