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

# Polling the TaskResponse

The Chunkr AI API follows a task-based pattern where you create a task and monitor its progress through polling.
The `poll()` method handles this by automatically checking the task's status at regular intervals until it transitions out of the `Starting` or `Processing` states.

After polling completes, it's important to verify the final task status, which will be one of:

* `Succeeded`: Task completed successfully
* `Failed`: Task encountered an error
* `Cancelled`: Task was manually cancelled

## Synchronous Usage

When you have a `TaskResponse` object, you can poll it.
Look at [creating](/sdk/data-operations/create) and [getting](/sdk/data-operations/get) a task for more information on how to get a `TaskResponse` object.

<CodeGroup>
  ```python Python theme={"system"}
  from chunkr_ai import Chunkr

  # Initialize client
  chunkr = Chunkr()

  try:
      # Given that you already have a task object, you can poll it
      task.poll()  
      print(task.output.chunks)
  finally:
      # Clean up when done
      chunkr.close()
  ```
</CodeGroup>

## Asynchronous Usage

For async applications, use `await`:

<CodeGroup>
  ```python Python theme={"system"}
  from chunkr_ai import Chunkr
  import asyncio

  async def process_document():
      # Initialize client
      chunkr = Chunkr()

      try:
          # Given that you already have a task object
          await task.poll()  
          print(task.output.chunks)
      finally:
          # Clean up when done
          chunkr.close()
  ```
</CodeGroup>

## Error Handling

By default, failed tasks i.e. `task.status == "Failed"` will not raise exceptions. You can configure this behavior using the `raise_on_failure` parameter when initializing the client:

<CodeGroup>
  ```python Python theme={"system"}
  from chunkr_ai import Chunkr

  # Initialize client with automatic error raising
  chunkr = Chunkr(raise_on_failure=True)
  ```
</CodeGroup>
