Sessions and Messages

Updated at:

The Long-term Memory Service organizes conversation messages into sessions and extracts memories from the messages. The APIs in this topic append and query messages, manage sessions, and query the extraction jobs and memories associated with a message.

Operations in this topic

OperationMethodPathDescription
Append messagesPOST/lmemo/v1/sessions/{session_id}/messagesAppends conversation messages to a specified session.
Query session messagesGET/lmemo/v1/sessions/{session_id}/messagesQueries the messages of a session by message ID cursor.
Submit backlogged messagesPOST/lmemo/v1/sessions/{session_id}/drainSubmits the backlogged messages of a session to the extraction process.
List sessionsGET/lmemo/v1/sessionsQueries the session list of a specified user.
Get a sessionGET/lmemo/v1/sessions/{session_id}Queries a specified session.
Delete a sessionDELETE/lmemo/v1/sessions/{session_id}Deletes a session and its messages.
Query the extraction jobs associated with a messageGET/lmemo/v1/sessions/{session_id}/messages/{message_id}/jobsQueries the IDs of the extraction jobs associated with a message.
Query the memories associated with a messageGET/lmemo/v1/sessions/{session_id}/messages/{message_id}/memoriesQueries the IDs of the memories produced by the completed extraction jobs associated with a message.

Prerequisites

  • LindormTable, LindormSearch, LindormVector, and LindormAI are activated, and the activation configuration of the Long-term Memory Service is complete.

  • A project with a valid project access key (SK). The SK determines the project scope of each request.

Request description

The following items apply to all operations in this topic:

ItemDescription
Request URLThe complete address obtained by concatenating the service endpoint and the API path.
AuthenticationThe request header carries Authorization: Bearer sk-....
Project scopeDetermined by the SK. You do not need to pass project_id.
User scopeDetermined by the user parameter of each API. The application is responsible for verifying the user identity.
Request formatA JSON request body uses Content-Type: application/json.
Response formatA successful response contains request_id and data. For the error format, see Service Overview: Response Description.

Prepare connection information

The examples in this topic use the following shell variables. Replace ENDPOINT with the service endpoint, which includes the protocol, the hostname, and the port. Replace SK with the project access key. The session, message, job, and memory IDs in the commands are example values. Replace them based on your actual data.

ENDPOINT="<service endpoint>"
SK="<project SK>"

Append messages

Appends conversation messages to a specified session. The session_id path parameter specifies the target session. If the session does not exist, the server automatically creates it.

Important

A request is rejected if the project quota is suspended or exceeded while auto_extract is true. A request must also stay within the limits listed in the request parameter tables, such as a maximum of 100 messages per request and a maximum of 5 attachments per message.

Request syntax

MethodURI
POST/lmemo/v1/sessions/{session_id}/messages

Request parameters

The following parameters are passed in the JSON request body.

ParameterTypeRequiredDescription
user_idstringYesThe user ID. Only a-zA-Z0-9_- are allowed.
agent_idstringNoThe agent context ID. The format constraints are the same as those of user_id.
conversation_typestringNonormal (default) or agent_conversation.
messagesarrayYes1 to 100 messages.
auto_extractbooleanNoDefault value: true. If this parameter is set to false, the messages are only saved.
extract_config.immediatebooleanNoDefault value: false. If auto_extract is true and this field is true, extraction is performed synchronously within the request.
session_metadataobjectNoThe session metadata. It takes effect only when the session is created for the first time.
messages[].message_idstringNoThe client message ID. If it is not empty, it is used as the idempotency key. If it is not passed or is blank, the server generates an ID prefixed with msg-.
messages[].rolestringYesuser, assistant, system, or tool.
messages[].contentstringYesThe message content. The maximum length is 65,536 characters. The value can be an empty string but cannot be omitted.
messages[].aliasstringNoThe speaker display name. During extraction, this name takes precedence over role.
messages[].tool_callsarrayNoThe tool calling trace of the agent.
messages[].tool_call_idstringNoThe tool call ID.
messages[].namestringNoThe tool name.
messages[].attachmentsarrayNoThe attachments. A maximum of 5 attachments are allowed. Each item must contain a non-blank string type field.
messages[].metadataobjectNoThe message-level metadata.
messages[].created_atnumberNoThe client message time, as a millisecond timestamp. If this field and mentioned_at are both passed, this field takes precedence.
messages[].mentioned_atnumberNoThe compatibility field for the mentioned time, as a millisecond timestamp. It is used as the time of the message only when created_at is omitted. If both are omitted, the server time is used.

Request example

The following example appends three messages to the session session-001:

curl --request POST "${ENDPOINT}/lmemo/v1/sessions/session-001/messages" \
  --header "Authorization: Bearer ${SK}" \
  --header "Content-Type: application/json" \
  --data-raw '{
  "user_id": "u1",
  "messages": [
    {
      "message_id": "existing-message",
      "role": "user",
      "content": "I like coffee."
    },
    {
      "message_id": "new-message",
      "role": "assistant",
      "content": "Which kind of coffee do you prefer?"
    },
    {
      "role": "user",
      "content": "I like latte."
    }
  ]
}'

