ai icon indicating copy to clipboard operation
ai copied to clipboard

deprecate `generateObject()` / `streamObject()` in favor of `generateText({ output })` / `streamText({ output })`

Open gr2m opened this issue 1 month ago • 2 comments

gr2m avatar Nov 05 '25 17:11 gr2m

Not sure it's the best place, or if it's better to create a new issue, but should this work in the latest beta versions:

import 'dotenv/config';

import { generateText, Output } from 'ai';
import z from 'zod';
import { experimental_createMCPClient as createMCPClient } from '@ai-sdk/mcp';
import { openai } from '@ai-sdk/openai';

const transport = {
  type: 'http',
  url: 'https://api.githubcopilot.com/mcp/',
  headers: { Authorization: process.env.GITHUB_MCP_API_KEY || '' },
} as const;

const client = await createMCPClient({ transport });
const tools = await client.tools();

const model = openai('gpt-5')
const schema = z.object({
  repositories: z.array(z.object({ name: z.string })),
});

const githubProfileName = '...';

await generateText({
  model,
  tools,
  output: Output.object({ schema }),
  prompt: `List all repositories owned by the GitHub user "${githubProfileName}" with at least 50 stars.`,
});

I'm currently getting NoOutputGeneratedError [AI_NoOutputGeneratedError]: No output generated. error.

More info here: https://community.vercel.com/t/no-output-when-using-generatetext-with-structured-output-and-mcp-tools/27423.

szimek avatar Nov 14 '25 16:11 szimek

Please create a separate issue, it's unrelated to the deprecation of generateObject() and streamObject(), it might be a bug with generateText({ output })

gr2m avatar Nov 14 '25 18:11 gr2m

How do I consume it in the ui after this deprecation? Before this, we can use useObject; now it seems we need manually extract it?

songkeys avatar Nov 21 '25 01:11 songkeys

@songkeys you can still use useObject (with text streams from streamText)

lgrammel avatar Nov 29 '25 10:11 lgrammel

@szimek you need to specify stopWhen since tools require multiple steps

lgrammel avatar Nov 29 '25 10:11 lgrammel