TurboJet
AI

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 modelId and system prompt via @repo/ai helpers
  • 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:

packages/api/src/modules/ai/router.ts
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[],
		});
	},
);
DetailValue
Method / pathPOST /api/ai/chat
AuthRequired (requireAuth)
Rate limitWRITE
Body{ messages: UIMessage[] }
SuccessUI message stream response
Missing gateway key503
Invalid body400 — 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.

On this page