<span id="查询最近-llm-消息-id"></span>

# Get the latest LLM message ID

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

Query the maximum message ID in the specified conversation for the current user.


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

<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/latest?completed_only=true" \
  --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. |
| `completed_only` | Query | string | No | 1 or case-insensitive true selects status=completed only; other values do not restrict state. |

message_id is0 without matching messages. This read does not independently check conversation existence, so0 proves neither existence nor absence. completed is a stored state, not proof of model task completion. Current dedicated SDK/CLI latest-message methods have no completed_only parameter. Use verified HTTP or generic resource requests for this condition.

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

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

## Successful response

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

```json
{
  "code": 0,
  "data": {
    "message_id": 0
  }
}
```

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

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | 0 on success; HTTP status is 200. |
| `data.message_id` | integer | Maximum message ID;0 if no message matches. |

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

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

## Error response

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