AI chat
A streaming chat interface backed by the Vercel AI SDK. Conversations are persisted and scoped to the active workspace.
Where it lives
| Path | Role |
|---|---|
app/(dashboard)/chat | Chat UI (list + [id] thread view). |
app/api/ai/chat | Streaming chat endpoint. |
app/api/ai/generate | Structured / one-shot generation endpoint. |
lib/ai/* | Provider wiring, tools, usage metering. |
How a message flows
- The client sends the message to
app/api/ai/chat. - The route checks the workspace’s plan limits (tokens / messages) and rate limit before calling the model.
- The model response streams back to the UI token by token.
- Token usage is recorded for metering.
Choosing the model
The provider and model come from AI_PROVIDER / AI_MODEL. See
AI providers. On paid plans, users can set a
custom system prompt (gated by features.customSystemPrompt).
Limits & metering
Every call is metered. When a workspace reaches its monthly token or message limit, further calls are blocked until the cycle resets or the plan is upgraded. A soft-limit warning fires around 80% usage. See Plans & limits.
AI chat is an opt-in feature at scaffold time. Agentic tool calling and LangFuse observability both build on it and enable it automatically.
Tool calling
The chat runs as a multi-step agent loop and ships with built-in calculator
and data-fetch tools. Enabling agentic tool calling adds a web_search
tool. Tools are gated by the plan’s features.tools and a template switch — see
Agentic tools.