folkwaysDocs
Realtime API

Publish

The Publish frame and POST /v1/publish, every field, receipts, idempotent retries, rate limits and errors.

Publishing is one frame, Publish, sent over a WebSocket or in the body of POST /v1/publish.

The Publish frame

FieldMeaning
topic or topic_idExactly one. Use the name the first time; the numeric topic_id comes back in the receipt
nameThe event name, e.g. message; 1–64 bytes
deliveryThe event type: Durable (stream), LastValue (kv) or Ephemeral (signal). Optional when the rule fixes the name's type, see event types
payloadYour bytes, at most 60 KiB. Never parsed
content_typeA label for receivers: Bytes, Json, Text, FlatBuffers, Protobuf, MsgPack, Cbor, or 1024 and up for your own. See content types
headersUp to 16 string pairs, passed through to subscribers
idempotency_keyA 128-bit unique ID. Required for stream events; reuse it when retrying
ackDefault, NoAck, Accepted or Committed. See below
keyKV and signals: which value. Default: your identity
ttl_msKV and signals: how long the value lives
tombstoneKV: true deletes the key
client_ts_msYour clock, passed through to subscribers

Writing needs the op for the event's type in both the token and the rule: publish for stream events, set or publish for KV, signal or publish for signals.

Receipts

On success the server answers PubAck:

FieldMeaning
topic_idThe topic's numeric ID
epoch, seqThe event's cursor. seq is 0 for KV in a topic that carries several types
uidThe event's permanent ID (stream and KV)
duplicatetrue when this was a retry of an event already accepted
levelThe level reached: Accepted
server_ts_msWhen the server accepted it

No PubAck is sent when you asked for NoAck, or for a signal left at Default (signals are fire-and-forget unless you ask for Accepted). Failures always get OpError { code, message, retry_after_ms }.

Committed isn't offered: the receipt's level reports Accepted, meaning the event was accepted for delivery.

Retrying safely

Retry a stream publish with the same idempotency_key and the same content:

  • within 10 minutes you get the original receipt with duplicate: true, and it isn't delivered again;
  • the same key with different content gets IdempotencyConflict;
  • keys are scoped to your identity and the topic.

Rate limits

A publish counts against your connection's rate, the topic's and the segment's. Over any of them you get OpError { RateLimited, retry_after_ms } and nothing was published: send it again after the delay. When the segment's outbound traffic is too high, the server slows publishers with Flow frames (see flow control). A payload over the limit gets PayloadTooLarge. None of these close the connection.

A publish refused for a monthly allowance gets QuotaExceeded with retry_after_ms set to the start of the next period.

POST /v1/publish

Publishes without keeping a connection open.

HTTP
POST https://realtime.folkways.net/v1/publish
Authorization: Bearer <token>
Content-Type: application/octet-stream

<one client packet: up to 64 Publish (and Ping) frames>
BodyOne client packet of Publish frames, at most 64 KiB. No Hello: the header authenticates
Response200 with application/octet-stream: server packets, each prefixed by its length ([u32 LE length][packet]…). One PubAck or OpError per publish, matched by corr
ErrorsPer-publish failures are OpError frames inside a 200. An authentication or packet-level failure returns the code's HTTP status and a body with one Close frame
CORSAny origin; preflight allows POST with Authorization and Content-Type, cached 24 hours. No cookies

Subscribe isn't accepted here (UnsupportedFrame); receive with POST /v1/poll or a WebSocket.

Errors

CodeWhen
ForbiddenNo rule matches the topic, or the token or rule doesn't allow the op. The same answer for both
InvalidTopicThe name isn't a valid topic name
ClassMismatchThe event type isn't allowed for this name or topic
IdempotencyKeyRequiredA stream publish without an idempotency key
IdempotencyConflictThe key was used with different content
PayloadTooLargeThe payload is over the limit
RateLimitedA rate limit was hit; retry after retry_after_ms
QuotaExceededA monthly allowance or cap is used up, or the topic limit is reached

All codes: Error codes.

On this page