Skip to content

nua.get()

View as Markdown

get() produces a single value. Use it to transform, classify, extract from, or generate from a single input.

// Prompt only: a plain string
nua.get(prompt: string): Promise<CastResult<string>>
// With options: a value matching the schema
nua.get<S extends z.ZodTypeAny>(prompt: string, options: GetOptions<S>): Promise<CastResult<z.infer<S>>>
ParameterTypeRequiredDescription
promptstringYesInstructions for the LLM. Keep it constant across calls; put what varies in input.
options.inputunknownNoData to process. Any JSON-serializable value.
options.output.namestringYesA name for the generated value, such as 'address'. The model sees it, so make it descriptive.
options.output.schemaZod schemaYesThe shape of the value: an object, array, or primitive. The answer is parsed with it, so defaults, transforms, and refinements apply.
options.modelModelInputNoOverrides the client’s default model for this call.
const result = await nua.get('What is the chemical formula for water?');
if (result.success) {
console.log(result.data); // "H2O"
}
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"
}
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"
}
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 },
});

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)
const result = await nua.get('Extract the address from this text', {
input: text,
output: { name: 'address', schema: AddressSchema },
model: { alias: 'sonnet' },
});
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.