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

# Set retention flag

> Mark a dataset for long-term retention, or clear the flag.

**`PUT`** `https://api-datahub.octoparse.com/v1/datasets/{dataset_id}/retention`

Authentication: API key required (`Authorization: Bearer <API Key>`).

Run results are kept for 90 days from creation by default. Datasets with the retention flag set are excluded from expiry cleanup. The flag is an explicit user declaration: reading does not renew retention, and set/clear are idempotent.

You can only mark your own datasets. Someone else's dataset, a public seed dataset, or a missing id all return `404`. The mark gate is narrower than the visibility gate because seed datasets are not your output and are not cleaned up, so marking them is meaningless.

## Request

### Path parameters

<ParamField path="dataset_id" type="string" required>
  Dataset id.
</ParamField>

### Request body

<ParamField body="retained" type="boolean" required>
  `true` to retain, `false` to clear the flag.
</ParamField>

### Example request

```bash theme={null}
curl -X PUT   -H "Authorization: Bearer $OCTOPARSE_API_KEY"   -H "Content-Type: application/json"   -d '{"retained": true}'   "https://api-datahub.octoparse.com/v1/datasets/ds_0bd5345d13d0/retention"
```

## Response

### 200 success

```json theme={null}
{
  "data": {
    "dataset_id": "ds_0bd5345d13d0",
    "retained": true
  }
}
```

### Errors

| HTTP | `code`              | `category`  | Description                                                                   |
| ---- | ------------------- | ----------- | ----------------------------------------------------------------------------- |
| 401  | `unauthorized`      | `forbidden` | Missing or invalid API key.                                                   |
| 404  | `dataset-not-found` | `not_found` | Dataset does not exist, is not yours, or is a public seed set (not markable). |

Error responses use `{"error": {code, category, message, retryable}}`. See <a href="/docs/en/datahub/api/reference/introduction#errors">Errors</a>.

## Client libraries

<CodeGroup>
  ```python Python theme={null}
  client.set_dataset_retention("ds_0bd5345d13d0", retained=True)
  ```

  ```js JavaScript theme={null}
  await client.setDatasetRetention("ds_0bd5345d13d0", true);
  ```
</CodeGroup>
