Common IssuesuseChat No Response with maxSteps

useChat No Response with maxSteps

Issue

I am using useChat with maxSteps. When I log the incoming messages on the server, I can see the tool call and the tool result, but the model does not respond with anything.

Background

The useChat hook uses a message structure (Message) that pre-dates the AI SDK Core message structure (CoreMessage).

Solution

To resolve this issue, convert the incoming messages to the CoreMessage format using the convertToCoreMessages function.

import { openai } from '@ai-sdk/openai';
import { convertToCoreMessages, streamText } from 'ai';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = await streamText({
model: openai('gpt-4o'),
messages: convertToCoreMessages(messages),
});
return result.toDataStreamResponse();
}