generateObject/streamObject are deprecated. The current pipeline streams structured JSON through the text stream and parses it incrementally on the client.

Server:

import { Output, streamText, toTextStream, createTextStreamResponse } from 'ai';
import { orderSchema } from './schema';

export const maxDuration = 30;

export async function POST(req: Request) {
  const { prompt } = await req.json();
  const result = streamText({
    model: 'your-model-id',
    output: Output.object({ schema: orderSchema }),
    prompt,
  });
  return createTextStreamResponse({ stream: toTextStream({ stream: result.stream }) });
}

Client:

import { useObject } from '@ai-sdk/react';
import { orderSchema } from './api/orders/schema';

const { object, submit, isLoading, error } = useObject({ api: '/api/orders', schema: orderSchema });

Rules:
1. One schema file imported by both sides. A drifted copy produces validation failures that look like model errors.
2. The object is partial while streaming: guard every field (object?.items?.map). First render always has undefined leaves.
3. .describe() on fields improves quality; it becomes prompt text for the model.
4. If the provider wraps JSON in fences, add extractJsonMiddleware to the model via wrapLanguageModel.
5. For non-streaming, generateText with the same output option returns { output } fully validated. Same schema, same validation, no client hook needed.
6. On validation failure you get NoObjectGeneratedError with a cause of JSONParseError or TypeValidationError. Log the cause; it tells you whether the JSON or the schema is at fault.
7. zod ^4.1.8 is required. Older versions degrade both type performance and runtime behavior.