# Query feedback statistics

Count the total number of reviews that the current user can review and the number of ratings.

```text
GET https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/feedback/stats
```

## Preparation before calling

Prepare a personal access token and target workspace ID that has access to the target workspace. If you need to filter by agent, first obtain the agent 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.
- `$AGENT_ID`: Optional agent filter ID.

## Request example

```bash
curl --get "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/feedback/stats" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  --data-urlencode "agent_id=$AGENT_ID"
```

## Path parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `workspace_id` | string | Yes | The current workspace ID. |

## Query parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `agent_id` | string | No | Filter by agent ID. |
| `agent_workspace_id` | string | No | The workspace to which the agent belongs. |
| `task_id` | string | No | Filter by task ID. |
| `message_id` | string | No | Filter by message ID. |
| `rating` | string | No | Only count the specified score. |

## Successful response

Returns `200` on success. `data.total` is the total number of feedback that meets the filter conditions, and `data.by_rating` returns the count by rating.

```json
{
  "code": 0,
  "data": {
    "total": 12,
    "by_rating": {
      "up": 9,
      "down": 3,
      "neutral": 0
    }
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `0` on success. |
| `data.total` | integer | The total number of feedback that meets the filter conditions. |
| `data.by_rating` | object | Amount grouped by rating; returned must contain at least `up`, `down`, and `neutral`. |
| `data.by_rating.<rating>` | integer | The number of feedback for the specified rating. |

## Error response

```json
{
  "code": 2,
  "message": "反馈筛选条件无效"
}
```

### Common HTTP errors

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

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `2`（`INVALID_ARGUMENT`）
  - Invalid resource ID or rating filter.
  - Check path and query parameters.
* - `401`
  - `6`（`UNAUTHENTICATED`）
  - Credentials are missing or invalid.
  - Check API Key.
* - `403`
  - `5`（`PERMISSION_DENIED`）
  - Current identity cannot read workspace feedback.
  - Use valid credentials, or contact your administrator for authorization.
* - `503`
  - `15`（`UNAVAILABLE`）
  - Feedback review service is unavailable.
  - Try again later.
```

## Follow-up operations

Use [Query feedback](list-feedback.md) to view specific records under statistical conditions.
