@nika-open/nika 0.125.2 · Apache-2.0 · macOS and Linux
The Nika TypeScript SDK.
Check, run and prove a workflow from your app. One package installs the client and the engine payload. Local by default. Point it at nika serve when you have a URL and a token.
Prerequisite: Node.js 22 or newer, on macOS or Linux (glibc). The published package @nika-open/nika@0.125.2 bundles engine 0.125.2, so one install brings the client and the engine it starts.
❯npm install @nika-open/nika@0.125.2
02
Mint the signing key
Once per machine, nika key init mints the key the engine signs each run’s record with. NIKA_KEYCHAIN=off makes it write the key as files, to ~/.nika/keys/ (mode 0600): that is where the engine your app starts and nika serve read it, on macOS and on Linux.
Without the variable, nika key init refuses on a Linux terminal (its --force puts the key in the desktop’s Secret Service, where neither looks) and on a Mac whose keychain holds a key from Nika 0.122 or older.
Put both in the folder where you installed the package. hello.nika is the workflow: one task, with mock/echo standing in for a model. demo.mts is your program: it runs the file, reads the typed result and asks the engine to verify the run’s record.
hello.nikaNika workflow
nika:hellomodel:mock/echopermits:{}tasks:greeting:infer:prompt:"Say hello from the Nika SDK."max_tokens:32outputs:greeting:${{ tasks.greeting.output }}
demo.mtsTypeScript
import { Nika, isNikaRunSucceeded } from '@nika-open/nika';
const nika = new Nika({ cwd: process.cwd() });
// The engine checks the file first: a workflow it refuses throws here and never starts.
const run = await nika.run<{ greeting: string }>('hello.nika', { maxCostUsd: 0 });
const result = await run.result();
// A failed run is data you read, not an exception.
if (!isNikaRunSucceeded(result) || !result.receipt) {
console.error(result.status, result.error?.code, result.error?.message);
process.exit(1);
}
console.log(result.outputs?.greeting);
// Ask the engine to verify the run's tamper-evident record.
const proof = await nika.traceVerify(result.receipt);
console.log(proof.verified ? 'receipt verified' : `not verified: ${proof.reason}`);
04
Run it
The rehearsal prints two lines: the greeting output, then the verdict on the run’s record. Node.js 22.18 or newer runs demo.mts as is; on an older 22.x, name it demo.mjs and remove <{ greeting: string }>.
❯node demo.mts
Expected rehearsal result
mock(echo) · Say hello from the Nika SDK.
receipt verified
Seeing not verified: receipt_mismatch?
The run succeeded, but the engine your app started found no signing key it can read, so the run’s record is unsealed. That engine reads ~/.nika/keys/ (or the NIKA_RUN_KEY_FILE and NIKA_RUN_PUB_FILE pair), never an OS keychain. Run NIKA_KEYCHAIN=off ./node_modules/.bin/nika key init, then the demo again.
A key that Nika 0.122 or older kept in the macOS keychain cannot be read or copied by 0.125.2: on such a Mac, this command mints a new key as files. On Linux, a key that nika key init --force put in the Secret Service can be copied instead, from a terminal: ./node_modules/.bin/nika key align. And receipt_mismatch is also the engine’s answer for a tampered or edited receipt: do not read every one as “just unsigned”.
The same run, recorded in a terminal
Recorded: the last screen of the package’s quick-start recording, the demo.mts above and what node demo.mts printed once NIKA_KEYCHAIN=off nika key init had minted the key. Captured in a terminal from @nika-open/nika 0.125.2 and its bundled engine nika 0.125.2 (ae2d5f0b7); the run is a mock/echo rehearsal, with no model key and no model call.
05
Check first, watch the events
check() is the same audit without running. run.events() gives the live events, then run.result() the typed result. With the key from step 02 in place, next.mjs prints six lifecycle events, then the verdict.
next.mjsJavaScript
import { Nika, isNikaRunSucceeded } from '@nika-open/nika'
const nika = new Nika()
const report = await nika.check('hello.nika')
if (!report.clean) throw new Error('check refused the file')
const run = await nika.run('hello.nika', { maxCostUsd: 0 })
for await (const event of run.events()) console.log(event.kind)
const result = await run.result()
if (!isNikaRunSucceeded(result)) throw new Error(result.status)
if (result.receipt) {
const proof = await nika.traceVerify(result.receipt)
console.log(proof.verdict)
}
new Nika() drives the bundled engine; new Nika({ url, token }) drives your own nika serve. check, run, events, cancel and traceVerify keep their names on both. Some options change: on a server, run() takes an idempotencyKey and refuses maxCostUsd, and plain http:// needs allowInsecureHttp: true.
An illustration with captured content. new Nika() starts the bundled engine as a child process; new Nika({ url, token }) reaches nika serve, where line 3 takes url, token and allowInsecureHttp and line 6 takes an idempotencyKey in place of maxCostUsd. The code is the quick start on this page, and every event, verdict, hash and version on screen was captured from @nika-open/nika 0.125.2, its bundled engine nika 0.125.2 (ae2d5f0b7) and nika serve 0.125.2 in a mock/echo rehearsal. The cards, lanes, packets and pacing are drawn; a real run takes milliseconds.
Animated diagram, 25 seconds. On the left is the quick start’s demo.mts, with a panel of what the app reads. In the middle, the @nika-open/nika package is a column with one junction. On the right are two doors: new Nika() leads to the bundled engine nika 0.125.2, run as a child process, and new Nika({ url, token }) leads to nika serve. Lines 3 and 6 are edited to the server door’s options and back: line 3’s cwd: process.cwd() becomes url, token, allowInsecureHttp: true, and line 6’s maxCostUsd: 0 becomes idempotencyKey. A refused list-files.nika gets NIKA-SEC-004, and run() throws NikaOperationError with no run. hello.nika is run ready. Six local events and two server events land in the app’s panel. The engine’s six hash-chained journal lines end with run_sealed. The receipt goes back for traceVerify(): verified locally and sealed by the server. One changed byte makes the verifier report BROKEN at line 5.
run(workflow, options?)
Checks the file, then starts it. A file the engine refuses never starts.
local · server
check(workflow, options?)
The same audit without running: clean, plus the findings.
local · server
run.events() · run.result()
Live events, then the typed result. A failed run is data, not an exception.
local · server
traceVerify(receipt)
The engine checks the run’s record against its receipt.
local · server
compile(request, options?)
Writes or edits a candidate workflow without running it.
local · server
attachRun(id) · schedule(…)
Picks a job back up after a restart; runs a workflow on a schedule.
server only
On your server
The same file, through nika serve.
The server holds durable jobs and schedules.
01
Start the server
In the folder that holds hello.nika, give the server a project file and a private token that stays out of git, then start it.
terminalbash
test -f nika.yaml || printf 'nika: my-project\n' > nika.yaml
mkdir -p .nika && (umask 077 && openssl rand -hex 24 > .nika/serve.token)
printf '.nika/\n' >> .gitignore # traces, job state and the token stay out of git
./node_modules/.bin/nika serve \
--bind 127.0.0.1:8787 --workflows . \
--token-file .nika/serve.token
02
Run through it
A run over HTTP takes an idempotency key you store before the call. It reports run.started then run.settled, and the same outputs.
remote.mjsJavaScript
import { readFile } from 'node:fs/promises'
import { Nika } from '@nika-open/nika'
const token = (await readFile('.nika/serve.token', 'utf8')).trim()
const nika = new Nika({
url: 'http://127.0.0.1:8787',
token,
allowInsecureHttp: true, // plain HTTP: loopback only
})
// over HTTP, a run takes a key you store before the call
const run = await nika.run('hello.nika', {
idempotencyKey: 'hello-first-run',
})
for await (const event of run.events()) console.log(event.kind)
console.log((await run.result()).outputs)