Sybil Server
Backend API for:
- LLM multiplexer (OpenAI / Anthropic / xAI (Grok))
- Personal chat database (chats/messages + LLM call log)
Stack
- Node.js + TypeScript
- Fastify (HTTP)
- Prisma + SQLite (dev)
Quick start
cp .env.example .env
npm run dev
Migrations are applied automatically on server startup (prisma migrate deploy).
Open docs: http://localhost:8787/docs
API contract docs for clients:
../docs/api/rest.md../docs/api/streaming-chat.md
Run Modes
npm run dev: runssrc/index.tswithtsxin watch mode (auto-restart on file changes). Use for local development.npm run start: runs compileddist/index.jswith Node.js (no watch mode). Use for production-like runs.
Both modes run startup checks (predev / prestart) and apply migrations at app boot.
Auth
Set ADMIN_TOKEN and send:
Authorization: Bearer <ADMIN_TOKEN>
If ADMIN_TOKEN is not set, the server runs in open mode (dev).
Env
OPENAI_API_KEYANTHROPIC_API_KEYXAI_API_KEYEXA_API_KEY
API
GET /healthGET /v1/auth/sessionGET /v1/chatsPOST /v1/chatsGET /v1/chats/:chatIdPOST /v1/chats/:chatId/messagesPOST /v1/chat-completionsPOST /v1/chat-completions/stream(SSE)GET /v1/searchesPOST /v1/searchesGET /v1/searches/:searchIdPOST /v1/searches/:searchId/runPOST /v1/searches/:searchId/run/stream(SSE)
Search runs now execute both Exa searchAndContents and Exa answer, storing:
- ranked search results (for result cards), and
- a top-level answer block + citations.
When chatId is provided to completion endpoints, you can send full conversation context. The server now stores only new non-assistant messages to avoid duplicate history rows.
POST /v1/chat-completions body example:
{
"chatId": "<optional chat id>",
"provider": "openai",
"model": "gpt-4.1-mini",
"messages": [
{"role":"system","content":"You are helpful."},
{"role":"user","content":"Say hi"}
],
"temperature": 0.2,
"maxTokens": 256
}
Next steps (planned)
- Better streaming protocol compatibility (OpenAI-style chunks + cancellation)
- Tool/function calling normalization
- User accounts + per-device API keys
- Postgres support + migrations for prod
- Attachments + embeddings + semantic search