Messages on a stored channel can be read back later. History is what lets a chat client fill in the backlog on load, and what the SDK uses internally to backfill gaps after a reconnect.
What gets stored
Whether a channel stores messages is decided by its channel rule. By default chat: channels store everything and other channels are live-only, keeping messages only for the short window reconnecting clients use to heal gaps. Add a persist-all rule for any prefix that needs a readable backlog.
Retention
How long stored messages stay readable is capped by your plan, 24 hours on Free and 30 days on every paid plan, and can be shortened per prefix in the channel rule. Messages published with ephemeral: true are never stored, whatever the rule says.
Fetch from the realtime SDK
const result = await channel.history({ limit: 50 });
for (const message of result.messages) {
console.log(message.timestamp, message.name, message.data);
}
Messages come back oldest first. result.more tells you older messages exist beyond the page, and you can pass the oldest serial you have (seq on each message) as the before cursor to page backward:
const older = await channel.history({ limit: 50, before: result.messages[0]?.seq });
The default page size is 100 and the service caps how much one request returns.
Fetch over REST
The REST client returns newest-first pages with built-in pagination:
import { Rest } from '@foony/realtime';
const rest = new Rest({ key: process.env.FOONY_API_KEY! });
let page = await rest.channels.get('chat:lobby').history({ limit: 100 });
while (true) {
render(page.items);
if (page.isLast()) {
break;
}
page = await page.next();
}
Capabilities
Reading history requires the history operation on the channel. Tokens minted before this operation existed and dashboards that only granted subscribe will get error 40301, so include history in the capability when clients need backlog. See Auth and capabilities.