Skip to main content
createFn lets your backend call Nuabase for individual inputs using your API key—no token exchange needed on the server.

Initialize Nua with your API key

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

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

Define and call a function

Pass a prompt and output schema to createFn, then invoke the returned function with your input value.
const classify = nua.createFn({
  prompt: "Classify this support ticket.",
  output: {
    name: "classification",
    schema: z.object({ category: z.string(), priority: z.string() })
  }
});

const result = await classify(ticketBody);
The result is typed from your schema, so you can safely use result.data in downstream server logic.