Extraction behavior

Memory extraction can be triggered in the following ways:

  • Asynchronous extraction (default): After the messages are saved, the server automatically triggers memory extraction based on the message volume and the waiting time. Query the job status by using the extraction job API.

  • Synchronous extraction (extract_config.immediate=true): Extraction with a timeout limit is performed within the request. This mode is suitable for debugging and small-scale verification. If the execution times out or fails, it can fall back to asynchronous extraction. If the submission phase fails, an error is returned.

  • If auto_extract is true, the project quota is checked before the write. For more information, see the Project Configuration and Quotas API. If the project quota is suspended or exceeded, the request is rejected.

    The following table compares the three extraction trigger paths. For drain, see Submit backlogged messages.
PathBlockingUse caseTimeout or failure behavior
Asynchronous extraction (default)No. Extraction runs after the messages are saved.Production environments—
Synchronous extraction (extract_config.immediate=true)Yes. Extraction runs within the request and has a timeout limit.Debugging and small-scale verificationCan fall back to asynchronous extraction if the execution times out or fails. An error is returned if the submission phase fails.
Drain (POST /lmemo/v1/sessions/{session_id}/drain)—Actively triggering extraction at the end of a session—

For production environments, use asynchronous extraction and reuse the original message_id when you retry.

Idempotency and retries

Within the same session, message_id is used as the idempotency identifier. To retry, reuse the original message_id. If message_id is not passed, the server generates a new ID.

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "session_id": "session-001",
    "requested_message_count": 3,
    "requested_message_ids": ["existing-message", "new-message", "msg-generated"],
    "skipped_message_count": 1,
    "skipped_message_ids": ["existing-message"]
  }
}

Response description

requested_message_ids returns the IDs of all final messages in request order, including the IDs generated by the server. skipped_message_ids returns only the IDs of the messages that are skipped because the ID already exists.

Query session messages

Queries messages based on the session ID. Cursor-based pagination by message ID is supported.

Request syntax

MethodURI
GET/lmemo/v1/sessions/{session_id}/messages

Request parameters

The following parameters are passed as query parameters.

ParameterDescription
afterReturns the messages after the specified message ID. This parameter implements cursor-based pagination.
limitThe number of entries to return. Default value: 50. Maximum value: 200. A value greater than 200 is processed as 200. A value less than or equal to 0 is processed as the default value.

Request example

The following example queries up to 50 messages after the message msg-001 in the session session-001:

curl --request GET "${ENDPOINT}/lmemo/v1/sessions/session-001/messages?after=msg-001&limit=50" \
  --header "Authorization: Bearer ${SK}"

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "session_id": "session-001",
    "messages": [
      {
        "id": "msg-...",
        "role": "user",
        "content": "I like latte",
        "tool_calls": [],
        "attachments": [],
        "created_at": "2026-07-24T08:00:00Z"
      }
    ],
    "has_more": false
  }
}

Response description

In the response, the message ID is returned in the id field, and created_at is an ISO 8601 timestamp. This differs from the request side, where the message ID is named message_id and created_at is a millisecond timestamp. alias, tool_call_id, and name are returned only when they have values.

Get a session

Queries a specified session. The session_id path parameter specifies the target session.

Request syntax

MethodURI
GET/lmemo/v1/sessions/{session_id}

Request example

The following example queries the session session-001:

curl --request GET "${ENDPOINT}/lmemo/v1/sessions/session-001" \
  --header "Authorization: Bearer ${SK}"

Delete a session

Deletes a specified session. The session_id path parameter specifies the target session.

Request syntax

MethodURI
DELETE/lmemo/v1/sessions/{session_id}

Request example

The following example deletes the session session-001:

curl --request DELETE "${ENDPOINT}/lmemo/v1/sessions/session-001" \
  --header "Authorization: Bearer ${SK}"

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "session_id": "session-001",
    "deleted": true
  }
}

Response description

If the session does not exist, deleted=false is returned.

Warning

Deleting a session removes the session and its messages, but does not delete the memory records that have already been extracted. After a session is deleted, the original messages and the message-based retrospection APIs are no longer available.

Submit backlogged messages

Submits the backlogged messages in a session that have not reached the extraction threshold to the extraction process. The request body can be empty. This operation is suitable for actively triggering extraction at the end of a session. For a comparison of the extraction trigger paths, see Extraction behavior.

Request syntax

MethodURI
POST/lmemo/v1/sessions/{session_id}/drain

Request example

The following example submits the backlogged messages of the session session-001:

