<span id="查询-llm-会话消息"></span>

# List LLM conversation messages

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Read the current user's conversation messages using a message ID cursor.


```http
GET https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/llm/sessions/{session_id}/messages
```

<span id="调用前准备"></span>

## Before you call this API

`BASE_URL` uses the product API prefix `https://api.moi.matrixorigin.cn/v5`. For a dedicated deployment, use its corresponding product API address.

[Configure Workspace identity and variables in the same environment](objects.md#request-prerequisites).

<span id="请求"></span>

## Request

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl --request GET \
  "$BASE_URL/workspaces/$WORKSPACE_ID/llm/sessions/$SESSION_ID/messages?after=0&limit=50" \
  --header "X-API-Key: $MOI_KEY" \
  --header "X-Workspace-ID: $WORKSPACE_ID"
```

Save the last message id from the preceding page as AFTER_MESSAGE_ID, then read the next page:

```bash
curl --request GET \
  "$BASE_URL/workspaces/$WORKSPACE_ID/llm/sessions/$SESSION_ID/messages?after=$AFTER_MESSAGE_ID&limit=50" \
  --header "X-API-Key: $MOI_KEY" \
  --header "X-Workspace-ID: $WORKSPACE_ID"
```

:::::
:::::{tab-item} Parameters

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `workspace_id` | Path | string | Yes | Target Workspace, matching X-Workspace-ID. |
| `session_id` | Path | integer | Yes | Positive integer ID returned by this service. |
| `after` | Query | integer | No | Returns IDs greater than this value. Defaults to 0; nonpositive values become0. |
| `limit` | Query | integer | No | Maximum messages per request, default 50. Values<=0 or>100 use 50. |
| `role` | Query | integer | No | Single role filter:0=user,1=system,2=assistant. The current service treats3 as no filtering. |
| `status` | Query | string | No | Filter by stored state; surrounding whitespace is trimmed. |

Messages sort by ascending ID. Set next after to the preceding page's last message id, retain filters, and continue until messages=[]. There is no next_cursor. total is the total after role/status filters and does not shrink with after. role must be one integer parseable as0–3. Repeated, empty, or out-of-range values return 400; omission means no filter. source/model currently do not filter results.

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 0,
  "data": {
    "messages": [
      {
        "id": 71,
        "user_id": "user-example",
        "session_id": 41,
        "source": "moi",
        "role": 0,
        "original_content": "",
        "content": "保存这条消息",
        "model": "",
        "status": "pending",
        "response": "",
        "modified_response": "",
        "config": "",
        "created_at": 1794445200,
        "updated_at": 1794445200
      }
    ],
    "total": 1
  }
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | 0 on success; HTTP status is 200. |
| `data.messages` | array (array of objects) | [Message records](objects.md#message-object) on this page. |
| `data.total` | integer | Total matching role/state filters, independent of after. |

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error response

[Error formats and read scope](objects.md#error-contract) explains differing identity, parameter, resource-read, and storage-failure outcomes.
