Skip to content

Node.JS API

An 8-bit style illustration showcases a stylized Node.JS logo alongside a geometric TypeScript symbol. Abstract gear and circuit patterns connect the two, representing the integration of GenAIScript in a corporate environment. The image uses five colors that highlight a digital, clean, and tech-focused aesthetic, remaining iconic and free of human elements or text.
Generated by 🤖 AI

A long standing feature request has been to run GenAIScript programmatically from other scripts. We are happy to announce that we have released a Node.JS API for GenAIScript. This API allows you to call GenAIScript from other TypeScript scripts (v1.83+).

You’ll want to add genaiscript as a (dev) dependency to your project.

Terminal window
npm i -D genaiscript

The run API is meant to mimic the behavior of the GenAIScript CLI. It takes the same arguments as the CLI and returns the same results. This allows you to call GenAIScript from other TypeScript scripts.

import { run } from "genaiscript/api"
const results = await run("summarize", ["myfile.txt"])

The result object contains the full list of messages, and additional parsed information like modified files, diagnostics and so forth.

On the caller side, the run implementation is a dependency free, side effect free function. It spawns a worker thread where GenAIScript does the work.

  • No global added
  • No package loaded
  • A few hundred b of memory used

Obviously this is a first draft and we could do a better job at providing callbacks for progress. Send us your feedback!