---
title: "Read Task Run Counts By State"
method: POST
path: "/api/ui/task_runs/count"
tags: ["Task Runs", "UI"]
---

# Read Task Run Counts By State

`POST /api/ui/task_runs/count`

## Headers

- `x-prefect-api-version` string

## Request body

- BodyReadTaskRunCountsByStateUiTaskRunsCountPost
  - `flows` FlowFilter — Filter for flows. Only flows matching all criteria will be returned.
    - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
    - `id` FlowFilterId — Filter by `Flow.id`.
      - `any_` string[] — A list of flow ids to include
    - `deployment` FlowFilterDeployment — Filter by flows by deployment
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `is_null_` boolean — If true, only include flows without deployments
    - `name` FlowFilterName — Filter by `Flow.name`.
      - `any_` string[] — A list of flow names to include
      - `like_` string — A case-insensitive partial match. For example, passing 'marvin' will match 'marvin', 'sad-Marvin', and 'marvin-robot'.
    - `tags` FlowFilterTags — Filter by `Flow.tags`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `all_` string[] — A list of tags. Flows will be returned only if their tags are a superset of the list
      - `is_null_` boolean — If true, only include flows without tags
  - `flow_runs` FlowRunFilter — Filter flow runs. Only flow runs matching all criteria will be returned
    - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
    - `id` FlowRunFilterId — Filter by `FlowRun.id`.
      - `any_` string[] — A list of flow run ids to include
      - `not_any_` string[] — A list of flow run ids to exclude
    - `name` FlowRunFilterName — Filter by `FlowRun.name`.
      - `any_` string[] — A list of flow run names to include
      - `like_` string — A case-insensitive partial match. For example, passing 'marvin' will match 'marvin', 'sad-Marvin', and 'marvin-robot'.
    - `tags` FlowRunFilterTags — Filter by `FlowRun.tags`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `all_` string[] — A list of tags. Flow runs will be returned only if their tags are a superset of the list
      - `is_null_` boolean — If true, only include flow runs without tags
    - `deployment_id` FlowRunFilterDeploymentId — Filter by `FlowRun.deployment_id`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `any_` string[] — A list of flow run deployment ids to include
      - `is_null_` boolean — If true, only include flow runs without deployment ids
    - `work_queue_name` FlowRunFilterWorkQueueName — Filter by `FlowRun.work_queue_name`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `any_` string[] — A list of work queue names to include
      - `is_null_` boolean — If true, only include flow runs without work queue names
    - `state` FlowRunFilterState — Filter by `FlowRun.state_type` and `FlowRun.state_name`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `type` FlowRunFilterStateType — Filter by `FlowRun.state_type`.
        - `any_` StateType[] — A list of flow run state types to include
      - `name` FlowRunFilterStateName — Filter by `FlowRun.state_name`.
        - `any_` string[] — A list of flow run state names to include
    - `flow_version` FlowRunFilterFlowVersion — Filter by `FlowRun.flow_version`.
      - `any_` string[] — A list of flow run flow_versions to include
    - `start_time` FlowRunFilterStartTime — Filter by `FlowRun.start_time`.
      - `before_` string, date-time — Only include flow runs starting at or before this time
      - `after_` string, date-time — Only include flow runs starting at or after this time
      - `is_null_` boolean — If true, only return flow runs without a start time
    - `expected_start_time` FlowRunFilterExpectedStartTime — Filter by `FlowRun.expected_start_time`.
      - `before_` string, date-time — Only include flow runs scheduled to start at or before this time
      - `after_` string, date-time — Only include flow runs scheduled to start at or after this time
    - `next_scheduled_start_time` FlowRunFilterNextScheduledStartTime — Filter by `FlowRun.next_scheduled_start_time`.
      - `before_` string, date-time — Only include flow runs with a next_scheduled_start_time or before this time
      - `after_` string, date-time — Only include flow runs with a next_scheduled_start_time at or after this time
    - `parent_flow_run_id` FlowRunFilterParentFlowRunId — Filter for subflows of a given flow run
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `any_` string[] — A list of parent flow run ids to include
    - `parent_task_run_id` FlowRunFilterParentTaskRunId — Filter by `FlowRun.parent_task_run_id`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `any_` string[] — A list of flow run parent_task_run_ids to include
      - `is_null_` boolean — If true, only include flow runs without parent_task_run_id
    - `idempotency_key` FlowRunFilterIdempotencyKey — Filter by FlowRun.idempotency_key.
      - `any_` string[] — A list of flow run idempotency keys to include
      - `not_any_` string[] — A list of flow run idempotency keys to exclude
  - `task_runs` TaskRunFilter — Filter task runs. Only task runs matching all criteria will be returned
    - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
    - `id` TaskRunFilterId — Filter by `TaskRun.id`.
      - `any_` string[] — A list of task run ids to include
    - `name` TaskRunFilterName — Filter by `TaskRun.name`.
      - `any_` string[] — A list of task run names to include
      - `like_` string — A case-insensitive partial match. For example, passing 'marvin' will match 'marvin', 'sad-Marvin', and 'marvin-robot'.
    - `tags` TaskRunFilterTags — Filter by `TaskRun.tags`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `all_` string[] — A list of tags. Task runs will be returned only if their tags are a superset of the list
      - `is_null_` boolean — If true, only include task runs without tags
    - `state` TaskRunFilterState — Filter by `TaskRun.type` and `TaskRun.name`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `type` TaskRunFilterStateType — Filter by `TaskRun.state_type`.
        - `any_` StateType[] — A list of task run state types to include
      - `name` TaskRunFilterStateName — Filter by `TaskRun.state_name`.
        - `any_` string[] — A list of task run state names to include
    - `start_time` TaskRunFilterStartTime — Filter by `TaskRun.start_time`.
      - `before_` string, date-time — Only include task runs starting at or before this time
      - `after_` string, date-time — Only include task runs starting at or after this time
      - `is_null_` boolean — If true, only return task runs without a start time
    - `subflow_runs` TaskRunFilterSubFlowRuns — Filter by `TaskRun.subflow_run`.
      - `exists_` boolean — If true, only include task runs that are subflow run parents; if false, exclude parent task runs
    - `flow_run_id` TaskRunFilterFlowRunId — Filter by `TaskRun.flow_run_id`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `any_` string[] — A list of task run flow run ids to include
      - `is_null_` boolean — Filter for task runs with None as their flow run id
  - `deployments` DeploymentFilter — Filter for deployments. Only deployments matching all criteria will be returned.
    - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
    - `id` DeploymentFilterId — Filter by `Deployment.id`.
      - `any_` string[] — A list of deployment ids to include
    - `name` DeploymentFilterName — Filter by `Deployment.name`.
      - `any_` string[] — A list of deployment names to include
      - `like_` string — A case-insensitive partial match. For example, passing 'marvin' will match 'marvin', 'sad-Marvin', and 'marvin-robot'.
    - `paused` DeploymentFilterPaused — Filter by `Deployment.paused`.
      - `eq_` boolean — Only returns where deployment is/is not paused
    - `is_schedule_active` DeploymentFilterIsScheduleActive — Legacy filter to filter by `Deployment.is_schedule_active` which is always the opposite of `Deployment.paused`.
      - `eq_` boolean — Only returns where deployment schedule is/is not active
    - `tags` DeploymentFilterTags — Filter by `Deployment.tags`.
      - `operator` 'and_' | 'or_' — Operators for combining filter criteria.
      - `all_` string[] — A list of tags. Deployments will be returned only if their tags are a superset of the list
      - `is_null_` boolean — If true, only include deployments without tags
    - `work_queue_name` DeploymentFilterWorkQueueName — Filter by `Deployment.work_queue_name`.
      - `any_` string[] — A list of work queue names to include

## Response `200`

Successful Response

- CountByState — A base pydantic.BaseModel for all Prefect schemas and pydantic models. As the basis for most Prefect schemas, this base model usually ignores extra fields that are passed to it at instantiation. Because adding new fields to API payloads is not considered a breaking change, this ensures that any Prefect client loading data from a server running a possibly-newer version of Prefect will be able to process those new fields gracefully. However, when PREFECT_TEST_MODE is on, extra fields are forbidden in order to catch subtle unintentional testing errors.
  - `COMPLETED` integer
  - `PENDING` integer
  - `RUNNING` integer
  - `FAILED` integer
  - `CANCELLED` integer
  - `CRASHED` integer
  - `PAUSED` integer
  - `CANCELLING` integer
  - `SCHEDULED` integer

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/prefecthq/apis/untitled-api-2.md) · [All operations](https://skmtc.net/prefecthq/apis/untitled-api-2/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/prefecthq/untitled-api-2/versions/29ba6c4f8837/schema)
