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"inpackage.jsonor.mjsfiles
Installation
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 --helpornpx sketricgen --help runWorkflowfor usage
Client Reference
SketricGenClient
The main client for interacting with the SketricGen API.Constructor
From Environment Variables
| Environment Variable | Default | Description |
|---|---|---|
SKETRICGEN_API_KEY | required | Your API key |
SKETRICGEN_TIMEOUT | — | Request timeout in seconds |
SKETRICGEN_UPLOAD_TIMEOUT | — | Upload timeout for large files |
SKETRICGEN_MAX_RETRIES | — | Maximum retry attempts |
runWorkflow()
Execute a workflow/chat request.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 afileId for use in runWorkflow(..., { assets: [fileId] }).
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.| Field | Type | Description |
|---|---|---|
agent_id | string | Workflow/Agent ID |
user_id | string | User identifier |
conversation_id | string | Conversation ID for follow-up messages |
response | string | The assistant’s response text |
owner | string | Owner of the agent |
error | boolean | Error flag (default: false) |
StreamEvent
Individual event from a streaming response.| Field | Type | Description |
|---|---|---|
event_type | string | Type of the SSE event |
data | string | JSON string containing event data |
id | string | undefined | Optional event ID |
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 thedata field as JSON to access event details.
Event Types
| Event Type | Description | Key Fields |
|---|---|---|
RUN_STARTED | Workflow execution started | thread_id, run_id |
TEXT_MESSAGE_START | Assistant message started | message_id, role |
TEXT_MESSAGE_CONTENT | Text chunk received | message_id, delta |
TEXT_MESSAGE_END | Assistant message completed | message_id |
TOOL_CALL_START | Tool/function call started | tool_call_id, tool_call_name |
TOOL_CALL_END | Tool/function call completed | tool_call_id |
RUN_FINISHED | Workflow completed | thread_id, run_id |
RUN_ERROR | Workflow error occurred | message |
CUSTOM | Custom event | varies |
Complete Streaming Example
File Attachments
Attach files to workflows for document analysis and image understanding.Supported File Types
| Type | MIME Types | Max Size |
|---|---|---|
| Images | image/jpeg, image/png, image/webp, image/gif | 20 MB |
| Documents | application/pdf | 20 MB |

