![// AI SDK 5 beta.1 - agentic controls and typed chat messages export async function POST(req: Request) { const { messages }: { messages: AudioPlayerMessage[] } = await req.json(); const result = streamText({ model: openai("gpt-4o"), messages: convertToModelMessages(messages), tools: { getArtists, getAlbums, getSongs, playSong }, prepareStep({ steps }) { if (hasToolCallInLastStep(steps, "getArtists")) { return { toolChoice: { type: "tool", toolName: "getAlbums" }, }; } }, stopWhen: [stepCountIs(5), hasToolCall("playSong")], }); return result.toUIMessageStreamResponse(); }](https://pbs.twimg.com/media/GuN4VUhbUAAI10O.jpg?name=small&format=webp)
ALT // AI SDK 5 beta.1 - agentic controls and typed chat messages export async function POST(req: Request) { const { messages }: { messages: AudioPlayerMessage[] } = await req.json(); const result = streamText({ model: openai("gpt-4o"), messages: convertToModelMessages(messages), tools: { getArtists, getAlbums, getSongs, playSong }, prepareStep({ steps }) { if (hasToolCallInLastStep(steps, "getArtists")) { return { toolChoice: { type: "tool", toolName: "getAlbums" }, }; } }, stopWhen: [stepCountIs(5), hasToolCall("playSong")], }); return result.toUIMessageStreamResponse(); }
![// @ai-sdk/anthropic 2.0.0-alpha.11 - PDF Citation Support const { text, sources } = await generateText({ model: anthropic("claude-4-sonnet-20250514"), messages: [ { role: "user", content: [ { type: "text", text: "When was this published?" }, { type: "file", mediaType: 'application/pdf', data, // your data as a base64 or binary providerOptions: { anthropic: { citations: { enabled: true } }, }, }, ], }, ], });](https://pbs.twimg.com/media/GtGBbxBbQAA3PUa.jpg?name=small&format=webp)
ALT // @ai-sdk/anthropic 2.0.0-alpha.11 - PDF Citation Support const { text, sources } = await generateText({ model: anthropic("claude-4-sonnet-20250514"), messages: [ { role: "user", content: [ { type: "text", text: "When was this published?" }, { type: "file", mediaType: 'application/pdf', data, // your data as a base64 or binary providerOptions: { anthropic: { citations: { enabled: true } }, }, }, ], }, ], });

ALT // [email protected] - Tool callbacks const result = streamText({ model: "openai/gpt-4.1-mini", tools: { generateCode: tool({ description: "...", parameters: z.object({ /* ... */ }), onArgsStreamingStart: () => {}, onArgsStreamingDelta: ({ argsTextDelta }) => {}, onArgsAvailable: ({ args }) => {}, execute: async (args) => { /* */ }, }), }, });















