# Workflows

> Synchronous execution endpoint for published multi-model workflows with typed JSON input and output, Shield metadata and EUR cost breakdown.

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

**POST** `https://api.noirdoc.de/v1/workflows/{slug}/run`
**POST** `https://api.noirdoc.de/v1/workflows/{slug}/v{n}/run`

Executes a published workflow version synchronously and returns the schema-validated output JSON together with per-step and EUR cost metadata. Omitting `/v{n}` executes the latest published version; specifying `/v{n}` pins execution to version `n`.

> **Beta & synchronous execution:** Workflows is in Beta (1 to 10 linear steps, synchronous JSON without SSE streaming, up to 300 s total wall-clock timeout). Use the pinned `/v{n}/run` route for production clients.

## Authentication & headers

| Header                         | Required | Effect                                                                                                           |
| ------------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `Authorization: Bearer px-...` | Yes      | Active Noirdoc API key for your organisation; key budgets, model allowlists and § 203 rules apply to every step. |
| `Content-Type`                 | Yes      | `application/json` (UTF-8, at most 15 MB; decoded file attachments at most 10 MB per file).                      |
| `X-Noirdoc-Tags`               | Optional | Up to 5 comma-separated request tags; forwarded to every model step and the workflow run fee debit.              |

## Request & response

The request body is a JSON object matching the workflow's `input_schema` (Draft 2020-12).

**Python**

```python
import os
import httpx

url = "https://api.noirdoc.de/v1/workflows/support-triage/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()
payload = res.json()
```

**TypeScript**

```ts
const url = "https://api.noirdoc.de/v1/workflows/support-triage/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 payload = await res.json();
```

**curl**

```bash
curl https://api.noirdoc.de/v1/workflows/support-triage/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": 2,
  "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"
      }
    ]
  }
}
```

All EUR amounts in `meta` are six-decimal strings. On 403 `shield_violation`, the error body lists only `blocked_rule`, `detected_types` and the `meta` cost breakdown (€0.00 model tokens; Shield at €0.40 / 1M tokens and the €0.002 run fee apply normally, never raw values).

### Response fields

#### Workflow identity & run ID (`workflow / version / run_id`)

*string · int · string*

`workflow` names the executed workflow slug (`^[a-z0-9][a-z0-9-]{1,62}$`), `version` the executed immutable version number (`1, 2, …`), and `run_id` the unique run identifier (`wfr_<uuid>`) for support and audit correlation.
  #### Validated output (`output`)

*object*

Result object validated against `output_schema` (Draft 2020-12).
  #### Duration & repair (`meta.duration_ms / repair_attempted`)

*int · bool*

`meta.duration_ms` reports total synchronous execution time in milliseconds; `meta.repair_attempted` is `true` if the engine performed its single automatic schema-repair call on the final step.
  #### Cost breakdown (`meta.*_cost_eur / workflow_fee_eur`)

*string (6 decimals)*

`meta.model_cost_eur` sums gateway model costs across all executed steps in EUR (`0.000000` for BYOK steps), `meta.shield_cost_eur` reports single-pass ingress Shield inspection cost (`0.000000` when `pii_mode` is `off`), `meta.workflow_fee_eur` is the flat orchestration fee (`0.002000` = €2.00 / 1,000 runs, charged per executed run including 403 `shield_violation`), and `meta.total_cost_eur` is the total sum.
  #### Shield metadata (`meta.pii_mode / detected_types`)

*string · array*

`meta.pii_mode` reports the effective Shield mode for the run (`off`, `block` or `redact`); `meta.detected_types` lists detected Shield entity categories (e.g. `["PERSON", "IBAN"]`), never plaintext values.
  #### Step metadata (`meta.steps[]`)

*array*

Per-step execution metadata (fields listed in the table below).

### Fields in `meta.steps[]`

| Field               | Type     | Description                                                                  |
| ------------------- | -------- | ---------------------------------------------------------------------------- |
| `key`               | `string` | Step key from the workflow definition (e.g. `classify`, `draft`).            |
| `model`             | `string` | Model ID executed from your organisation's catalogue.                        |
| `provider`          | `string` | Executing provider slug (e.g. `aki-io`, `anthropic-gcp`, `google`, `azure`). |
| `wire_format`       | `string` | API wire protocol used for the step (`openai` or `anthropic`).               |
| `duration_ms`       | `int`    | Execution time for this individual step in milliseconds.                     |
| `prompt_tokens`     | `int`    | Billed input tokens for the step.                                            |
| `completion_tokens` | `int`    | Billed output tokens for the step.                                           |
| `cost_eur`          | `string` | Gateway model cost for this step in EUR (`0.000000` for BYOK steps).         |

