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

> ## Agent Instructions
> Start with /introduction/getting-started. Use the Direct Query API (POST /query) with the Newton Fusion model (text, image, and video reasoning) or the Newton Omega encoder (time-series embeddings). ATAI_API_ENDPOINT must include the version path: /v0.5 for most APIs, /v0.6 for the Fine-Tuning Service. Pages whose descriptions are marked (Archived) document the legacy Lens runtime — do not use them for new projects.

# Download File

> Download the raw bytes of a previously uploaded file

## Overview

This endpoint streams the raw contents of a previously uploaded file. The response body is `application/octet-stream` — the file as it was uploaded.

The file must be in a downloadable state. Files that are still uploading, deleted, or corrupt will return `400`.

## Path Parameters

<ParamField path="file_id" type="string" required>
  Identifier of the file to download
</ParamField>

## Response

The response body is the raw file bytes with `Content-Type: application/octet-stream`.

<RequestExample>
  ```bash cURL theme={"system"}
  curl https://api.u1.archetypeai.app/v0.5/files/download/file-abc123 \
    -H "Authorization: Bearer $ATAI_API_KEY" \
    -o downloaded_file.csv
  ```

  ```python Python theme={"system"}
  import requests
  import os

  api_key = os.environ.get("ATAI_API_KEY")
  file_id = "file-abc123"

  response = requests.get(
      f"https://api.u1.archetypeai.app/v0.5/files/download/{file_id}",
      headers={"Authorization": f"Bearer {api_key}"},
      stream=True,
  )
  response.raise_for_status()

  with open("downloaded_file.csv", "wb") as fh:
      for chunk in response.iter_content(chunk_size=1 << 20):
          fh.write(chunk)

  print(f"Downloaded {file_id}")
  ```

  ```javascript JavaScript theme={"system"}
  import fs from "node:fs";
  import { Readable } from "node:stream";

  const fileId = "file-abc123";

  const response = await fetch(
    `https://api.u1.archetypeai.app/v0.5/files/download/${fileId}`,
    {
      headers: {
        Authorization: `Bearer ${process.env.ATAI_API_KEY}`,
      },
    }
  );

  if (!response.ok) {
    throw new Error(`Download failed: ${response.status}`);
  }

  const out = fs.createWriteStream("downloaded_file.csv");
  Readable.fromWeb(response.body).pipe(out);
  ```
</RequestExample>

<ResponseExample>
  ```text 200 - Success theme={"system"}
  <binary file contents — Content-Type: application/octet-stream>
  ```

  ```json 400 - File not downloadable theme={"system"}
  {
    "errors": [
      {
        "code": "file_not_downloadable",
        "message": "File exists but is not in a downloadable state (status: Uploading).",
        "suggestion": "Wait for the file to reach the Registered status before downloading.",
        "error_uid": "err-xxxxxxxx"
      }
    ]
  }
  ```

  ```json 401 - Unauthorized theme={"system"}
  {
    "errors": [
      {
        "code": "unauthorized_request",
        "message": "Unauthorized or invalid access.",
        "suggestion": "Provide valid authentication credentials and ensure they have the required permissions.",
        "error_uid": "err-xxxxxxxx"
      }
    ]
  }
  ```

  ```json 404 - File not found theme={"system"}
  {
    "errors": [
      {
        "code": "file_not_found",
        "message": "No file with the given file_id was found for the organization.",
        "suggestion": "Verify the file_id and that the file has not been deleted.",
        "error_uid": "err-xxxxxxxx"
      }
    ]
  }
  ```
</ResponseExample>
