AI chatbot
Authenticated streaming chat via POST /api/ai/chat and @repo/ai.
TurboJet includes a streaming chat API built on the Vercel AI SDK. Completions go through the Vercel AI Gateway and return a UI message stream suitable for useChat / DefaultChatTransport.
No chatbot UI yet
There is no chat UI in apps/marketing today. The package and API route are
ready for a client you add yourself (dashboard, modal, or dedicated page).
Features you can build on
The backend supports the pieces you need for a full chatbot experience:
- Streaming responses (
createUIMessageStreamResponse) - Multi-turn message arrays (conversation context)
- Optional
modelIdandsystemprompt via@repo/aihelpers - Auth-gated access and write rate limiting on the route
Session list, persisted history, and a polished UI are application concerns you layer on top.
API route
The Hono router is mounted at /api/ai from the marketing app:
export const aiRouter = new Hono<AuthEnv>().post(
"/chat",
rateLimit("WRITE"),
requireAuth,
async (c) => {
if (!env.AI_GATEWAY_API_KEY) {
fail(503, "AI Gateway is not configured");
}
const body = await c.req.json<{ messages?: unknown }>();
if (!Array.isArray(body.messages)) {
fail(400, "messages must be an array");
}
return createChatUIMessageResponse({
messages: body.messages as UIMessage[],
});
},
);| Detail | Value |
|---|---|
| Method / path | POST /api/ai/chat |
| Auth | Required (requireAuth) |
| Rate limit | WRITE |
| Body | { messages: UIMessage[] } |
| Success | UI message stream response |
| Missing gateway key | 503 |
| Invalid body | 400 — messages must be an array |
Streaming logic lives in packages/ai/src/chat.ts (createChatUIMessageResponse).
Wire a client
Use the AI SDK’s useChat with a transport that posts to /api/ai/chat. Session cookies must be sent so Better Auth can authenticate the request:
"use client";
import { useChat } from "@ai-sdk/react";
import { DefaultChatTransport } from "ai";
export function AiChat() {
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({
api: "/api/ai/chat",
credentials: "include",
}),
});
// Render messages and an input that calls sendMessage...
}Install @ai-sdk/react in the app that hosts the UI if it is not already a dependency. See the Vercel AI SDK documentation for useChat details.
Related
- AI overview — models and gateway setup
- Using prompts — reusable prompt helpers
- Environment —
AI_GATEWAY_API_KEY - API — Hono module conventions