## Files & Vision (`format: "data-url"` & `attachments`)

To pass PDFs, images or text files to a Vision step (such as `gemini-3.8-flash`, `claude-sonnet-5-5` or `gpt-5.4-mini`), declare the input property in `input_schema` with `"format": "data-url"` and reference it in the step via `attachments`:

```json
{
  "input_schema": {
    "type": "object",
    "required": ["receipt_file"],
    "properties": {
      "receipt_file": { "type": "string", "format": "data-url" }
    }
  },
  "steps": [
    {
      "key": "extract",
      "model": "gemini-3.8-flash",
      "attachments": ["input.receipt_file"],
      "prompt": "Extract vendor, invoice number, net total and VAT."
    }
  ]
}
```

- **Allowed MIME types:** `application/pdf`, `image/png`, `image/jpeg`, `image/webp`, `image/gif` and UTF-8 text files (`text/plain`, `text/markdown`, `text/csv`, `application/json`, `application/xml`, `text/xml`).
- **Size caps:** At most 15 MB total JSON body and 10 MB decoded per file.

> **Binary attachments under enforced Shield:** Binary PDFs and images cannot be text-inspected and return 422 `shield_uninspectable_content` (€0 workflow fee) before Step 1 when your organisation policy is `enforced`.

## Limits

| Dimension / limit             | Value                                                               | Error when exceeded                                                                        |
| ----------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Steps per workflow            | 1 to 10 linear steps                                                | 422 on save / publish                                                                      |
| Request body                  | at most 15 MB JSON                                                  | 413 `payload_too_large` (€0 workflow fee)                                                  |
| File attachments (`data-url`) | at most 10 MB decoded per file (PDF, PNG/JPEG/WebP/GIF, UTF-8 text) | 413 `payload_too_large`, 422 `invalid_workflow_input` / 422 `shield_uninspectable_content` |
| Total wall-clock timeout      | 300 s total (steps share the remaining run budget)                  | 504 `workflow_timeout`, 504 `step_timeout`                                                 |
| Streaming (SSE)               | not supported (synchronous JSON only)                               | –                                                                                          |
| Schema auto-repair            | at most 1× on final step                                            | 502 `workflow_output_invalid`                                                              |

