Mentis AI

Mentis AI is a full stack AI workspace built with Next.js 16, Vercel AI SDK, Better Auth, and PostgreSQL. Users can interact with OpenAI, Anthropic, and Gemini models using encrypted keys, streaming responses, server tools (Web Search, URL Reader, Calculator, Search), conversation branching, and PDF or Markdown exporting.

Mentis AI screenshot 1
Mentis AI screenshot 2
Mentis AI screenshot 3
Mentis AI screenshot 4
Mentis AI screenshot 5
Mentis AI screenshot 6
Mentis AI screenshot 7
Next.jsNext.js
TypeScriptTypeScript
Tailwind CSSTailwind CSS
ShadcnShadcn
PostgreSQLPostgreSQL
DrizzleDrizzle
BetterAuthBetterAuth
OpenAI SDKOpenAI SDK
Gemini APIGemini API
VercelVercel

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:

  1. I own my keys: Zero platform markups; keys are encrypted using AES-256 on the client and server.
  2. True multi-model flexibility: Seamlessly toggle between Claude 3.7 Sonnet, GPT-4o, and Gemini 2.5 Flash in the exact same conversation thread.
  3. 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.

Loading diagram...

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.

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.