Oouhammmourachid /
Public
ouhammmourachid / ai-chat-history
PublicStore conversations and messages for your LLM app: per-user history, auto titles, token usage, and an endpoint that returns messages ready to send to any LLM API.
- Other
- 0 deploys
- 0 forks
AI Chat History for LLM apps
Store conversations and messages for your LLM app: per-user history, auto titles, token usage, and an endpoint that returns messages ready to send to any LLM API.
What you get
- Conversations and messages per user, with system prompt and model
- Conversations are titled from the first user message
- Token usage per message, summed at
GET /api/conversations/{id}/usage GET /api/conversations/{id}/llmreturns{ system, model, messages: [{ role, content }] }- Messages are append-only (no edits), so history stays trustworthy
- Provider-agnostic: works with Claude, OpenAI, Gemini or local models
Collections
conversations
| Field | Type | Notes |
|---|---|---|
title | text | Auto-filled from the first message |
user (required) | relation → users | Set by a hook to the signed-in user |
model | text | e.g. the model id you call |
system_prompt | text | |
archived | bool | |
last_message_at | date | Set automatically |
| Action | Who can do it |
|---|---|
| List / view | user = @request.auth.id |
| Create | signed-in users |
| Update | user = @request.auth.id |
| Delete | user = @request.auth.id |
messages
| Field | Type | Notes |
|---|---|---|
conversation (required) | relation → conversations | |
role (required) | select | system, user, assistant, tool |
content | text | |
model | text | Model that produced it |
tokens_in | number | |
tokens_out | number | |
metadata | json | Tool calls, finish reason, anything else |
| Action | Who can do it |
|---|---|
| List / view | conversation.user = @request.auth.id |
| Create | signed-in users |
| Update | superusers only |
| Delete | conversation.user = @request.auth.id |
Hooks
All hooks are in pb_hooks/main.pb.js and commented.
Quick start
import PocketBase from "pocketbase"
const pb = new PocketBase("https://YOUR-INSTANCE.pocketshub.com")
const convo = await pb.collection("conversations").create({ model: "your-model-id" })
await pb.collection("messages").create({ conversation: convo.id, role: "user", content: "Hi!" })
// Ready to send to your LLM:
const { system, messages } = await pb.send(`/api/conversations/${convo.id}/llm`, {})
// Save the reply with its usage:
await pb.collection("messages").create({
conversation: convo.id, role: "assistant", content: reply, tokens_in: 12, tokens_out: 40,
})
Notes
- Call the LLM from your server (or a PocketBase hook) so your API key never reaches the browser.
License
MIT
2 collections, 1 relation. Hover a collection to trace its relations