> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nuabase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# createFn

> Define and call single-item LLM functions from your server

`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

```typescript theme={null}
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.

```typescript theme={null}
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.
