Usage

import Itzam from "itzam";

const itzam = new Itzam("YOUR_API_KEY");

const response = await itzam.streamText({
  input: "Hello, world!",
  workflowSlug: "my_great_workflow",
  threadId: "my-thread-id",
});

To consume the stream, you can use it like this:

for await (const chunk of response.stream) {
  setResponse((prev) => prev + chunk);
}

You can also get the metadata of the run once the stream is finished:

const metadata = await response.metadata;

Parameters

ParameterTypeRequiredDescription
inputstringYesThe input text to generate a response for.
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.

Return Value

The streamText method returns the following object:

type StreamTextResponse = {
  stream: AsyncGenerator<string, void, unknown>; // The stream of text
  metadata: Promise<{
    runId: string; // The ID of the run
    cost: number; // 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
  }>;
};