Realtime
GET /api/databases/{dbid}/subscribe streams row changes in a database as Server-Sent Events. Realtime is available on the Starter plan and above, and needs the Databases permission.
curl -N "https://api.vaultdb.io/api/databases/shop/subscribe?tables=orders,customers" \
-H "Authorization: Bearer $VAULTDB_API_KEY"
tables is optional. Without it you receive changes to every table in the database.
Events
The first event confirms the subscription:
event: connected
data: {"database":"shop","tables":["orders","customers"]}
After that, each insert, update or delete arrives as an event named insert, update or delete:
event: insert
data: {"table":"orders","data":{"customer":"ada","total":120.5},"changes":1,"timestamp":"2026-10-07T12:00:00.000Z"}
data and changes hold the same values a webhook delivery would carry for the same write. Every 30 seconds the stream also sends a comment line (: heartbeat) to keep the connection open.
Changes made through the REST API, GraphQL and CSV import produce events. Writes made with raw SQL or by a scheduled query do not.
Connecting from code
The browser's EventSource cannot send an Authorization header, so it cannot authenticate to this endpoint. Read the stream with fetch instead:
const res = await fetch('https://api.vaultdb.io/api/databases/shop/subscribe?tables=orders', {
headers: { Authorization: `Bearer ${apiKey}` }
})
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader()
let buffer = ''
for (;;) {
const { value, done } = await reader.read()
if (done) break
buffer += value
const messages = buffer.split('\n\n')
buffer = messages.pop()
for (const message of messages) {
const event = message.match(/^event: (.*)$/m)?.[1]
const data = message.match(/^data: (.*)$/m)?.[1]
if (event && data) console.log(event, JSON.parse(data))
}
}
Run this on a server, not in a browser page, so the API key stays secret.
Limits
- An account can hold at most 5 open subscriptions at once. A sixth gets
429until one closes. - Events are not stored. A change made while you are disconnected is not sent when you reconnect. To catch up, read the table with the REST API.
- If the VaultDB API runs on more than one server, a subscription receives only the changes handled by the server that holds its connection.
- If a table has
selectrow-level policies, an event carriesdataonly for an inserted row those policies let the subscriber read, judged from the values sent. Under a!=ornot_inpolicy, events on that table never carrydata. Other events on that table, including every update and delete, arrive withtable,changesandtimestamponly.