# Query calculation instance indicators

Read usage metrics for a compute instance.

```text
GET https://moi.matrixorigin.cn/newmoi/compute-resources/{resource_id}/metrics
```

## Preparation before calling

First [Query the computing instance details](get-compute-resource.md)] and confirm the instance you want to query. Prepare a personal access token with access to the target workspace, the target workspace ID, and the compute instance ID.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: Target workspace ID, passed through `X-Workspace-ID` Header.
- `$RESOURCE_ID`: The computing instance ID to be queried.

The indicator items in `data.breakdown` will evolve with the service implementation, and the caller should be able to accept new fields.

## Request example

```bash
curl "https://moi.matrixorigin.cn/newmoi/compute-resources/$RESOURCE_ID/metrics" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID"
```

## Path parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `resource_id` | string | Yes | Compute instance ID. |

## Successful response

Returns `200` on success, and the business data is located at `data`. The requested resource ID is used to identify the indicator ownership; the current interface can return empty indicator objects.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "compute_resource_id": "cr-001",
    "total_credit": 0,
    "breakdown": {}
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data` | object | Indicator object. |
| `data.compute_resource_id` | string | The calculation instance ID to which the indicator belongs. |
| `data.total_credit` | integer | The total Credit value returned by the server. |
| `data.breakdown` | object | Indicator details; the keys and values are provided by the server and may be added. |

## Error response

```json
{
  "code": "GET_METRICS_FAILED",
  "msg": "服务端错误",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `401`
  - —
  - Missing or invalid access credentials.
  - Check API Key and Workspace Header.
* - `403`
  - `ErrForbidden`
  - The current identity does not have permission to read instance metrics.
  - Use valid credentials, or contact your administrator for authorization.
* - `500`
  - `GET_METRICS_FAILED`
  - The service cannot read the indicator.
  - Record the request time and error message and try again.
```

## Follow-up operations

[Query calculation instance details](get-compute-resource.md) to associate indicators with the current status of the instance.
