AI SDK Backend
ai-sdk-backend
Next.js route handler that streams chat completions through the AI SDK.
import { openai } from "@ai-sdk/openai";
import { frontendTools } from "@assistant-ui/ai-sdk";
import {
streamText,
convertToModelMessages,
type UIMessage,
type JSONSchema7,
} from "ai";
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 result = streamText({
model: openai("gpt-5.6-luna"),
messages: await convertToModelMessages(messages),
tools: {
...frontendTools(tools ?? {}),
},
...(system === undefined ? {} : { system }),
});
return result.toUIMessageStreamResponse();
}
Built on AI SDK Backend
Other @assistant-ui items that list this one as a dependency.
More from @assistant-ui
Streaming never steals your scroll position; a pill offers the way back down.
A checklist the agent works through, with progress you can glance.
Work measured in minutes: weighted stages, an ETA, and a way out.
A read-only transcript someone sent you, with a way to pick it up yourself.
Human in the loop: the agent asks before it runs anything with side effects.
A pixel matrix that keeps time while the model has nothing to show yet.
Citations collapsed into a pill, expanding into scannable source cards.
Work still going somewhere else, and the results waiting to be collected.