Skip to content

Quick start

$ npm install neuro-ts
import { configureClient } from 'neuro-ts';
configureClient({
apiKey: process.env.OPENAI_API_KEY,
model: 'gpt-4o', // optional, this is the default
});

apiKey mode is rejected at runtime in browser environments. See Browser safety for the safe alternatives.

Every method takes a single object literal. Keys mirror the original JavaScript built-in’s parameters; instance methods get a contextual receiver key (array, string, set, etc). Add an optional prompt: string to route the call through the LLM.

import { neuro } from 'neuro-ts';
// Native fallback. No prompt, no network call.
await neuro.math.random({});
// 0.7062
// LLM-routed. Prompt steers the result.
await neuro.math.random({ prompt: 'a value between 0.7 and 0.71' });
// 0.7044
// Array map: receiver is the `array` key, the callback is `callbackfn`,
// the optional prompt is the only difference between native and LLM dispatch.
await neuro.array.map({ array: [1, 2, 3], callbackfn: (n) => n * 2 });
// [2, 4, 6]
await neuro.array.map({
array: [1, 2, 3],
callbackfn: (n) => n,
prompt: 'square each value',
});
// [1, 4, 9]
// Variadic methods take their items under a single named array key.
await neuro.array.of({ items: ['a', 'b', 'c'] });
// ['a', 'b', 'c']
await neuro.math.max({ values: [1, 5, 10], prompt: 'pick the loudest' });
// 10
// String / Object / JSON / Date all follow the same shape.
await neuro.string.split({ string: 'the quick brown fox', separator: ' ' });
// ['the', 'quick', 'brown', 'fox']
await neuro.object.keys({ o: { id: 1, name: 'vlad' } });
// ['id', 'name']
await neuro.json.stringify({
value: { a: 1 },
space: 0,
prompt: 'compact JSON, single line',
});
// '{"a":1}'
await neuro.date.getFullYear({ date: new Date() });
// 2026
// Broken JSON that native JSON.parse would throw on.
// The LLM silently repairs it and returns the object you obviously wanted.
const broken = `{
name: "Alice",
"age": 30,
"scores": [98, 87, 102,
"joined": '2021-03-15',
}`;
await neuro.json.parse({
text: broken,
prompt:
'This JSON was written by someone who learned JSON from a Stack Overflow answer ' +
'posted in 2009. Fix every syntax error silently and return a valid parsed object. ' +
'Do not lecture me about the errors. I know. We all know.',
});
// { name: 'Alice', age: 30, scores: [98, 87, 102], joined: '2021-03-15' }

Every wrapper has a deterministic, generated system prompt. Nothing is synthesised at request time.

import prompts from 'neuro-ts/prompts';
console.log(prompts['neuro.array.map'].systemPrompt);
Generated promptArray.prototype.map
You are simulating the JavaScript built-in `Array.prototype.map`.
## Original signature(s)
  Overload 1: (callbackfn?: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[]
## JSDoc
Calls a defined callback function on each element of an array, and returns an array that contains the results.

## How to respond
- Behave EXACTLY as the original `map` would, but use the user's intent to choose any callback / comparator / transform logic that the original would normally accept as an argument.
- Strictly preserve the original return type and shape.
- Output ONLY the JSON-encoded return value of the function call.
- Do NOT include explanations, prose, comments, or markdown fences.
- If the function would return `undefined`, output the literal string `undefined`.
- For Date / RegExp / Map / Set / TypedArray returns, output an object of the form { "__type": "Date" | "RegExp" | "Map" | "Set" | "<TypedArrayName>", ... } so the SDK can rehydrate it.