Custom Nodes

Creating a Node is easy - it's just an async function!

A Node function receives two parameters - input and apiKeys:

  • The input is either a Record<string, any> or a ReadableStream.
  • The apiKeys is a Record<string, string> that contains all API Keys that were passed into the Aigur Client instance. You can use them for your API calls.

The Node function must return a Promise that resolves to the output of the Node (Record<string, any> or a ReadableStream).

Simple Example

Here is an example of a Node that greets its input:


export async function greeter(input: { subject: string }): Promise<{greeting: string}> {
return {
greeting: `Hello, ${input.subject}!`,

Using Runtime Validators (Optional)

You can use runtime schema validators/parsers such as Zod (opens in a new tab) to validate the input and output of your Node.


import { z } from 'zod';
const inputSchema = z.object({
subject: z.string().default('world'),
const outputSchema = z.object({
greeting: z.string(),
export async function replaceString(
input: z.input<typeof inputSchema>
): Promise<z.output<typeof outputSchema>> {
// parse the input and set default values if defined
const payload = inputSchema.parse(input);
return {
greeting: `Hello, ${payload.subject}!`,