Skip to main content
Chat is the easiest Capsule surface to start with. A message handler receives a Session and a Message, then replies back to the same session.

1. Create the app

App(...) is the object capsule serve and capsule deploy read.

2. Add a message handler

Run it:
Open the preview URL and send a message.

3. Add conversation history

Most model APIs want alternating user and assistant messages. Capsule keeps the session history and can merge the current message for you:

4. Stream a reply

Use streaming when work takes longer than a single response.

Full example

Next steps