curl --request POST "${ENDPOINT}/lmemo/v1/sessions/session-001/drain" \
  --header "Authorization: Bearer ${SK}"

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "session_id": "session-001",
    "drained": true,
    "mem_cell_ids": [],
    "batch_ids": []
  }
}

Response description

drained=true indicates that the submission request has been processed. mem_cell_ids and batch_ids are empty arrays. Query the extraction progress by using the extraction job API.

List sessions

Queries the session list of a specified user. This operation uses page-based pagination (page and page_size), unlike Query session messages, which uses cursor-based pagination.

Request syntax

MethodURI
GET/lmemo/v1/sessions

Request parameters

The following parameters are passed as query parameters.

ParameterRequiredDescription
user_idYesThe user ID.
agent_idNoThe agent context ID.
pageNoThe page number. Pages start from 1. Default value: 1.
page_sizeNoThe number of entries per page. Valid values: 1 to 100. Default value: 20.

Request example

The following example queries the first page of the session list of the user u1:

curl --request GET "${ENDPOINT}/lmemo/v1/sessions?user_id=u1&agent_id=a1&page=1&page_size=20" \
  --header "Authorization: Bearer ${SK}"

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "items": [
      {
        "session_id": "session-001",
        "user_id": "u1",
        "agent_id": "a1",
        "conversation_type": "normal",
        "created_at": "2026-07-24T08:00:00Z",
        "updated_at": "2026-07-24T08:10:00Z"
      }
    ],
    "pagination": {
      "page": 1,
      "page_size": 20,
      "total": 1,
      "has_more": false
    }
  }
}

Query the extraction jobs associated with a message

Queries the IDs of the extraction jobs associated with a specified message. The project is determined by the SK. The session ID and the message ID are specified by the session_id and message_id path parameters.

Request syntax

MethodURI
GET/lmemo/v1/sessions/{session_id}/messages/{message_id}/jobs

Request example

The following example queries the extraction jobs associated with the message msg-001 in the session session-001:

curl --request GET "${ENDPOINT}/lmemo/v1/sessions/session-001/messages/msg-001/jobs" \
  --header "Authorization: Bearer ${SK}"

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "job_ids": ["batch-1"]
  }
}

Response description

ScenarioResult
The message exists and has associated jobs.200. The deduplicated IDs of the associated jobs are returned.
The message exists but no extraction job has been generated.200, data.job_ids=[].
A historical message has no recorded associated job.200, data.job_ids=[].
auto_extract=false and no other extraction operation has been performed.200, data.job_ids=[].
The message does not exist.404 not_found.
The association data of the message is invalid.500 internal_error.

This API returns only the IDs of the associated jobs. It does not return the job status, and it does not exclude failed or canceled jobs. Query the job details by using GET /lmemo/v1/jobs/{job_id}.

Query the memories associated with a message

Queries the IDs of the memories produced by the completed extraction jobs associated with a message. The results are aggregated by job. The project is determined by the authenticated SK. A message is located by the combination of the project, the session ID, and the message ID, which are specified by the session_id and message_id path parameters. The request does not need to carry a request body.

Request syntax

MethodURI
GET/lmemo/v1/sessions/{session_id}/messages/{message_id}/memories

Only GET is allowed. Other methods return 405 method_not_allowed.

Request example

The following example queries the memories associated with the message msg-001 in the session session-001:

curl --request GET "${ENDPOINT}/lmemo/v1/sessions/session-001/messages/msg-001/memories" \
  --header "Authorization: Bearer ${SK}"

Response example

The following output is returned:

{
  "request_id": "req-example",
  "data": {
    "memory_ids": ["em-example", "el-example", "ac-example", "as-example"]
  }
}

Response description

data contains only memory_ids. Query the associated jobs by using the API for querying the extraction jobs associated with a message. Query the memory details by using the memory record API.

ScenarioResult
The message does not exist.404 not_found
The message exists but has no associated job or no valid extraction result.200. data.memory_ids=[] is returned.
The associated job is not complete, has been deleted, or has no valid extraction result.The memory IDs of that job are not returned.
The result of the associated job cannot be parsed.The memory IDs of that job are not returned.

The returned IDs are deduplicated in order of first occurrence. User profile updates are not included in this list.

Trace an extraction end to end

To trace how a message turns into memories, complete the following steps:

  1. Append messages to a session. By default, the server triggers memory extraction asynchronously. To submit the backlogged messages that have not reached the extraction threshold, call drain. drained=true indicates that the submission request has been processed.

  2. Query the extraction jobs associated with a message to obtain job_ids. If data.job_ids=[] is returned, no extraction job has been generated yet.

  3. The extraction jobs API in step 2 returns only job IDs. Query the job status and details by using GET /lmemo/v1/jobs/{job_id}.

  4. Query the memories associated with the message to obtain memory_ids. Only completed jobs with valid extraction results contribute memory IDs. If data.memory_ids=[] is returned, the message has no associated job or no valid extraction result.

  5. Query the memory details by using the memory record API.