Context API is a small FastAPI backend for memory-backed chat. It keeps recent conversation, durable memories, and rolling summaries in SQLite, then injects only the most relevant context into each model call.
POST /chatfor authenticated chat with bounded memory retrievalPOST /rememberfor explicit memory storageGET /sessions/{id}for chat history and current rolling summaryGET /healthfor deployment checks- API-key auth backed by the database, with an environment bootstrap key for day-one setup
- Python 3.11+
- FastAPI
- SQLAlchemy + SQLite
- OpenAI
- Docker Compose for Mac mini deployment
- Clone the repo and enter it.
- Copy the environment file:
cp .env.example .env- Set at least:
CONTEXT_API_OPENAI_API_KEYCONTEXT_API_BOOTSTRAP_API_KEY
- Install dependencies:
python -m pip install -e ".[dev]"- Run the API:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000pytestcurl http://127.0.0.1:8000/healthcurl -X POST http://127.0.0.1:8000/remember \
-H "Content-Type: application/json" \
-H "X-API-Key: change-me" \
-d '{
"content": "our domain is context-api.uft1.com",
"kind": "fact",
"project_tag": "launch",
"tags": ["domain"],
"importance": 3
}'curl -X POST http://127.0.0.1:8000/chat \
-H "Content-Type: application/json" \
-H "X-API-Key: change-me" \
-d '{
"message": "What domain should I use for the API?",
"project_tag": "launch",
"title": "Launch prep"
}'const response = await fetch("https://context-api.uft1.com/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": import.meta.env.VITE_CONTEXT_API_KEY,
},
body: JSON.stringify({
message: "Continue my launch plan",
session_id,
project_tag: "launch",
}),
});
const data = await response.json();- Recent chat: only the last configured
Nmessages are considered for replay - Durable memories: explicit facts plus light heuristic extraction from user messages
- Rolling summaries: older session history is compressed once the message count passes a threshold
The prompt builder enforces separate budgets for summary, memory, and history before the final request goes to OpenAI.
git clone git@github.com:jovylle/context-api.git
cd context-api
cp .env.example .env
docker compose up -d --buildThe container listens on 127.0.0.1:8000, which is ideal for pairing with Cloudflare Tunnel.
Use a cloudflared ingress rule like this:
tunnel: your-tunnel-id
credentials-file: /Users/you/.cloudflared/your-tunnel-id.json
ingress:
- hostname: context-api.uft1.com
service: http://127.0.0.1:8000
- service: http_status:404Then run cloudflared as a persistent service on the Mac mini. Your external traffic flow becomes:
client -> Cloudflare -> context-api.uft1.com -> localhost:8000 -> Context API
- Swap SQLite for Postgres and keep the route/service shape
- Replace the simple memory ranking with embeddings later
- Add more providers behind the
LLMService - Add worker jobs and tool execution without changing the public chat contract