Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.tensormesh.ai/llms.txt

Use this file to discover all available pages before exploring further.

Structured output is requested through the AI SDK chat model call. With tensormesh(modelId), the request is sent to /v1/chat/completions and the AI SDK parses the response against your schema.
import {
  extractJsonMiddleware,
  Output,
  streamText,
  wrapLanguageModel,
} from "ai";
import { tensormesh } from "@tensormesh/ai-sdk-provider";
import { z } from "zod";

const launchPlanSchema = z.object({
  title: z.string(),
  audience: z.string(),
  summary: z.string(),
  integrationSteps: z.array(
    z.object({
      step: z.string(),
      detail: z.string(),
    }),
  ),
  successSignals: z.array(z.string()),
});

const result = streamText({
  model: wrapLanguageModel({
    model: tensormesh("deepseek-ai/DeepSeek-V4-Flash"),
    middleware: extractJsonMiddleware(),
  }),
  prompt:
    "Create a launch plan for a TypeScript team adopting Tensormesh serverless inference. Return only the JSON object.",
  output: Output.object({
    schema: launchPlanSchema,
  }),
});

for await (const partialObject of result.partialOutputStream) {
  console.log(partialObject);
}
Structured output is useful when your application needs predictable JSON for forms, workflow plans, routing decisions, or typed UI state. Use extractJsonMiddleware() when a model may wrap JSON in Markdown code fences.