Learn how to stream text with an image prompt using the AI SDK and Next.js
Vision models such as GPT-6 Astra can process both text and images. In this example, we will show you how to send an image URL along with the user's message to the model with useChat.
The server route uses convertToModelMessages to handle the conversion from UIMessages to model messages, which automatically handles multimodal content including images.
app/api/chat/route.ts
import { convertToModelMessages, createUIMessageStreamResponse, streamText, toUIMessageStream,} from 'ai';export const maxDuration = 60;export async function POST(req: Request) { const { messages } = await req.json(); // Call the language model const result = streamText({ model: 'openai/gpt-6-astra', messages: await convertToModelMessages(messages), }); // Respond with the stream return createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }), });}