Chatbook Bot API
Chatbook is an iPhone app for chatting with bots, and anyone can make one. People find your bot in the app’s directory or by its @handle and chat with it: messages, a typing line, emoji reactions, photos. Your code talks to it over plain HTTPS, from a laptop or a server.
- The shortest bot (long polling, runs anywhere, no server)
- The shortest bot (webhook, one HTTPS function)
- Updates
- Endpoints
- Webhooks
- A bot with a brain (Claude)
- Limits
- No code at all
- Sharing a bot
Base URL: https://usechatbook.com/v1
Every request carries the bot’s token: Authorization: Bearer <token>. Get the token in the Chatbook app: My Bots → your bot → Token. Bodies are JSON. Errors are { "error": "<sentence>", "code": "<snake_case>" } with a 4xx or 5xx status.
A bot only ever talks inside a conversation a person started with it. It cannot message someone first.
The shortest bot (long polling, runs anywhere, no server)
const API = "https://usechatbook.com/v1";
const headers = { Authorization: `Bearer ${process.env.CHATBOOK_TOKEN}`, "Content-Type": "application/json" };
let after;
for (;;) {
const response = await fetch(`${API}/updates?wait=25${after === undefined ? "" : `&after=${after}`}`, { headers });
const { updates, next } = await response.json();
after = next;
for (const update of updates) {
if (update.type !== "message") continue;
await fetch(`${API}/messages`, {
method: "POST",
headers,
body: JSON.stringify({ conversation_id: update.conversation_id, text: `you said: ${update.message.text}` }),
});
}
}
Run it with CHATBOOK_TOKEN=cb_... node bot.mjs (Node 18+), then message the bot in the app.
The shortest bot (webhook, one HTTPS function)
Give the bot a webhook URL in the app (or PUT /v1/webhook). Chatbook POSTs every update to it. Answer in the response body and you never have to call the API at all:
export async function POST(request) {
const update = await request.json();
if (update.type !== "message") return Response.json({});
return Response.json({ reply: [`you said: ${update.message.text}`, "anything else?"] });
}
reply is a string or an array of up to 6 strings. Each string is one message; Chatbook shows the typing line between them.
To see a webhook bot work before writing one, set your bot’s webhook to https://usechatbook.com/examples/echo and message it.
Updates
An update is something that happened to your bot. You receive them either by long polling GET /v1/updates or at your webhook. Every update has update_id (an integer that only goes up, per bot), type, created_at (ISO 8601), and conversation_id.
message: a person sent your bot a message.
{
"update_id": 42,
"type": "message",
"created_at": "2026-09-29T21:04:11.120Z",
"conversation_id": "cnv_8k2m4x9p1q7r3s5t",
"user": { "id": "usr_1a2b3c4d5e6f7g8h", "name": "Ben" },
"message": {
"id": "msg_9z8y7x6w5v4u3t2s",
"text": "what should I eat",
"media": [{ "url": "https://…/photo.jpg", "width": 1200, "height": 900 }],
"created_at": "2026-09-29T21:04:11.101Z"
}
}
text may be empty when the message is only photos. media is always an array of images.
conversation_started: a person opened a conversation with your bot for the first time. Fields: conversation_id, user. A good moment to say hello.
reaction: a person reacted to a message with an emoji, or took the reaction back. Fields: conversation_id, user, message_id, emoji (a string such as "❤️", or null when removed).
typing: the person started or stopped typing. Off by default; turn it on with PATCH /v1/me {"typing_events": true}. Fields: conversation_id, user, typing (boolean). Treat true as stale after 10 seconds.
Ignore any type you do not recognise. New ones will be added.
Endpoints
GET /v1/updates
Long polling. Query: after (return updates with update_id greater than this; omit it to continue from where the bot last left off), wait (seconds to hold the request open when there is nothing new, 0 to 50, default 25), limit (1 to 100).
Returns { "updates": [...], "next": <number> }. Pass next as after on the following call. Passing after acknowledges everything up to it, so a bot that restarts without state and omits after picks up exactly where it stopped. Updates are kept for 48 hours.
Polling still works while a webhook is set.
POST /v1/messages
Send a message. Body: conversation_id (required), text (up to 8,000 characters), media (array of up to 10 { "url": "https://…", "width": 1200, "height": 900 }; width and height are optional but avoid layout shift). At least one of text or media.
Returns { "message": { "id", "conversation_id", "text", "media", "created_at" } }. Sending a message also marks the conversation read and clears your typing indicator.
To sound like a person, send a few short messages instead of one long one.
POST /v1/typing
Show or hide the typing line (“Sous is writing”). Body: conversation_id, typing (boolean, default true). It clears itself when you send a message or after 60 seconds.
POST /v1/read
Mark everything in the conversation as read, so your own unread counts stay right. Body: conversation_id.
POST /v1/reactions
React to a message with an emoji, or remove the reaction. Body: message_id, emoji (a string, or null to remove). A bot has one reaction per message.
GET /v1/conversations
The 200 most recently active conversations: { "conversations": [{ "id", "user": { "id", "name" }, "last_message_at", "created_at" }] }.
GET /v1/conversations/:id/messages
History, oldest first, so a stateless bot can rebuild context. Query: limit (1 to 100, default 30), before (a message id, for the page before it). Returns { "messages": [{ "id", "from": "user" | "bot", "text", "media", "reactions": [{ "from", "emoji" }], "created_at" }], "has_more": true }.
POST /v1/uploads
Host an image to send. The body is the raw image bytes with a Content-Type of image/jpeg, image/png, image/gif, image/webp or image/heic, up to 4 MB. Returns { "url": "https://…" } to use in media.
GET /v1/me
{ "bot": { "id", "handle", "name", "tagline", "avatar_url", "webhook_url", "webhook_status", "typing_events" } }. webhook_status is "ok" or the last delivery error.
PATCH /v1/me
Body: typing_events (boolean).
PUT /v1/webhook, DELETE /v1/webhook
Body for PUT: url (must be https:// and publicly reachable).
Webhooks
Chatbook POSTs each update as JSON to your URL and expects a 2xx within 10 seconds. A failed delivery is retried twice (after 1.5 s and 5 s). Whatever is never delivered stays available from GET /v1/updates for 48 hours. The latest delivery result is shown in the app and in GET /v1/me.
A 2xx to a message update shows the person “Delivered”.
Each request carries Chatbook-Timestamp (Unix seconds) and Chatbook-Signature: the hex HMAC-SHA256 of <timestamp>.<raw body> keyed with your bot token.
import crypto from "node:crypto";
function isFromChatbook(rawBody, headers, token) {
const timestamp = headers.get("chatbook-timestamp");
const expected = crypto.createHmac("sha256", token).update(`${timestamp}.${rawBody}`).digest("hex");
const given = headers.get("chatbook-signature") ?? "";
return given.length === expected.length && crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
}
A bot with a brain (Claude)
import Anthropic from "@anthropic-ai/sdk";
const API = "https://usechatbook.com/v1";
const headers = { Authorization: `Bearer ${process.env.CHATBOOK_TOKEN}`, "Content-Type": "application/json" };
const claude = new Anthropic();
const call = (path, body) => fetch(`${API}${path}`, { method: "POST", headers, body: JSON.stringify(body) });
let after;
for (;;) {
const { updates, next } = await (await fetch(`${API}/updates?wait=25${after === undefined ? "" : `&after=${after}`}`, { headers })).json();
after = next;
for (const update of updates) {
if (update.type !== "message") continue;
const conversation_id = update.conversation_id;
await call("/read", { conversation_id });
await call("/typing", { conversation_id });
const history = await (await fetch(`${API}/conversations/${conversation_id}/messages?limit=30`, { headers })).json();
const turns = history.messages
.filter((message) => message.text)
.map((message) => ({ role: message.from === "bot" ? "assistant" : "user", content: message.text }));
while (turns[0]?.role === "assistant") turns.shift();
const reply = await claude.messages.create({
model: "claude-opus-5-5",
max_tokens: 2000,
system: "You write like a person in a chat. Short lines, one thought per line, no lists.",
messages: turns,
});
const text = reply.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
for (const line of text.split("\n").filter(Boolean).slice(0, 4)) {
await call("/messages", { conversation_id, text: line });
}
}
}
Limits
- Text: 8,000 characters per message. Media: 10 images per message, 4 MB per upload.
- Updates are kept 48 hours. Long polls hold for at most 50 seconds.
- Up to 25 bots per account.
- Handles are 3 to 24 letters, numbers or underscores.
No code at all
In the app, a bot can also be “Personality”: you describe who it is in plain words and Chatbook runs it for you. Bots made that way do not use this API. Switch a bot to “Your Code” in the app to drive it yourself.
Sharing a bot
https://usechatbook.com/@<handle> opens the conversation with your bot in the app.