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

# TypeScript SDK

> Run .nika workflows from a TypeScript application, local or on your server, with typed results and verifiable receipts.

`@supernovae-st/nika` runs `.nika` workflows from your application and proves
what they did. Your product owns the request, the interface and the business
state. The Nika engine owns parsing, admission, execution, policy, events,
receipts and traces, and the engine comes inside the npm package.

```sh theme={"system"}
npm install @supernovae-st/nika@0.124.1
```

The first integration is two calls, admit and settle:

```ts theme={"system"}
import { Nika, isNikaRunSucceeded } from '@supernovae-st/nika'

const nika = new Nika({ cwd: process.cwd() })

const run = await nika.run('hello.nika', { maxCostUsd: 0 })
const result = await run.result()

if (!isNikaRunSucceeded(result)) {
  // 'failed' carries the engine's error; 'paused' waits on a human gate
  throw new Error(`run ended as ${result.status}`)
}
console.log(result.outputs)
```

`run()` admits the workflow **before** it returns: a file the engine refuses
throws a typed `NikaOperationError`, and no handle is ever handed out.
`result()` is the one settlement: an admitted workflow that fails resolves as
`status: 'failed'` data, not a throw. The [quickstart](https://docs.nika.sh/sdk/start/quickstart.md)
runs this end to end in five minutes.

## Two doors, one client

```mermaid theme={"system"}
flowchart LR
  app(["Your app"]) --> sdk["@supernovae-st/nika"]
  sdk -->|"new Nika({ cwd })"| local["bundled engine<br/>child process"]
  sdk -->|"new Nika({ url, token })"| serve["nika serve --bind<br/>your server"]
  local --> out["typed result + receipt"]
  serve --> out
```

```ts theme={"system"}
const local = new Nika({ cwd: process.cwd() })
const remote = new Nika({
  url: 'https://nika.example.com',
  token: process.env.NIKA_TOKEN!,
})
```

Omit `url` for the local transport. Supply `url` and `token` for HTTP. On a
server, a served name such as `workflows/release.nika` (the workflow's path
from the server's project root) needs no local engine or file; an explicit
local path such as `./release.nika` uses a compatible local engine to capture
an immutable snapshot first. [How the SDK works](https://docs.nika.sh/sdk/how-it-works.md) compares
the two doors line by line.

<video controls muted playsInline preload="none" poster="/images/posters/sdk-doors.png" aria-label="Animated illustration of the two doors: new Nika() starts the bundled engine nika 0.123.0 as a child process and new Nika({ url, token }) reaches nika serve; lines 3 and 6 of demo.mts switch between them, line 3's cwd: process.cwd() becoming url, token, allowInsecureHttp: true and line 6's maxCostUsd: 0 becoming idempotencyKey; the engine refuses list-files.nika with NIKA-SEC-004 before any run exists, runs hello.nika, streams six local or two server events, seals six hash-chained journal lines and verifies the receipt, and one changed byte makes the verifier report BROKEN at line 5" alt="Animated illustration of the two doors: new Nika() starts the bundled engine nika 0.123.0 as a child process and new Nika({ url, token }) reaches nika serve; lines 3 and 6 of demo.mts switch between them, line 3's cwd: process.cwd() becoming url, token, allowInsecureHttp: true and line 6's maxCostUsd: 0 becoming idempotencyKey; the engine refuses list-files.nika with NIKA-SEC-004 before any run exists, runs hello.nika, streams six local or two server events, seals six hash-chained journal lines and verifies the receipt, and one changed byte makes the verifier report BROKEN at line 5">
  <source src="https://mintcdn.com/supernovae-acdf3706/BQMaEHUNhf9JYml1/videos/sdk-doors.mp4?fit=max&auto=format&n=BQMaEHUNhf9JYml1&q=85&s=83c30c9f83de7c4843e1a6f1d200c090" type="video/mp4" />
</video>

**An illustration of the two doors, with captured content.** `new Nika()` starts the bundled engine as a child process, and `new Nika({ url, token })` reaches `nika serve` with the same methods and other options. Two lines of `demo.mts`, the quick start in the package README, change between them: line 3, the constructor, takes `url`, `token` and `allowInsecureHttp: true`, which a plain `http://` URL to a loopback host needs, and line 6, the run options, takes an `idempotencyKey` in place of `maxCostUsd`, which a server run refuses. The engine checks before anything runs: it refuses `list-files.nika` with `NIKA-SEC-004`, so no run exists, and runs `hello.nika`. The app reads six events from the local engine or two from the server, the run's record is sealed, `traceVerify(receipt)` answers `verified` locally and `sealed` from the server, and one changed byte makes the verifier report `BROKEN at line 5`. *An illustration: every code line, event, verdict, hash and version on screen was captured from `@supernovae-st/nika` 0.123.0, its bundled engine `nika 0.123.0 (0bfde3765)` and `nika serve` 0.123.0 in a `mock/echo` rehearsal; the cards, lanes, packets and pacing are drawn, and a real run takes milliseconds.*

## One lifecycle vocabulary

| Intent | Method | Door |
| - | - | - |
| Audit | `check(workflow, options?)` | both |
| Author a candidate | [`compile(request, options?)`](https://docs.nika.sh/sdk/local/compile) | both |
| Admit and execute | `await run(workflow, options?)` | both |
| Observe | [`run.events(options?)`](https://docs.nika.sh/sdk/runtime/events) | both |
| Settle | [`await run.result()`](https://docs.nika.sh/sdk/runtime/results) | both |
| Cancel | `run.cancel()` | both |
| Verify proof | [`traceVerify(receipt, options?)`](https://docs.nika.sh/sdk/runtime/receipts) | both |
| Recover a durable job | `attachRun(id, options?)` | HTTP only |
| Read live status | `run.status()` | HTTP only |
| Discover workflows | `listWorkflows()` · `workflow(name)` | HTTP only |
| Manage one schedule | [`schedule()` · `scheduleStatus()`](https://docs.nika.sh/sdk/remote/schedules) | HTTP only |
| Download what a job produced | [`run.artifacts()` · `run.readArtifact()` · `run.downloadArtifact()`](https://docs.nika.sh/sdk/remote/artifacts) | HTTP only |

`run()` returns a handle only after admission; the handle is not a result.
Events are optional to render; `run.result()` is the run's one ending,
including a pause at a human gate. Locally, a paused run resumes from the
command line; `nika serve` 0.124.1 has no route to answer the gate.
Configuration, compatibility, transport and protocol failures throw typed
[errors](https://docs.nika.sh/sdk/runtime/errors.md).

> [accordion] Compatibility aliases from earlier releases
>
> `nika.events(run)`, `nika.cancel(run)`, `nika.status(run)` and `run.done`
> remain as deprecated aliases. `run.done` is the same promise as
> `run.result()`. New code should call the methods on the run handle:
> `run.events()`, `run.result()`, `run.cancel()`, `run.status()`.

## Documentation map

> [card] [How it works](https://docs.nika.sh/sdk/how-it-works.md)
>
> The two doors, the run lifecycle and who owns what.

> [card] [Start](https://docs.nika.sh/sdk/start/quickstart.md)
>
> Install the published package and complete one typed, verified run.

> [card] [Project](https://docs.nika.sh/sdk/project/nika-yaml.md)
>
> nika.yaml, arm policy, precedence and runtime state.

> [card] [Local API](https://docs.nika.sh/sdk/local/client.md)
>
> Check, run, observe, cancel and compile through the bundled engine.

> [card] [Runtime](https://docs.nika.sh/sdk/runtime/results.md)
>
> Results, events, errors, receipts, spend caps and permits.

> [card] [Remote API](https://docs.nika.sh/sdk/remote/serve-quickstart.md)
>
> Authenticated jobs, recovery, SSE, workflows and schedules on nika serve.

> [card] [Operations](https://docs.nika.sh/sdk/operations/ci.md)
>
> CI admission, resident serving, OS schedulers and security.

> [card] [Reference](https://docs.nika.sh/sdk/reference/methods.md)
>
> Constructor, methods, errors and exported types.

## Authority boundary

* The SDK does not parse a second Nika language.
* It does not reconstruct traces or receipts in TypeScript.
* An observer `AbortSignal` does not cancel a run; call `run.cancel()`.
* It does not infer success from an event kind.
* It exposes only the routes the released server answers.

## Version and channel

> [accordion] Which published release these pages describe
>
> > [!NOTE]
> >
> > These pages describe the published `@supernovae-st/nika@0.124.1`
> > [SDK release](https://github.com/supernovae-st/nika-client/tree/v0.124.1) and its matching
> > [bundled engine](https://github.com/supernovae-st/nika/releases/tag/v0.124.1). A newer engine
> > release or SDK main commit does not change an installed package. Use Node.js
> > 22 or newer, on macOS (arm64, x64) or Linux with glibc (x64, arm64); no
> > global Nika installation is required for local mode.
>
> > [!NOTE]
> >
> > **Live project control plane.** The released engine
> > discovers `nika.yaml` from the working directory toward its
> > ancestors. The file is optional when built-in defaults are enough. Its
> > project-shape grammar is closed: `nika` ·
> > `ceiling` · `arm` · `traces` ·
> > `registry`. Direct runs and the cadence path
> > (`nika arm` · `nika serve`) read the same file.
>
> > [!TIP]
> >
> > **One client, local by default.** Import `Nika` from
> > the package root and omit `url`. The client takes the engine
> > from `bin`, then `NIKA_BIN` (both absolute paths), then
> > the platform package npm installed with it; it never uses a
> > `nika` found on your `PATH`. These examples target
> > the published [0.124.1 SDK release](https://github.com/supernovae-st/nika-client/tree/v0.124.1).
>
> > [!NOTE]
> >
> > **The same client selects HTTP when `url` and
> > `token` are present.** A served name such as
> > `workflows/release.nika` (its path from the project root) goes
> > directly to the server and needs no local engine or file. An explicit local
> > path such as `./release.nika` needs a compatible local engine to
> > capture an immutable snapshot. The released OpenAPI of
> > `nika serve` 0.124.1 covers jobs, SSE events,
> > cancellation, trace verification, the artifacts a settled job's sealed
> > journal records (behind `run.artifacts()`), workflow listing,
> > schedule read and write, and stateless authoring
> > (`POST /v1/compile`, behind `compile()`). It has no
> > `POST /v1/run`, job-list, or schedule list, delete, trigger
> > or backfill route. The server owns its engine version; check its
> > compatibility separately from the bundled local engine.

> [card] [Review the published source](https://github.com/supernovae-st/nika-client/tree/v0.124.1)
>
> The source of the published SDK release and its engine payloads.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.