Why I Built Mentis AI
Most AI interfaces either lock you into a single company's ecosystem or make you pay separate recurring subscriptions across OpenAI, Claude, and Gemini. Even worse, if you want to use custom agentic tools (like live web searches, URL scraping, or searching your own historical message archive), you are constrained to whatever the platform decides to support.
I wanted a unified workspace where:
- I own my keys: Zero platform markups; keys are encrypted using AES-256 on the client and server.
- True multi-model flexibility: Seamlessly toggle between Claude 3.7 Sonnet, GPT-4o, and Gemini 2.5 Flash in the exact same conversation thread.
- Real native tool execution: Automatic tool calling for web retrieval, live page analysis, and safe math without extra setup.
Architecture & System Flow
The application is architected around a decoupled provider adapter engine built on top of the Vercel AI SDK, Next.js 16 App Router, and Drizzle ORM with PostgreSQL.
Decoupled Provider Adapters
Because each LLM provider handles streaming frames and tool calling schemas slightly differently, the engine normalizes incoming prompts through an abstract adapter layer:
export async function createAIStream({ provider, model, apiKey, messages, tools }) {
const modelInstance = resolveProvider(provider, apiKey)(model);
return streamText({
model: modelInstance,
messages,
tools: {
webSearch: tavilyTool,
urlReader: urlReaderTool,
calculator: safeMathTool,
},
maxSteps: 5,
});
}
Key Highlights & Decisions
1. Client & Server AES-256 Key Encryption
Instead of storing plaintext API keys in a database, Mentis AI gives users the choice between session-only in-memory keys or encrypted persistent vaults. Keys are dynamically decrypted only at the moment a request stream initiates.
2. Native PostgreSQL Full-Text Search
Finding a past conversation shouldn't require paying for an external vector database when relational databases do text search remarkably well. We implemented native to_tsvector and websearch_to_tsquery indexing over message contents with millisecond search response times.
3. Conversation Branching
Ever had an LLM give an answer that went in the wrong direction? Instead of deleting your prompt or starting a whole new thread, Mentis AI introduces branching trees. You can fork at any user turn, test alternative prompts, and navigate back and forth between branches.
Lessons Learned
"Building around the edge-runtime and streaming protocols requires treating state as a stream rather than a snapshot."
- Streaming backpressure matters: Buffering intermediate tool calls before dispatching markdown chunks produces a far smoother UI experience without flickering layout shifts.
- Token cost observability: Showing per-turn input and output token consumption helps users understand model economics before burning through their credits.






