Usage

import Itzam from "itzam";
import { z } from "zod";

const itzam = new Itzam("YOUR_API_KEY");

const schema = z.array(
  z.object({
    name: z.string(),
    description: z.string(),
  })
);

const response = await itzam.streamObject({
  input: "List the characters in Atlas Shrugged",
  workflowSlug: "atlas-shrugged",
  schema,
});

for await (const chunk of response.stream) {
  console.log(chunk); // Partial or full object as it streams in
}

const metadata = await response.metadata;
console.log(metadata); // Metadata about the run

Parameters

When using a JSON schema, you must add as const to the schema object for it to be properly typed. More info
ParameterTypeRequiredDescription
inputstringYesThe input text to generate a response for.
schemaobjectYesThe Zod v3, v4 or JSON schema that defines the structure of the expected response.
workflowSlugstringNoThe slug of the workflow to use for generation (not required if you’re using a threadId).
threadIdstringNoIdentifier for associating runs with a conversation thread.
attachmentsAttachment[]NoArray of attachments to include in the generation.
contextSlugsstring[]NoThe slugs of the contexts that the AI model can access.

Return Value

The streamObject method returns the following object:

type StreamObjectResponse<T> = {
  stream: AsyncGenerator<T, void, unknown>; // The stream of objects
  metadata: Promise<{
    runId: string; // The ID of the run
    cost: string; // The cost of the run in USD
    model: {
      name: string; // The name of the model
      tag: string; // The tag of the model
    };
    durationInMs: number; // The duration of the run in milliseconds
    inputTokens: number; // The number of input tokens used for this generation
    outputTokens: number; // The number of output tokens used for this generation
  }>;
};