Page Router AI SDK Streaming
Unanswered
Ghost ant posted this in #help-forum
Ghost antOP
In the documentation (https://sdk.vercel.ai/examples/next-pages/chat/stream-chat-completion) the server code is
I copied and pasted it into /pages/api/chat directory and the streaming fails.
Failed to load resource: the server responded with a status of 404 (Not Found)Understand this error
index.mjs:914
POST http://localhost:3000/api/chat 404 (Not Found)
I am not sure what to do
import { CoreMessage, streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
export async function POST(req: Request) {
const { messages }: { messages: CoreMessage[] } = await req.json();
const result = await streamText({
model: openai('gpt-4'),
system: 'You are a helpful assistant.',
messages,
});
return result.toDataStreamResponse();
}I copied and pasted it into /pages/api/chat directory and the streaming fails.
Failed to load resource: the server responded with a status of 404 (Not Found)Understand this error
index.mjs:914
POST http://localhost:3000/api/chat 404 (Not Found)
I am not sure what to do
3 Replies
Ghost antOP
Even after doing this it doesnt work
@Ghost ant Click to see attachment
The error message should be different this time. What does the error message look like?