Skip to main content

Overview

Node.js SDK for the SketricGen Chat Server API. Build AI-powered workflows, chat applications, and document analysis tools with TypeScript or JavaScript.

Requirements

  • Node.js 18 or later (uses built-in fetch, FormData, Blob, and streams)
  • ESM: use "type": "module" in package.json or .mjs files

Installation

Or with other package managers:

Quick Start

Features

  • Run Workflows: Execute chat/workflow requests with AI agents
  • Streaming: Real-time streaming responses using Server-Sent Events
  • File Attachments: Attach images and PDFs to workflows (paths or explicit upload)
  • TypeScript: Full type definitions included
  • Error Handling: Typed error classes (e.g. SketricGenAPIError, SketricGenValidationError)
  • CLI Help: Run npx sketricgen --help or npx sketricgen --help runWorkflow for usage

Client Reference

SketricGenClient

The main client for interacting with the SketricGen API.

Constructor

From Environment Variables


runWorkflow()

Execute a workflow/chat request.
Returns: Promise<ChatResponse> if stream is false or omitted; AsyncGenerator<StreamEvent> if stream: true.

Example: Non-Streaming

Example: Streaming


files.upload()

Upload a file and get a fileId for use in runWorkflow(..., { assets: [fileId] }).
When file is a path string, filename and contentType are optional (inferred from the path). When file is a Buffer or Node Readable stream, filename is required.

Response Models

ChatResponse

Response from a non-streaming workflow request.

StreamEvent

Individual event from a streaming response. Parse event.data with JSON.parse(event.data) to access the payload. The parsed object may include a type field matching event_type.

Streaming Events

The streaming API uses the AG-UI Protocol. Parse the data field as JSON to access event details.

Event Types

Complete Streaming Example


File Attachments

Attach files to workflows for document analysis and image understanding.

Supported File Types

Single File (via filePaths)

Multiple Files

Upload First, Then Run (assets)

Streaming with Files