nua.get()
get() produces a single value. Use it to transform, classify, extract from, or generate from a single input.
Signatures
Section titled “Signatures”// Prompt only: a plain stringnua.get(prompt: string): Promise<CastResult<string>>
// With options: a value matching the schemanua.get<S extends z.ZodTypeAny>(prompt: string, options: GetOptions<S>): Promise<CastResult<z.infer<S>>>Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Instructions for the LLM. Keep it constant across calls; put what varies in input. |
options.input | unknown | No | Data to process. Any JSON-serializable value. |
options.output.name | string | Yes | A name for the generated value, such as 'address'. The model sees it, so make it descriptive. |
options.output.schema | Zod schema | Yes | The shape of the value: an object, array, or primitive. The answer is parsed with it, so defaults, transforms, and refinements apply. |
options.model | ModelInput | No | Overrides the client’s default model for this call. |
Examples
Section titled “Examples”Plain string
Section titled “Plain string”const result = await nua.get('What is the chemical formula for water?');
if (result.success) { console.log(result.data); // "H2O"}Data extraction
Section titled “Data extraction”const AddressSchema = z.object({ street: z.string(), city: z.string(), state: z.string(), zipCode: z.string(),});
const result = await nua.get('Extract the address from this text', { input: 'Please ship to 123 Main St, Springfield, IL 62701', output: { name: 'address', schema: AddressSchema },});
if (result.success) { console.log(result.data.city); // "Springfield"}Classification
Section titled “Classification”const TicketSchema = z.object({ category: z.enum(['bug', 'feature', 'question', 'other']), priority: z.enum(['low', 'medium', 'high']), summary: z.string(),});
const result = await nua.get('Classify this support ticket', { input: 'The app crashes when I click the submit button. This is blocking our team.', output: { name: 'classification', schema: TicketSchema },});
if (result.success) { console.log(result.data.category); // "bug" console.log(result.data.priority); // "high"}Generating from structured input
Section titled “Generating from structured input”const EmailSchema = z.object({ subject: z.string(), body: z.string(), tone: z.enum(['formal', 'casual', 'friendly']),});
const result = await nua.get('Draft a follow-up email to the attendee', { input: { meeting: 'Q4 Planning Session', attendee: 'John', keyPoints: ['Budget approved', 'Timeline set for December'], }, output: { name: 'email', schema: EmailSchema },});Primitive outputs
Section titled “Primitive outputs”The schema doesn’t have to be an object:
const hasQuestion = await nua.get('Does this message contain a question?', { input: 'I was wondering if you could help me with something.', output: { name: 'hasQuestion', schema: z.boolean() },});// hasQuestion.data: boolean
const revenue = await nua.get('Extract Q3 revenue in US dollars', { input: 'Q3 revenue hit $2.5M with 15% growth.', output: { name: 'revenueUsd', schema: z.number() },});// revenue.data: number (2500000)Choosing a model per call
Section titled “Choosing a model per call”const result = await nua.get('Extract the address from this text', { input: text, output: { name: 'address', schema: AddressSchema }, model: { alias: 'sonnet' },});Error handling
Section titled “Error handling”const result = await nua.get('Classify this support ticket', { input, output });
if (!result.success) { showError(result.reason); // why it failed, in the agent's or provider's words logger.warn(result.error); // a one-line summary: attempts made and the last failure return;}
processData(result.data);See API Overview for which failures are returned and which throw.