Overview
Connect LLMs through the Vercel AI SDK and AI Gateway with @repo/ai.
TurboJet is a strong starting point for building AI-powered SaaS. It integrates the Vercel AI SDK and routes model calls through the Vercel AI Gateway, so you can use OpenAI, Anthropic, and other providers with a single API key.
Shared helpers live in @repo/ai. The marketing app hosts an authenticated streaming chat endpoint at POST /api/ai/chat.
Configure models
Default chat models are defined in packages/ai/src/models.ts:
import { gateway } from "ai";
/** Default chat model via Vercel AI Gateway. */
export const DEFAULT_CHAT_MODEL = "openai/gpt-4o-mini";
export function getChatModel(modelId: string = DEFAULT_CHAT_MODEL) {
return gateway(modelId);
}To change the default model, update DEFAULT_CHAT_MODEL to another gateway model ID. For example, Anthropic:
export const DEFAULT_CHAT_MODEL = "anthropic/claude-sonnet-4";Or pass a model ID when calling helpers:
import { getChatModel } from "@repo/ai";
import { streamText } from "ai";
const response = streamText({
model: getChatModel("anthropic/claude-sonnet-4"),
messages: [{ role: "user", content: "What is the capital of France?" }],
});For UI message streams (compatible with useChat), use createChatUIMessageResponse from @repo/ai:
import { createChatUIMessageResponse } from "@repo/ai";
return createChatUIMessageResponse({
messages,
modelId: "openai/gpt-4o-mini", // optional; defaults to DEFAULT_CHAT_MODEL
});Environment
Set AI_GATEWAY_API_KEY in the root .env. Without it, POST /api/ai/chat returns 503. See Environment.
OPENAI_API_KEY is reserved for direct OpenAI usage if you add it later; the current stack uses the gateway only.