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

# Run abbrechen

> Wartenden oder laufenden Run abbrechen. Erzeugte Datensätze bleiben erhalten.

**`POST`** `https://api-datahub.octoparse.com/v1/runs/{run_id}/cancel`

Authentifizierung: API-Schlüssel erforderlich (`Authorization: Bearer <API Key>`).

Sendet ein Cancel-Signal, wartet kurz (bis 5 Sekunden) auf die Executor-Antwort und gibt das aktuelle Run-Objekt zurück. Gequeuete Runs stoppen sofort; laufende meist kooperativ in wenigen Sekunden. Bereits geschriebene Datensätze bleiben (`partial` = `true`), lesbar, und nur das Produzierte wird abgerechnet.

Ownership entspricht Run-Detail: Sie können nur selbst gestartete Runs abbrechen. Nach Cancel den terminalen Status mit Run abrufen bestätigen.

## Anfrage

### Pfadparameter

<ParamField path="run_id" type="string" required>
  Run-ID.
</ParamField>

### Beispielanfrage

```bash theme={null}
curl -X POST \
  -H "Authorization: Bearer $OCTOPARSE_API_KEY" \
  "https://api-datahub.octoparse.com/v1/runs/run_c62bc0fb8df2/cancel"
```

## Antwort

### 200 Erfolg

```json theme={null}
{
  "data": {
    "run_id": "run_c62bc0fb8df2",
    "namespace": "carol",
    "app_name": "probe-b",
    "app_version": "0.1.0",
    "build_id": null,
    "run_kind": "production",
    "state": "SUCCEEDED",
    "input": {
      "product": "p-now"
    },
    "progress": {
      "done": 20,
      "total": null,
      "status_text": null
    },
    "dataset_id": "ds_0bd5345d13d0",
    "partial": false,
    "cancel_requested": false,
    "triggered_by": "api",
    "upstream_ref": null,
    "created_at": "2026-09-15T07:45:40.411993+00:00",
    "started_at": "2026-09-15T07:45:40.419610+00:00",
    "first_started_at": "2026-09-15T07:45:40.419610+00:00",
    "finished_at": "2026-09-15T07:45:40.822250+00:00",
    "usage": {
      "metrics": {
        "records_collected": 20
      },
      "duration_ms": 402
    },
    "billing": {
      "events": [
        {
          "event": "record",
          "label": "One record",
          "qty": 20.0,
          "unit_price": 0.001,
          "amount": 0.02,
          "unit_size": null,
          "raw_qty": null
        }
      ],
      "total": 0.02,
      "currency": "USD",
      "charged": true
    },
    "error": null,
    "sample_records": null,
    "warnings": []
  }
}
```

Liefert ein Run-Objekt. Die Felder entsprechen <a href="/docs/de/datahub/api/reference/runs/start-run">Start a run</a>.

Payload ist in `data` gewrappt. Felder:

<ResponseField name="run_id" type="string" required>
  —
</ResponseField>

<ResponseField name="namespace" type="string">
  —
</ResponseField>

<ResponseField name="app_name" type="string">
  —
</ResponseField>

<ResponseField name="app_version" type="string">
  —
</ResponseField>

<ResponseField name="build_id" type="string">
  —
</ResponseField>

<ResponseField name="run_kind" type="string">
  —
</ResponseField>

<ResponseField name="state" type="enum" required>
  Werte: `PENDING` / `QUEUED` / `RUNNING` / `SUCCEEDED` / `PARTIALLY_SUCCEEDED` / `FAILED` / `CANCELLED` / `EXPIRED`.
</ResponseField>

<ResponseField name="input" type="object">
  —
</ResponseField>

<ResponseField name="progress" type="object">
  —

  <Expandable title="fields">
    <ResponseField name="done" type="integer">
      —
    </ResponseField>

    <ResponseField name="total" type="integer">
      —
    </ResponseField>

    <ResponseField name="status_text" type="string">
      —
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="dataset_id" type="string">
  —
</ResponseField>

<ResponseField name="partial" type="boolean">
  —
</ResponseField>

<ResponseField name="cancel_requested" type="boolean">
  `true`, solange ein Abbruch angefordert wurde und der Run noch ausläuft (kooperativer Stopp / Wiederherstellung von Teilergebnissen). In Endzuständen immer `false` (serverseitig normalisiert), sodass Clients es nicht aus `state` ableiten müssen.
