Falsafa
Backend API

Send message to character (SSE stream)

POST
/character/chat

Sends a user message to a character and receives a Server-Sent Events (SSE) stream of response tokens. The backend loads the character's system prompt and session data (with Redis caching), retrieves relevant context via hybrid search (Qdrant vector + TypeSense BM25), deduplicates and reranks results, then streams the LLM response token-by-token. Messages are persisted to Supabase after the stream completes.

The frontend is responsible for session lifecycle — create and delete sessions directly in Supabase. The backend only reads session data and returns 404 if the session does not exist.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

text/event-stream

application/json

application/json

curl -X POST "https://example.com/character/chat" \  -H "Content-Type: application/json" \  -d '{    "user_id": "a169451c-8525-4352-b8ca-070dd449a1a5",    "character_id": "75d2158a-b5d3-4617-be3d-6d06bd9ebb9b",    "book_id": "49cf97ac-d4b0-4fb1-a148-592152017f4d",    "session_id": "1ffd059c-17ea-40a8-8aef-70fd0307db82",    "user_message": "string"  }'
{
  "token": "string"
}
{
  "error": "string"
}
{
  "error": "string"
}