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

# Task System Overview

> Understanding Chunkr's task-based processing system

All processing in Chunkr is handled through a task-based system. When you submit a file, a new task is created, and you receive a `task_id`. Use this ID to get a task asynchronously.

This asynchronous approach allows you to submit long-running jobs without tying up your application. Once the task status is `Succeeded`, the full processing results are available.

## Key Features

* **Scalability**: Handle millions of files without tying-up your infrastructure.
* **[Broad File Support](/pages/get-started/file-types)**: Process a variety of file types like PDFs, Excel, PPTs, Doc.
* **[Multiple Input Sources](/pages/task-system/task-handling#supported-input-sources)**: Provide files from local path, from a URL, or as a base64-encoded string.
* **[Data Retention](/pages/task-system/task-handling#data-retention)**: Set custom expiration times for automatic data deletion.
* **[Webhook Support](/pages/task-system/webhooks/overview)**: Receive real-time notifications when tasks complete.

### Example: Upload a file, create a task, and get results

Here's how to upload, create a parse task, and retrieve results.

<CodeGroup>
  ```python Python theme={"system"}
  import os
  import time

  from chunkr_ai import Chunkr

  # Initialize the client
  client = Chunkr(api_key=os.environ["CHUNKR_API_KEY"])

  # 1. Upload a local file
  with open("path/to/doc.pdf", "rb") as f:
      uploaded = client.files.create(file=f)

  # 2. Create a parse task using the uploaded file URL
  parse_task = client.tasks.parse.create(file=uploaded.url)
  print(f"Task created with ID: {parse_task.task_id}")

  # 3. Wait for the task to complete
  while not parse_task.completed:
      print(f"Task status: {parse_task.status}")
      time.sleep(3)
      parse_task = client.tasks.parse.get(task_id=parse_task.task_id)

  # 4. Access the results
  if parse_task.status == "Succeeded" and parse_task.output is not None:
      print("Task completed successfully!")
      print(f"Document has {len(parse_task.output.chunks)} chunks")
  else:  # Could be "Failed" or "Cancelled"
      print(f"Task status: {parse_task.status}")
  ```

  ```typescript TypeScript theme={"system"}
  import Chunkr from "chunkr-ai";
  import fs from "fs";

  // Initialize the client
  const client = new Chunkr({ apiKey: process.env.CHUNKR_API_KEY! });

  // 1. Upload a local file
  const fileStream = fs.createReadStream("path/to/doc.pdf");
  const uploaded = await client.files.create({
    file: fileStream,
    file_metadata: JSON.stringify({ name: "doc.pdf", type: "application/pdf" }),
  });

  // 2. Create a parse task using the uploaded file URL
  let task = await client.tasks.parse.create({ file: uploaded.url });
  console.log(`Task created with ID: ${task.task_id}`);

  // 3. Wait for the task to complete
  while (!task.completed) {
    task = await client.tasks.parse.get(task.task_id);
    console.log(`Task status: ${task.status}`);
    await new Promise((resolve) => setTimeout(resolve, 3000));
  }

  // 4. Access the results
  if (task.status === "Succeeded") {
    console.log("Task completed successfully!");
    console.log(`Document has ${task.output?.chunks.length} chunks`);
  } else { // Could be "Failed" or "Cancelled"
    console.log(`Task status: ${task.status}`);
  }
  ```
</CodeGroup>