</ResponseField>

<ResponseField name="triggered_by" type="string">
  —
</ResponseField>

<ResponseField name="upstream_ref" type="string">
  —
</ResponseField>

<ResponseField name="created_at" type="string">
  —
</ResponseField>

<ResponseField name="started_at" type="string">
  —
</ResponseField>

<ResponseField name="first_started_at" type="string">
  Wann ein Worker den Run zuerst geclaimed hat. Anders als `started_at` wird dies bei Retry nie überschrieben — Anker für Queue-Zeit: queued = `first_started_at - created_at`, Gesamtwandzeit = `finished_at - first_started_at`. Queue-Zeit aus `started_at` abzuleiten zählt frühere Attempts als Queuing. `null` nur bei nie geclaimten Runs.
</ResponseField>

<ResponseField name="finished_at" type="string">
  —
</ResponseField>

<ResponseField name="usage" type="object">
  Objektives Usage-Metering: wie viel der Run geleistet hat. Getrennt von der Abrechnung; das vergleichen Evaluations.

  <Expandable title="fields">
    <ResponseField name="metrics" type="object">
      —
    </ResponseField>

    <ResponseField name="duration_ms" type="integer">
      —
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="billing" type="object">
  Abrechnungsbuch = Nutzung × Preise × Abrechnungsregeln: wie viel berechnet wird.

  <Expandable title="fields">
    <ResponseField name="events" type="object[]">
      —

      <Expandable title="fields">
        <ResponseField name="event" type="string" required>
          —
        </ResponseField>

        <ResponseField name="label" type="string">
          —
        </ResponseField>

        <ResponseField name="qty" type="number" required>
          —
        </ResponseField>

        <ResponseField name="unit_price" type="number" required>
          —
        </ResponseField>

        <ResponseField name="amount" type="number" required>
          —
        </ResponseField>

        <ResponseField name="unit_size" type="integer">
          —
        </ResponseField>

        <ResponseField name="raw_qty" type="number">
          —
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="total" type="number">
      —
    </ResponseField>

    <ResponseField name="currency" type="string">
      —
    </ResponseField>

    <ResponseField name="charged" type="boolean">
      —
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="error" type="object">
  —

  <Expandable title="fields">
    <ResponseField name="code" type="string" required>
      —
    </ResponseField>

    <ResponseField name="category" type="string">
      —
    </ResponseField>

    <ResponseField name="message" type="string" required>
      —
    </ResponseField>

    <ResponseField name="retryable" type="boolean">
      —
    </ResponseField>

    <ResponseField name="retry_after" type="number">
      —
    </ResponseField>

    <ResponseField name="item_index" type="integer">
      —
    </ResponseField>

    <ResponseField name="details" type="object[]">
      —
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="sample_records" type="object[]">
  —
</ResponseField>

<ResponseField name="warnings" type="object[]">
  —

  <Expandable title="fields">
    <ResponseField name="code" type="string" required>
      —
    </ResponseField>

    <ResponseField name="event" type="string">
      —
    </ResponseField>

    <ResponseField name="detail" type="object">
      —
    </ResponseField>

    <ResponseField name="count" type="integer">
      —
    </ResponseField>

    <ResponseField name="updated_at" type="string">
      —
    </ResponseField>
  </Expandable>
</ResponseField>

### Fehler

| HTTP | `code`          | `category`      | Beschreibung                                                        |
| ---- | --------------- | --------------- | ------------------------------------------------------------------- |
| 401  | `unauthorized`  | `forbidden`     | Fehlender oder ungültiger API-Schlüssel.                            |
| 404  | `run-not-found` | `not_found`     | Run existiert nicht oder wurde nicht vom aktuellen Konto gestartet. |
| 409  | `run-terminal`  | `invalid_input` | Run bereits beendet und kann nicht abgebrochen werden.              |

Fehlerantworten nutzen `{"error": {code, category, message, retryable}}`. Siehe <a href="/docs/de/datahub/api/reference/introduction#errors">Fehler</a>.

## Client-Bibliotheken

<CodeGroup>
  ```python Python theme={null}
  run = client.cancel("run_c62bc0fb8df2")
  print(run["state"], run["partial"])
  ```

  ```js JavaScript theme={null}
  const run = await client.cancel("run_c62bc0fb8df2");
  console.log(run.state, run.partial);
  ```
</CodeGroup>
