Skip to main content
createArrayFn is optimized for server-side batch operations. Initialize Nua with your API key, define the array function, then pass an array plus the primary key field to keep results aligned.

Initialize Nua with your API key

import { Nua } from 'nuabase';
import { z } from 'zod';

const nua = new Nua({ apiKey: process.env.NUABASE_API_KEY });

Batch processing

const LeadInfo = z.object({
  company: z.string(),
  website: z.string().url().optional()
});

const enrichLeads = nua.createArrayFn({
  prompt: "Extract company info from these leads.",
  output: { name: "info", schema: LeadInfo }
});

const leads = [
  { id: 1, note: "Looking for analytics" },
  { id: 2, note: "Interested in a demo" }
];

// Pass the array and the name of the primary key field ('id')
const results = await enrichLeads(leads, 'id');

Row-level caching

Nuabase caches rows for array functions. Re-running a batch only processes the rows that changed, saving time and compute.