Help Center/ ModelArts/ API Reference/ Model Training/ Training Management/ Counting the Number of Training Job Resources by Tag
Updated on 2026-11-12 GMT+08:00

Counting the Number of Training Job Resources by Tag

Function

This API is used to query the total number of training jobs that meet the conditions in the current project based on tags.

This API is applicable to scenarios where you need to count training jobs by criteria such as tag key-value pairs or resource names. The prerequisite for using this API is that you are logged in and possess the permissions to view training job tags. After the query operation completes, the platform will return the total count of matching training jobs. If you do not have the permission to perform operations, the API will return an error message.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    modelarts::listResourcesByTag

    List

    -

    g:TagKeys

    modelarts:tag:listTags

    -

URI

POST /v2/{project_id}/modelarts-training-job/resource-instances/count

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition: Project ID. For details, see Obtaining a Project ID and Name.

Constraints: N/A

Range: The value can contain 1 to 64 characters. Only letters, digits, and hyphens (-) are allowed.

Default Value: N/A

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

limit

No

Integer

Definition: Number of returned records.

Constraints: N/A

Value range: 1 to 1000

Default Value: 1000

offset

No

Integer

Definition: Offset, indicating the number of the data record from which the query starts.

Constraints: N/A

Range: no less than 0

Default Value: 0

Request Parameters

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

tags

No

Array of tags objects

Definition: Tag filter criteria. Only training jobs with all listed tags are returned.

Constraints: The number of tags cannot exceed the maximum number of tags allowed by the system.

Range: N/A

Default Value: N/A

matches

No

Array of matches objects

Definition: Fuzzy match condition. Fuzzy search can be performed by field such as the resource name.

Constraints: A maximum of one condition is allowed.

Range: N/A

Default Value: N/A

workspace_id

No

String

Definition: Workspace ID.

Constraints: N/A

Range: N/A

Default Value: 0

without_any_tag

No

Boolean

Definition: Specifies whether to obtain training jobs that have no tags.

Constraints: N/A

Range: N/A

Default Value: false

Table 4 tags

Parameter

Mandatory

Type

Description

key

Yes

String

Definition: Tag key.

Constraints: N/A

Range: 1 to 128 characters.

Default Value: N/A

values

No

Array of strings

Definition: A list of tag values.

Constraints: A maximum of 10 tag values is allowed. Each tag value can have 0 to 255 characters.

Range: N/A

Default Value: N/A

Table 5 matches

Parameter

Mandatory

Type

Description

key

Yes

String

Definition: Matching field name.

Constraints: N/A

Range: N/A

Default Value: N/A

value

Yes

String

Definition: Matched value.

Constraints: N/A

Range: 1 to 255 characters.

Default Value: N/A

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

total_count

Integer

Definition: Total number of training jobs that meet the search criteria.

Range: N/A

Status code: 400

Table 7 Response body parameters

Parameter

Type

Description

error_msg

String

Error message

error_code

String

Error code

error_solution

String

Solution

Example Requests

Collect statistics on the number of training jobs whose tag key is workspace and value is 0.

POST https://{endpoint}/v2/{project_id}/modelarts-training-job/resource-instances/count

{
  "tags" : [ {
    "key" : "workspace",
    "values" : [ "0" ]
  } ]
}

Example Responses

Status code: 200

{
  "total_count" : 100
}

Status code: 400

{
  "error_msg" : "limit should be a num between 1~1000.",
  "error_code" : "ModelArts.2755",
  "error_solution" : "Check whether the request parameters are valid."
}

Status Codes

Status Code

Description

200

Response body for counting the number of training job resources by tag

400

General error response message body format.

Error Codes

See Error Codes.