# Workflows: 5-Minute Guide

> From starter template to browser test run, immutable v1 publish and your first production API call.

- **Source:** https://www.noirdoc.de/en/docs/guides/workflows/
- **API base URL:** `https://api.noirdoc.de/v1`

With **Noirdoc Workflows**, you chain typed JSON inputs, single-pass Shield inspection and multiple EU models on a visual drafting canvas, then call the entire pipeline through one synchronous endpoint.

> **Beta & prerequisites:** Workflows is in Beta and enabled by default for every active organisation (1 to 10 linear steps, synchronous JSON without streaming, up to 300 s wall-clock timeout). Creating, editing, test-running, publishing and archiving require the `admin` role (`member` users have read-only access).

## What you call in production

Instead of wiring two SDKs, PII redaction and JSON retry loops in your backend, five minutes of setup gets you down to a single synchronous call:

**Python**

```python
import os
import httpx

key = os.environ["NOIRDOC_API_KEY"]
res = httpx.post(
    "https://api.noirdoc.de/v1/workflows/support-triage/v1/run",
    headers={"Authorization": f"Bearer {key}"},
    json={
        "message": "Order #48291 from Max Weber arrived damaged.",
        "channel": "email",
    },
    timeout=310,
)
res.raise_for_status()
print(res.json()["output"])
```

**TypeScript**

```ts
const url = "https://api.noirdoc.de/v1/workflows/support-triage/v1/run";

const res = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NOIRDOC_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    message: "Order #48291 from Max Weber arrived damaged.",
    channel: "email",
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const { output } = await res.json();
console.log(output);
```

**curl**

```bash
curl https://api.noirdoc.de/v1/workflows/support-triage/v1/run \
  -H "Authorization: Bearer $NOIRDOC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Order #48291 from Max Weber arrived damaged.",
    "channel": "email"
  }'
```

**200 Response**

```jsonc
// 200 OK · 2 models, 1× Shield, 1 synchronous call
{
  "workflow": "support-triage",
  "version": 1,
  "output": {
    "category": "damaged_item",
    "urgency": "high",
    "reply_draft": "We are shipping a replacement for order #48291.",
  },
  "meta": {
    "duration_ms": 1842,
    "total_cost_eur": "0.006120",
    "detected_types": ["PERSON"],
  },
}
```

**403 Shield**

```jsonc
// 403 Forbidden · Shield block at ingress (€0 model cost)
{
  "error": {
    "code": "shield_violation",
    "message": "Input blocked by Noirdoc Shield policy.",
    "blocked_rule": "pii",
    "detected_types": ["PERSON", "IBAN"],
  },
  "meta": {
    "workflow": "support-triage",
    "version": 1,
    "model_cost_eur": "0.000000",
    "shield_cost_eur": "0.000020",
    "workflow_fee_eur": "0.002000",
    "total_cost_eur": "0.002020",
  },
}
```

One request runs input validation, single-pass Shield inspection, both model steps and local `output_schema` checks. The five steps to your first call take five minutes in the Portal.

## Step-by-step setup

### 1. Create from a template in the Portal

