Skip to Content
StackBlaze Templates — operator documentation

AI chat

A streaming chat interface backed by the Vercel AI SDK. Conversations are persisted and scoped to the active workspace.

Where it lives

PathRole
app/(dashboard)/chatChat UI (list + [id] thread view).
app/api/ai/chatStreaming chat endpoint.
app/api/ai/generateStructured / one-shot generation endpoint.
lib/ai/*Provider wiring, tools, usage metering.

How a message flows

  1. The client sends the message to app/api/ai/chat.
  2. The route checks the workspace’s plan limits (tokens / messages) and rate limit before calling the model.
  3. The model response streams back to the UI token by token.
  4. 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.