# Node.JS API

> Learn about the new API to call genaiscript for other typescript scripts.

[Your browser does not support the audio element.](https://microsoft.github.io/genaiscript/llms-full.txt.mp3 "Generated by 🤖 AI with random voice personality. Content interpretation may vary.")

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+).

* [Documentation](https://microsoft.github.io/genaiscript/reference/api/)

## Installation

[Section titled “Installation”](#installation)

You’ll want to add [genaiscript](https://www.npmjs.com/package/genaiscript) as a (dev) dependency to your project.

* npm

  ```sh
  npm i @genaiscript/api
  ```

* pnpm

  ```sh
  pnpm add @genaiscript/api
  ```

* yarn

  ```sh
  yarn add @genaiscript/api
  ```

## The `run` API

[Section titled “The run API”](#the-run-api)

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.

```js
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.

## Don’t mess with my process

[Section titled “Don’t mess with my process”](#dont-mess-with-my-process)

On the caller side, the [run implementation](https://github.com/microsoft/genaiscript/blob/main/packages/cli/src/api.ts) 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

## Help us improve it!

[Section titled “Help us improve it!”](#help-us-improve-it)

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