> For a complete page index of the Captain API documentation, fetch https://docs.filesearch.dev/llms.txt?excludeSpec=true

# Rollback Job

PATCH https://api.filesearch.dev/v2/jobs/{job_id}/rollback

Rollback a completed/failed indexing job — removes all indexed data (RDS + Turbopuffer).

Behavior:
- If job is RUNNING: returns 409 Conflict — cancel it first
- If job is in terminal state (SUCCEEDED/FAILED/ABORTED/TIMED_OUT): deletes all data
- If job not found: returns 404

Returns:
- job_id: The job identifier
- status: "rolled_back" or "error"
- files_removed: List of file names that were removed
- rolled_back_at: Timestamp of rollback

Authentication: Requires Bearer token in Authorization header

Reference: https://docs.filesearch.dev/reference/jobs/rollback

## Request

### Path parameters

- `job_id` (string, required)

### Headers

- `authorization` (string, optional, nullable)

## Response

### 200

Successful Response

- `job_id` (string, required)
- `status` (string, required)
- `files_removed` (list of string, optional, nullable)
- `message` (string, optional, nullable)
- `rolled_back_at` (string, optional, nullable)

## Examples

**SDK Code**

```python
import json
import requests
import uuid

BASE_URL = "https://api.filesearch.dev"
API_KEY = "your_api_key"
JOB_ID = "job_abc123"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Idempotency-Key": str(uuid.uuid4()),
}

response = requests.patch(
    f"{BASE_URL}/v2/jobs/{JOB_ID}/rollback",
    headers=headers,
    timeout=30.0
)

print(json.dumps(response.json(), indent=2))
```

```typescript
const BASE_URL = "https://api.filesearch.dev";

const API_KEY = "your_api_key";

const job_id = "job_abc123";

const headers = {
  Authorization: `Bearer ${API_KEY}`,
  "Idempotency-Key": crypto.randomUUID(),
};

const response = await fetch(`${BASE_URL}/v2/jobs/${job_id}/rollback`, {
  method: "PATCH",
  headers,
});

const data = await response.json();
console.log(JSON.stringify(data, null, 2));
```