Assistant UI
pageai-sdk-backendsource: ok · hit
AI SDK Backend
Next.js route handler that streams chat completions through the AI SDK.
npx shadcn add "https://r.assistant-ui.com/ai-sdk-backend.json"free
Where it goes
chat
Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.
Dependencies
Bundle weight · lightai@ai-sdk/openai@assistant-ui/ai-sdk
Files1 · source cached 10/14/2026, 9:30:54 PM
app/api/chat/route.ts
import { openai } from "@ai-sdk/openai";
import { frontendTools } from "@assistant-ui/ai-sdk";
import {
type JSONSchema7,
streamText,
convertToModelMessages,
type UIMessage,
} from "ai";
export const maxDuration = 30;
export async function POST(req: Request) {
const {
messages,
system,
tools,
}: {
messages: UIMessage[];
system?: string;
tools?: Record<string, { description?: string; parameters: JSONSchema7 }>;
} = await req.json();
const aiSDKTools = { ...frontendTools(tools ?? {}) };
const result = streamText({
abortSignal: req.signal,
model: openai("gpt-6-luna"),
messages: await convertToModelMessages(messages, { tools: aiSDKTools }),
tools: aiSDKTools,
...(system === undefined ? {} : { system }),
});
return result.toUIMessageStreamResponse({
onError: (error) =>
error instanceof Error ? error.message : String(error),
});
}