Open **Workflows** in the [Noirdoc Portal](https://portal.noirdoc.de) and choose one of three starter templates:

| Template           | Slug               | Models                                       | Default Shield |
| ------------------ | ------------------ | -------------------------------------------- | -------------- |
| Support triage     | `support-triage`   | `mistral4-119b` → `claude-sonnet-5-5`        | `redact`       |
| Invoice extraction | `beleg-extraktion` | `gemini-3.8-flash` (Vision) → `gpt-5.4-mini` | `off`          |
| Feedback analysis  | `feedback-analyse` | `gpt-oss-120b` → `claude-sonnet-5-5`         | `redact`       |

The draft opens on the visual canvas with five connected nodes (`IN`, `PII`, `01`, `02`, `OUT`). Creating, editing, test-running, publishing and archiving workflows require the `admin` role; organisation `member` users have read-only access to workflows, versions and run metadata.

### 2. Inspect steps, files and Shield on the canvas

Click any node to review its configuration in the inspector:

#### Input schema (`IN`)

*JSON Schema Draft 2020-12*

Defines required fields and types using JSON Schema Draft 2020-12 (required `message` and optional `channel` in `support-triage`). For PDFs, images or text files, mark a string property with `"format": "data-url"` (at most 10 MB decoded per file, 15 MB total request body).
  #### Noirdoc Shield (`PII`)

*off · block · redact*

Selects `off`, `block` or `redact`. When your organisation is set to `enforced` under **Models → Shield**, `off` is disabled (422 `shield_enforced_cannot_disable`) and binary PDFs or images are rejected with 422 `shield_uninspectable_content`.
  #### Prompt steps (`01 / 02`)

*Multi-model & Vision*

Pick any model from your organisation's catalogue (mixing OpenAI, Gemini and Anthropic wires freely), reference text values with `{{input.message}}` and `{{steps.classify.category}}`, and pass file inputs via `attachments: ["input.receipt_file"]` directly to Vision models such as `gemini-3.8-flash`, `claude-sonnet-5-5` or `gpt-5.4-mini`.
  #### Output schema (`OUT`)

*Max. 1× auto-repair*

Validates the final JSON locally against Draft 2020-12 and runs at most one automatic repair call on mismatch.

> **Your input:** Order #48291 for Max Weber (DE89 3704 0044 0532 0130 00) arrived damaged.
> **Sent to the model:** Order #48291 for [PERSON] ([IBAN]) arrived damaged.

### 3. Run a browser test

As an `admin`, click **Test run** in the top bar with the synthetic sample payload. Browser test runs bill against your organisation's balance (no API key paste required) and enforce your [§ 203 StGB posture](/en/docs/routing/#berufsgeheimnistraeger).

Each node updates live with latency, executing provider, detected Shield categories and real EUR cost (model + Shield + €0.002 workflow fee). Intermediate step outputs return live in the HTTP response only – nothing is stored.

### 4. Publish version `v1`

Once the test run passes, click **Publish** as an `admin`. The engine stores an immutable `v1` snapshot (stripping `sample_input` and `ui_layout`). Later draft edits never affect live calls to `v1` until `v2` is published.

### 5. Call the published workflow

Invoke the workflow using your existing `px-` key at `POST /v1/workflows/{slug}/v1/run` (pinned) or `POST /v1/workflows/{slug}/run` (latest version) – optionally with `X-Noirdoc-Tags` for [tag budgets](/en/docs/keys-billing/#budgets):

**Python**

```python
import os
import httpx

url = "https://api.noirdoc.de/v1/workflows/support-triage/v1/run"
res = httpx.post(
    url,
    headers={
        "Authorization": f"Bearer {os.environ['NOIRDOC_API_KEY']}",
        "X-Noirdoc-Tags": "support-inbox",
    },
    json={
        "message": "Order #48291 from Max Weber arrived damaged.",
        "channel": "email",
    },
    timeout=310,
)
res.raise_for_status()
data = res.json()
print(data["output"], data["meta"]["total_cost_eur"])
```

**TypeScript**

```ts
const url = "https://api.noirdoc.de/v1/workflows/support-triage/v1/run";

const res = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NOIRDOC_API_KEY}`,
    "Content-Type": "application/json",
    "X-Noirdoc-Tags": "support-inbox",
  },
  body: JSON.stringify({
    message: "Order #48291 from Max Weber arrived damaged.",
    channel: "email",
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(data.output, data.meta.total_cost_eur);
```

**curl**

```bash
curl https://api.noirdoc.de/v1/workflows/support-triage/v1/run \
  -H "Authorization: Bearer $NOIRDOC_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Noirdoc-Tags: support-inbox" \
  -d '{
    "message": "Order #48291 from Max Weber arrived damaged.",
    "channel": "email"
  }'
```

**200 Response**

```json
{
  "workflow": "support-triage",
  "version": 1,
  "run_id": "wfr_019a7f3c9d2e4b81",
  "output": {
    "category": "damaged_item",
    "urgency": "high",
    "reply_draft": "We are shipping a replacement for order #48291."
  },
  "meta": {
    "duration_ms": 1842,
    "model_cost_eur": "0.004100",
    "shield_cost_eur": "0.000020",
    "workflow_fee_eur": "0.002000",
    "total_cost_eur": "0.006120",
    "pii_mode": "redact",
    "detected_types": ["PERSON"],
    "repair_attempted": false,
    "steps": [
      {
        "key": "classify",
        "model": "mistral4-119b",
        "provider": "aki-io",
        "wire_format": "openai",
        "duration_ms": 410,
        "prompt_tokens": 184,
        "completion_tokens": 42,
        "cost_eur": "0.000400"
      },
      {
        "key": "draft",
        "model": "claude-sonnet-5-5",
        "provider": "anthropic-gcp",
        "wire_format": "anthropic",
        "duration_ms": 1418,
        "prompt_tokens": 312,
        "completion_tokens": 96,
        "cost_eur": "0.003700"
      }
    ]
  }
}
```

Production calls return only the validated `output` object and step metadata.

## Passing PDFs & images with Vision (`beleg-extraktion`)

For document and image workflows such as `beleg-extraktion`, pass files as base64 data URLs (`format: "data-url"`, up to 10 MB decoded per file, 15 MB total request body). Bind the field in a prompt step via `attachments: ["input.receipt_file"]` on a Vision model (`gemini-3.8-flash`, `claude-sonnet-5-5` or `gpt-5.4-mini`):

**Python**

```python
import base64
import os
import httpx

pdf_b64 = base64.b64encode(open("invoice.pdf", "rb").read()).decode()
res = httpx.post(
    "https://api.noirdoc.de/v1/workflows/beleg-extraktion/v1/run",
    headers={"Authorization": f"Bearer {os.environ['NOIRDOC_API_KEY']}"},
    json={"receipt_file": f"data:application/pdf;base64,{pdf_b64}"},
    timeout=310,
)
res.raise_for_status()
print(res.json()["output"])
```

**TypeScript**

```ts
import { readFileSync } from "node:fs";

const url = "https://api.noirdoc.de/v1/workflows/beleg-extraktion/v1/run";
const pdfB64 = readFileSync("invoice.pdf").toString("base64");
const res = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.NOIRDOC_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    receipt_file: `data:application/pdf;base64,${pdfB64}`,
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const { output } = await res.json();
console.log(output);
```

**curl**

```bash
{
  printf '%s' '{"receipt_file":"data:application/pdf;base64,'
  base64 < invoice.pdf | tr -d '\n'
  printf '%s\n' '"}'
} | curl https://api.noirdoc.de/v1/workflows/beleg-extraktion/v1/run \
  -H "Authorization: Bearer $NOIRDOC_API_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @-
```

**200 Response**

```json
{
  "workflow": "beleg-extraktion",
  "version": 1,
  "output": {
    "invoice_no": "INV-2026-412",
    "vendor": "CloudHost GmbH",
    "net_eur": 420.0,
    "vat_rate": 0.19,
    "gross_eur": 499.8
  }
}
```

Allowed MIME types are PDF (`application/pdf`), images (PNG, JPEG, WebP, GIF) and UTF-8 text files. When your organisation Shield policy is `enforced`, binary PDFs or images return 422 `shield_uninspectable_content` (€0 fee).

## `/run` vs. `/v1/run` & error handling

#### Pinned version for production (`/v1/workflows/{slug}/v1/run`)

*Recommended*

Keeps your application locked to immutable `v1`, even after an `admin` publishes `v2` with updated prompts or models.
  #### Unpinned for staging (`/v1/workflows/{slug}/run`)

*Always latest version*

Always runs the latest published version – useful for verifying prompt and model changes without a backend deploy.

> **Always branch on error.code in client code:** Branch on `error.code` rather than `message`: 401 `invalid_api_key` indicates a missing, invalid or disabled API key or an inactive organisation (€0), 413 `payload_too_large` indicates a request exceeding the 15 MB body cap or 10 MB per-file cap (€0), 422 `invalid_workflow_input` reports failing `input_schema` paths (`details`, without raw values, €0), 422 `shield_uninspectable_content` rejects binary PDFs or images under `enforced` Shield (€0), and 403 `shield_violation` returns `blocked_rule`, `detected_types` and `meta` (€0.00 model tokens; Shield inspection and the single €0.002 workflow run fee apply normally). See concrete error payloads and all codes in the [API reference](/en/docs/reference/workflows/#fehlercodes).

## Related pages

- [**Workflows: Concepts & Architecture**](/en/docs/concepts/workflows/) — Execution lifecycle, Draft 2020-12 schemas, safe variable interpolation, Shield guarantees and pricing.
- [**Workflows: API Reference**](/en/docs/reference/workflows/) — Full headers, response fields, Vision attachments and error codes for /v1/workflows/{slug}/run.
