Chats
The chats API (proteus.chats) lets you create chats, read their message history, and join their realtime rooms.
Create a chat
Provide the participants you want in the chat (e.g. the agent you want to talk to). The authenticated entity is added automatically.
const chat = await proteus.chats.create({
participants: [{ id: '<agentId>', type: 'AGENT' }],
// key: 'my-stable-chat-key', // optional: create/reuse a logical chat
// title: 'Billing help',
});
console.log('chat id', chat.id);Get a chat's messages
Supports index- and cursor-based pagination.
const messages = await proteus.chats.getMessages(chat.id, { limit: 50 });
// cursor-based
const next = await proteus.chats.getMessages(chat.id, {
cursor: messages[messages.length - 1].id,
limit: 50,
});Join / leave a chat's realtime room
Join a chat to receive its messages and streamed responses in real time.
await proteus.chats.join(chat.id);
// ...later
await proteus.chats.leave(chat.id);Send a message to a chat
// string shorthand (defaults to a TEXT message)
await proteus.chats.send(chat.id, 'Hello!');
// full payload
await proteus.chats.send(chat.id, { content: 'Hello!', type: 'TEXT' });The value returned by send is your outgoing message, not the agent's reply. See Messages for receiving replies and streaming.
Listen to events scoped to a chat
proteus.chats.on filters realtime events to a single chat and returns an unsubscribe function.
const off = proteus.chats.on(chat.id, 'message', (message) => {
console.log('new message in this chat:', message.content);
});
// stop listening
off();