ChatAPI

Real-time chat infrastructure for AI-powered apps.

Go version License Release CI

Quick Start · API Reference · AI Bots · GitHub


ChatAPI is a self-hosted messaging server for apps where AI participates in conversations. It handles real-time delivery, message history, presence, typing indicators, and LLM streaming — so you focus on your product, not the plumbing.

How it fits in your stack#

Messaging#

flowchart LR
    A["User A"]
    CA["ChatAPI"]
    B["User B"]
    BE["Your Backend"]

    A -->|"send message"| CA
    CA -->|"deliver"| B
    CA -->|"message.offline"| BE
    BE -->|"email / push / SMS"| B

Users connect over WebSocket. ChatAPI stores messages, broadcasts to online room members, and fires a webhook when a recipient is offline — your backend decides how to notify them.

AI Bots#

flowchart LR
    C["Browser / Mobile"]
    CA["ChatAPI"]
    BE["Your Backend"]
    LLM["LLM Provider"]

    C <-->|"WebSocket"| CA
    CA -->|"bot.context"| BE
    BE -->|"system prompt"| CA
    CA -->|"chat/completions"| LLM
    LLM -->|"stream"| CA
    CA -->|"message.stream.*"| C

When a bot is in a room, ChatAPI calls your backend webhook to get the system prompt — your RAG pipeline, customer data, and escalation logic stay in your app. ChatAPI calls the LLM and streams tokens back to clients in real time.

Built for#

Use caseHow ChatAPI fits
In-app messagingAdd DM and group chat to any product — presence, typing indicators, and message history included
Push notification relayWebhook fires when a message arrives for an offline user — forward to FCM, APNs, email, SMS, or any channel
Customer supportBot handles tier-1 questions; human agent takes over with skip: true escalation
In-app AI assistantAdd an AI chat panel to any SaaS product — bot answers questions about your data via RAG in the webhook
Sales & lead qualificationBot qualifies leads 24/7; human rep steps in when the lead is warm
User onboardingBot guides new users through setup; escalates to a human success manager for complex accounts
Internal team AIAdd AI bots to team rooms to answer questions about docs, policies, and internal data

Features#

  • Managed AI bots — register a bot with an LLM provider URL; ChatAPI calls the model, streams tokens back via message.stream.* events, and stores the reply
  • Real-time messaging — rooms (DM or group) with presence, typing indicators, and at-least-once delivery
  • JWT auth — your backend signs tokens, ChatAPI validates them; no vendor accounts, no sessions
  • Offline delivery — messages queue for offline users; webhook fires so you can send push notifications
  • Escalation support — webhook can return {"skip": true} to silence a bot when a human agent takes over
  • Single binary — SQLite included, no external services required
  • Portable — swap SQLite → PostgreSQL or local pub/sub → Redis by implementing one interface

Documentation#