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

# Download Step Document

> Download a document produced by a specific workflow step, such as a generated draft, negotiated version, or signed contract, using the task and step IDs.

## Endpoint

```
GET /tasks/{task_id}/steps/{step_id}/document
```

## Authentication

This endpoint requires authentication via API key. Include your API key in the `X-API-Key` header:

```bash theme={null}
X-API-Key: ca_your_api_key_here
```

## Path Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `task_id` | integer | Yes | Unique identifier for the task |
| `step_id` | string | Yes | Unique identifier for the workflow step |

## Request Example

```bash cURL theme={null}
curl -X GET "https://platform.chamelio.ai/tasks/12345/steps/review_step/document" \
  -H "X-API-Key: ca_your_api_key_here"
```

```python Python theme={null}
import requests

task_id = 12345
step_id = "review_step"

url = f"https://platform.chamelio.ai/tasks/{task_id}/steps/{step_id}/document"
headers = {
    "X-API-Key": "ca_your_api_key_here"
}

response = requests.get(url, headers=headers)
data = response.json()

# Then fetch the presigned URL to get the file itself
document = requests.get(data["download_url"])
with open(data["file_name"], "wb") as f:
    f.write(document.content)
```

```javascript JavaScript theme={null}
const taskId = 12345;
const stepId = 'review_step';

const response = await fetch(
  `https://platform.chamelio.ai/tasks/${taskId}/steps/${stepId}/document`,
  {
    method: 'GET',
    headers: {
      'X-API-Key': 'ca_your_api_key_here'
    }
  }
);

const data = await response.json();

// Then fetch the presigned URL to get the file itself
const downloadResponse = await fetch(data.download_url);
if (!downloadResponse.ok) {
  throw new Error('Document download failed');
}

const blob = await downloadResponse.blob();
const objectUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = objectUrl;
link.download = data.file_name;
link.click();
URL.revokeObjectURL(objectUrl);
```

## Response

### Success Response

**Status Code:** `200 OK`

The response is JSON metadata containing a presigned URL - not the file bytes.

```json theme={null}
{
  "file_id": "document_790",
  "file_name": "reviewed_contract.pdf",
  "content_type": "pdf",
  "download_url": "https://s3.amazonaws.com/...",
  "expires_at": "2025-01-20T12:00:00Z"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `file_id` | string | Unique file identifier (`document_{id}` or `attachment_{id}`) |
| `file_name` | string | Name of the document file |
| `content_type` | string | Type of the file |
| `download_url` | string | Presigned URL to download the document |
| `expires_at` | string | ISO 8601 timestamp when the download URL expires |

## Error Responses

### 401 Unauthorized

Returned when authentication fails. See the [authentication errors](https://docs.chamelio.ai/api-reference/api-keys.md#authentication-errors) section for details.

```json theme={null}
{
  "detail": "Invalid API key"
}
```

### 404 Not Found

Returned when the task, step, or document doesn't exist.

```json theme={null}
{
  "detail": "Document not found for step"
}
```

### 501 Not Implemented

Returned when the step hasn't generated a document yet or doesn't generate documents.

```json theme={null}
{
  "detail": "Document not available for this step"
}
```

### 500 Internal Server Error

Returned when the request fails due to a server error.

```json theme={null}
{
  "detail": "Failed to download step document"
}
```

## Notes

> [!NOTE]
>
> This endpoint is specifically for documents generated by workflow steps (like document generation or AI review steps). For uploaded documents, use the [Download File](https://docs.chamelio.ai/api-reference/endpoint/files/download.md) endpoint instead.

> [!WARNING]
>
> The presigned download URL expires after a certain time (indicated by `expires_at`). Download the file before the URL expires or request a new URL.

> [!TIP]
>
> Use the [List Task Files](https://docs.chamelio.ai/api-reference/endpoint/tasks/list-files.md) endpoint to discover which steps have generated documents and their associated `step_id` values.

## Use Cases

This endpoint is useful for:

* **Document retrieval** - Download AI-generated or modified documents from workflows
* **Contract export** - Export reviewed, redlined, or approved contracts
* **Archival** - Save generated documents to external storage systems
* **Distribution** - Share workflow outputs with external stakeholders
