Set up API routes to handle chat requests and configure system prompts for RAG behavior.
route.ts
file and can export HTTP methods like GET, POST, PUT, PATCH, etc.
Create the File
app/api/chat/route.ts
.Add the Code
Declare the POST Function
POST
that handles incoming HTTP POST requests to this route.Extract Request Data
await request.json()
to
get the conversation history.Call AI SDK
streamText
function imported from the AI SDK, along
with the specified model configuration.Return Response
UIMessageStreamResponse
format, which enables real-time text streaming to the client.Start the Development Server
pnpm run dev
and navigate to http://localhost:3000Send a Test Message
Ask a Question
Test Different Queries