> ## 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.

# Your first workflow

> Write one .nika file by hand, check it, run it offline, read the result.

**Goal:** write one file, run it offline, read a typed output. No API key,
no model server, nothing leaves your machine.

> [!NOTE]
>
> [Install Nika](https://docs.nika.sh/getting-started/installation.md) first if you have not. This
> page writes each file by hand so you learn every line; to describe a job in
> your own words instead, open the [terminal Session](https://docs.nika.sh/getting-started/session.md).

## 1. Write the file

Create `hello.nika`:

```yaml hello.nika theme={"system"}
nika: hello
model: mock/echo        # rehearsal model: echoes the prompt, no network
permits: {}             # explicit: this workflow touches nothing
tasks:
  greet:
    infer:
      prompt: "Say hello to a new user, briefly."
      max_tokens: 32
outputs:
  greeting: ${{ tasks.greet.output }}
```

* **`nika: <name>`** is the mark and the workflow's kebab-case identifier.
* **`model: mock/echo`** needs no key and no server — the engine echoes the
  prompt back. The mechanics are real; the "answer" is a rehearsal.
* **`permits: {}`** declares zero authority up front. A workflow that later
  touches a file, a host or a shell must say so here, or admission refuses
  it (`NIKA-SEC-004`, naming the missing permission).
* **`max_tokens`** caps the answer's length.
* **`outputs:`** names what the run hands back.

## 2. Check it, then run it

```bash theme={"system"}
nika check hello.nika   # static audit — before a single token is spent
nika run hello.nika
```

Captured from `nika 0.123.1` on a fresh machine, offline. The audit ends
fully green (`audited · 1 task · 1 wave · permits {} · est out ≤$0.0000 · 0
hints · risk low`, then `layers · valid ✔ · access ready ✔ · capacity fit ✔ ·
run ready ✔`), and the run prints:

```text theme={"system"}
  ✔  greet  infer · mock/echo  3ms
  1 task · 1 wave · 0 retries · 9 tok
  ── 1/1 done · unpriced (1 call) · elapsed 0.0s ─────────────────
    wrote .nika/traces
    said "mock(echo) · Say hello to a new user, brief…"
    see it whole: nika trace outputs
    rehearsal · a mock model echoed the prompt — not a real answer
  explore: nika run hello.nika --json > run.ndjson · nika trace outputs run.ndjson
    trace: .nika/traces/2026-10-25T11-48-15Z-d0f5.ndjson · 5 events · chain 9ad6d842…
```

`nika check` catches broken references, missing dependencies and schema
problems before any model is called, and points at the exact fix. The run
wrote a hash-chained record under `.nika/traces/`. `unpriced (1 call)` is the
honest total for a model the catalog cannot price: never `$0.00`. Verify the
latest record:

```bash theme={"system"}
nika trace verify
```

```text theme={"system"}
OK — 5 events · chain intact · head 9ad6d842614fc0136921dc3fa14fe97c2d58acb953e96bd1ecbae1fd68467020
  internally consistent (tamper-evident, not tamper-proof) — compare the head
  against the one the run printed to close the loop
UNSEALED — no run_sealed frame: the run was not signed (no signing key at run time · a run killed before its seal · or a journal cut after it) — a run key (`nika key init`) makes later runs seal · `--sealed` requires the tier
…
```

The chain is intact, but the run is `UNSEALED`: this machine has no
run-signing key yet. Mint one once, run again, and the record is signed:

```bash theme={"system"}
NIKA_KEYCHAIN=off nika key init
nika run hello.nika
nika trace verify     # … SEALED — the run_sealed signature verifies · key …
```

Verification re-executes nothing: it reads the record and reports the
evidence available to it. A missing key changes the verdict, not the run's
result. [Seal your runs](https://docs.nika.sh/getting-started/installation.md#seal-your-runs)
explains the variable and where the key is stored.

## 3. Ask the file three questions

> [accordion] What if a required input is missing?
>
> Mark an input `required: true` (with no `default:`) and the run refuses
> to start without it (`NIKA-1708`, exit 3): admission fails, nothing
> half-executes. An input with neither `required: true` nor a `default:`
> does not stop the start: the first task that reads it fails
> (`NIKA-VAR-001`, exit 1). Callers pass values with
> `run(..., { inputs })` in the SDK or `--var key=value` on the CLI.

> [accordion] What if a permission is absent?
>
> Admission refuses at check; the finding names the missing
> permission. An absent `permits:` block is zero authority
> (`NIKA-AUTH-006`). A declared `permits: {}` that omits a reached
> tool or path is `NIKA-SEC-004` — the plate below. The file needs
> both the named tool (`nika:read`) and the specific path
> (`./hello.nika`). `nika check --infer-permits` drafts the
> tightest block for you.

> [accordion] What if I switch the model?
>
> One line. `ollama/llama3.2:3b` runs locally after
> `ollama pull llama3.2:3b`; a cloud provider takes its environment key
> (`export MISTRAL_API_KEY=...` for `mistral/mistral-small-latest`). A
> reasoning (thinking) model spends its thinking inside `max_tokens`, so
> raise the cap when you switch to one: `nika check` names the minimum for
> a cataloged reasoning model. The file, the check and the record keep the
> same shape; only the answer changes. `nika doctor` reports what your
> machine can reach.

Measured CLI **0.120.1** plates (condensed, not a live recording); the
refusal is unchanged in 0.124.3. Press play: nothing autoplays.

<video controls playsInline preload="none" poster="/images/posters/check-denied.webp" aria-label="nika check refusing a workflow that lacks the permits it needs" alt="nika check refusing a workflow that lacks the permits it needs">
  <source src="https://mintcdn.com/supernovae-acdf3706/sfsgY9WBv_OMsIOX/videos/check-denied.webm?fit=max&auto=format&n=sfsgY9WBv_OMsIOX&q=85&s=95ba9da96f2047015863e58dc918fa96" type="video/webm" />

  <source src="https://mintcdn.com/supernovae-acdf3706/sfsgY9WBv_OMsIOX/videos/check-denied.mp4?fit=max&auto=format&n=sfsgY9WBv_OMsIOX&q=85&s=bb65f9308bd6e6e6fb6ff54a6dda185a" type="video/mp4" />
</video>

<details>
  <summary>What this plate shows</summary>
  `nika check denied.nika` on CLI 0.120.1. Task `peek` would invoke
  `nika:read` on `./hello.nika`. `permits: {}` grants nothing.
  Admission refuses with `NIKA-SEC-004`. Adding only
  `permits.tools: ["nika:read"]` still refuses: the path
  `./hello.nika` is outside `permits.fs.read`. Authorize both the
  named tool and that specific file path. Nothing ran. Condensed
  measured plate, not the TypeScript SDK.
</details>

[Download GIF](https://docs.nika.sh/images/gifs/check-denied.gif)

## 4. Add a second task that depends on the first

Save this as `greet-chain.nika`:

```yaml greet-chain.nika theme={"system"}
nika: greet-chain
model: mock/echo
permits: {}
tasks:
  greet:
    infer:
      prompt: "Say hello to a new user, briefly."
      max_tokens: 32

  critique:
    with:
      greeting: ${{ tasks.greet.output }}  # the binding IS the edge
    infer:
      prompt: |
        The greeting was: ${{ with.greeting }}
        Rewrite it shorter.
      max_tokens: 32
outputs:
  shorter: ${{ tasks.critique.output }}
```

The `with:` block is a [binding](https://docs.nika.sh/concepts/bindings.md): it names the data the
task consumes and declares the edge that orders it — greet → critique, one
declaration, no invisible edges. Tasks with no edge between them run in
parallel automatically. (For ordering without data, such as deploy after
tests while consuming nothing, use `after: { tests: success }`.) The
`outputs:` line matters too: without a consumer, `nika check` points out that
the last task's tokens would be spent unread (`[dead-spend]`).

## 5. Get structured output

Save this as `names.nika`:

```yaml names.nika theme={"system"}
nika: names
model: mock/echo
permits: {}
tasks:
  names:
    infer:
      prompt: "Generate three names for a butterfly."
      max_tokens: 200
      schema:                          # structured output · JSON Schema
        type: object
        additionalProperties: false
        properties:
          names:
            type: array
            items:
              type: string
              minLength: 3
              maxLength: 20
            minItems: 3
            maxItems: 3
        required: [names]
outputs:
  names: ${{ tasks.names.output.names }}
```

The engine asks the provider for output that conforms (using each
provider's native structured-output mode where the [capability
rules](https://docs.nika.sh/reference/capabilities.md) allow it) and validates the reply against
your schema before passing it on. The mock validates too — it synthesizes
a conformant instance, so this exact file runs offline. Captured from
`nika 0.123.1` (`nika run names.nika --output json`):

```json theme={"system"}
{"names":["mock","mock","mock"]}
```

`${{ tasks.names.output.names }}` indexes into the validated object, so the
output is the array itself. `additionalProperties: false` closes the shape,
so every provider returns the same keys.

On a **successful** run, `outputs:` carries the declared shape — checked
when the model answers. A failed or refused run produces no output: the
guarantee covers shape, not outcome.

## 6. See a real job

This short recorded demonstration turns synthetic notes into an action
list using `xai/grok-3-mini`, on CLI 0.120.1 with condensed timing. The
0.124.3 catalog no longer lists that model: to reproduce it, pick a model
`nika catalog` lists, for example `xai/grok-4.3` (a reasoning model, so give
it `max_tokens` of at least 256) with your `XAI_API_KEY`.

The demonstration file has no typed schema, so the run exports a
**string**. The full [meeting-actions](https://docs.nika.sh/examples/meeting-actions.md)
example declares `{owner, task, due}` and exports typed actions.

<video controls playsInline preload="none" poster="/images/posters/meeting-actions.webp" aria-label="CLI 0.120.1 running a measured xai/grok-3-mini meeting-notes job" alt="CLI 0.120.1 running a measured xai/grok-3-mini meeting-notes job">
  <source src="https://mintcdn.com/supernovae-acdf3706/sfsgY9WBv_OMsIOX/videos/meeting-actions.webm?fit=max&auto=format&n=sfsgY9WBv_OMsIOX&q=85&s=7e689553fd7b969f05efc995e69948ca" type="video/webm" />

  <source src="https://mintcdn.com/supernovae-acdf3706/sfsgY9WBv_OMsIOX/videos/meeting-actions.mp4?fit=max&auto=format&n=sfsgY9WBv_OMsIOX&q=85&s=f68fd936d02360f1af0e7a9d3f306ab5" type="video/mp4" />
</video>

<details>
  <summary>What this plate shows</summary>
  Synthetic notes: Maya ships the changelog Friday; Leo pings legal
  about the DPA; Sam books the staging window. `nika run
      meeting-actions.nika --model xai/grok-3-mini` on CLI 0.120.1
  (`9d554c84c`) returned:

  Maya — ship the changelog (Friday).
  Leo — ping legal about the DPA (TBD).
  Sam — book the staging window (TBD).

  Measured: 11.4s · 29 output tokens · 235 in · 192 cached · \$0.00114.
  Condensed plates of a live infer, not a mock rehearsal.
</details>

[Download GIF](https://docs.nika.sh/images/gifs/meeting-actions.gif)

## What you just built

* Workflows are YAML files: `.nika`.
* Tasks are units of work; the map key is the identity.
* Four verbs (`infer`, `exec`, `invoke`, `agent`) define what each task
  does (HTTP fetch is the `nika:fetch` builtin under `invoke`).
* `with:` (data) and `after:` (control) build the DAG — the binding IS the
  edge.
* `${{ tasks.X.output }}` crosses a task boundary in `with:`; the body
  reads `${{ with.<name> }}`.
* `schema:` checks AI output shape at answer time; `outputs:` exports the
  result.

## Next lesson

**1. Drive it from an app**

[SDK quickstart](https://docs.nika.sh/sdk/start/quickstart.md): the same file through
`check` → `run` → `result` → `traceVerify` in TypeScript.

**2. Inspect the DAG**

`nika inspect hello.nika` (add `--format mermaid|dot|json` for the
machine projections); `nika explain hello.nika` narrates the waves and
the cost before a token is spent.

**3. Wire your agent**

Run `nika wire detected --dry-run` to preview, then `nika wire detected`
to add Nika's MCP server to the agent clients this machine shows, or
`nika wire cursor` for one client.

## Read next

> [card] [Examples · real jobs](https://docs.nika.sh/examples/overview.md)
>
> Starter chains to multi-step reports: every file passes `nika check`, and
> each page lists what it needs to run.

> [card] [How to write Nika](https://docs.nika.sh/guides/patterns.md)
>
> The patterns of well-written Nika, each taught by a canonical example.

> [card] [The 4 verbs](https://docs.nika.sh/concepts/verbs.md)
>
> Deep dive on `infer`, `exec`, `invoke`, `agent`.

> [card] [Bindings](https://docs.nika.sh/concepts/bindings.md)
>
> How data flows between tasks with taint tracking.

> [card] [Providers](https://docs.nika.sh/concepts/providers.md)
>
> Why one `InferRequest` works across 18 providers.

> [card] [Cost honesty](https://docs.nika.sh/guides/cost-honesty.md)
>
> Read the cost report: floors, ceilings and honest « unpriced ».


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