See [Error Codes & Limits](/en/docs/reference/error-codes/#grenzen) for all gateway limits.

## Error codes

When an upstream error occurs during a step, the error body adds `step_key` and `model` context and preserves `Retry-After` on 429, 503 and 504.

**Typical error payloads**

**422 Input**

```jsonc
// HTTP 422 Unprocessable Content · €0 workflow fee
{
  "error": {
    "code": "invalid_workflow_input",
    "message": "Input payload does not match workflow input_schema.",
    "details": [
      "$: 'message' is a required property",
      "$.channel: value is not one of the allowed enum values",
    ],
  },
}
```

**403 Shield**

```jsonc
// HTTP 403 Forbidden · €0 models · Shield + €0.002 run fee
{
  "error": {
    "code": "shield_violation",
    "message": "Input blocked by Noirdoc Shield policy.",
    "blocked_rule": "pii",
    "detected_types": ["PERSON", "IBAN"],
  },
  "meta": {
    "run_id": "wfr_019a7f3c9d2e4b81",
    "workflow": "support-triage",
    "version": 2,
    "duration_ms": 64,
    "model_cost_eur": "0.000000",
    "shield_cost_eur": "0.000020",
    "workflow_fee_eur": "0.002000",
    "total_cost_eur": "0.002020",
    "pii_mode": "block",
    "detected_types": ["PERSON", "IBAN"],
  },
}
```

**502 / 504 Step**

```jsonc
// HTTP 502 step_execution_failed (504 step_timeout with Retry-After)
{
  "error": {
    "code": "step_execution_failed",
    "message": "Workflow step failed at upstream provider.",
    "step_key": "draft",
    "model": "claude-sonnet-5-5",
  },
}
```

On 403 `shield_violation`, model tokens are €0.00 while Shield (€0.40 / 1M tokens) and the €0.002 run fee apply normally and are reported in `meta`. On 504 `step_timeout`, the body carries the same `step_key` and `model` fields with `"code": "step_timeout"` and preserves any `Retry-After` header. Raw input values never appear in error payloads.

| Status | Code | Meaning |
| --- | --- | --- |
| 401 | `invalid_api_key` | The key is missing, invalid or deactivated, or the organisation is not active. |
| 402 | `insufficient_credit` | The organisation's credit is used up or lower than the estimated maximum cost of the request (including Noirdoc Shield, also on BYOK routes when Shield is active). |
| 402 | `key_budget_exhausted` | This key's budget is used up for the current period or does not cover the estimated cost of the request. |
| 402 | `tag_budget_exhausted` | The budget of a tag named in `X-Noirdoc-Tags` is used up for the current period or does not cover the estimated cost of the request; `message` names the tag. |
| 403 | `shield_violation` | Noirdoc Shield blocked the request before forwarding to the provider because an active protection filter configured with `block` matched; `message` names the triggered rule (`secrets`, `pii`, `ner`, `injection` or `custom`). |
| 404 | `workflow_not_found` | The workflow slug or requested version does not exist, has been archived or is not yet published for your organisation. |
| 404 | `workflow_version_not_found` | The published version requested in `/v1/workflows/{slug}/v{n}/run` does not exist for this workflow or is less than `1`. |
| 409 | `slug_already_exists` | An active (non-archived) workflow with this `slug` already exists in your organisation. |
| 413 | `payload_too_large` | The JSON body of a workflow call exceeds the 15 MB limit (or an inline file exceeds 10 MB decoded) before schema and Shield inspection (`0 €` workflow fee). |
| 422 | `shield_uninspectable_content` | The Shield policy is `enforced`, and the request carries content that Shield cannot inspect as text (`binary_document` such as PDF or Office, `media_not_inspectable` such as images, audio or video, `file_reference` by ID or URL, `file_too_large` at 4 MiB or above, `file_not_decodable` or `unrecognised_content`). The gateway did not forward the request. |
| 422 | `invalid_workflow_input` | The JSON body violates the workflow's `input_schema` (Draft 2020-12); execution stops before Step 1 with no workflow fee (`details` lists the missing or invalid fields without raw values). |
| 422 | `invalid_template_variable` | A prompt template in step `step_key` references an unknown or missing path under `{{input.*}}` or `{{steps.*}}`. |
| 422 | `shield_enforced_cannot_disable` | The organisation's Shield policy is `enforced`, so a workflow cannot be saved or published with `pii_mode: "off"`. |
| 429 | `resource_exhausted` | The provider reported capacity problems or exhausted credit (status code 429 or 402), even after failover across up to three providers. The response contains `Retry-After` with the wait in seconds. |
| 502 | `workflow_output_invalid` | The final workflow step's output still did not match `output_schema` (Draft 2020-12) after one automatic repair attempt. |
| 502 | `step_execution_failed` | A workflow model step failed with a gateway or provider response carrying no more specific error code; the response includes `step_key` and `model`. |
| 502 | `workflow_charge_failed` | Settling the flat workflow run fee at the gateway was rejected or failed with an unexpected response. |
| 503 | `provider_overloaded` | The provider reported overload (status code 503 or 529), even after failover across up to three providers. The status code is 503 on OpenAI endpoints and 529 on `/v1/messages` and `/v1/skills`. The response contains `Retry-After` with the provider's value between 1 and 60 seconds, otherwise 5 seconds. |
| 503 | `shield_unavailable` | The Noirdoc Shield inspection service is temporarily unreachable; the gateway never forwards a request that requires inspection uninspected (fail-closed). The response contains `Retry-After` with 5 seconds. |
| 503 | `billing_unavailable` | The gateway billing endpoint was temporarily unreachable while settling the workflow run fee. |
| 504 | `workflow_timeout` | The synchronous workflow run exceeded the 300-second total wall-clock limit. |
| 504 | `step_timeout` | A single model step (`step_key`) exceeded the remaining timeout budget of the 300-second run. |

## Related pages

- [**Workflows: 5-Minute Guide**](/en/docs/guides/workflows/) — Create from a starter template, run a browser test, publish v1 and make your first API call.
- [**Workflows: Concepts & Architecture**](/en/docs/concepts/workflows/) — Execution lifecycle, Draft 2020-12 schemas, interpolation, zero payload retention and billing.
