Add Message

This API allows you to add one or more messages to a specific conversation. As illustrated in the examples bellow, you can add messages in real time during a user-assistant interaction, import historical messages in bulk, or enrich the conversation with user preferences and behavior data. All added messages are transformed into memories by MemOS, enabling their retrieval in future conversations to support chat history management, user behavior tracking, and personalized interactions.

POST
/
add
/
message
import os
import requests
import json

# Replace with your API Key
os.environ["MEMOS_API_KEY"] = "YOUR_API_KEY"
os.environ["MEMOS_BASE_URL"] = "https://memos.memtensor.cn/api/openmem/v1"

data = {
    "user_id": "memos_user_123",
    "conversation_id": "0610",
    "messages": [
      {"role": "user", "content": "I’ve planned to travel to Guangzhou this summer. What chain hotels are available for accommodation?"},
      {"role": "assistant", "content": "You can consider options like 7 Days Inn, All Seasons, Hilton, etc."},
      {"role": "user", "content": "I’ll choose 7 Days Inn."},
      {"role": "assistant", "content": "Alright, feel free to ask me if you have any other questions."}
    ]
  }
headers = {
  "Content-Type": "application/json",
  "Authorization": f"Token {os.environ['MEMOS_API_KEY']}"
}
url = f"{os.environ['MEMOS_BASE_URL']}/add/message"

res = requests.post(url=url, headers=headers, data=json.dumps(data))

print(f"result: {res.json()}")
{
  "code": 0,
  "data": {
    "success": true,
    "task_id": "<string>",
    "status": "running"
  },
  "message": "ok"
}

Authorizations

Authorization
string
header
required

Token API_key, available in API Console > API Keys

Body

application/json
user_id
string
required

Unique identifier of the user associated with the message.

conversation_id
string
required

Unique identifier of the conversation.

messages
MessageInput·object[]
required

Array of message objects representing the memory content. The total token limit for the message array is 8k. Each object contains:

Show child attributes
agent_id
string

Unique identifier of the Agent associated with the added message, primarily used to query exclusive memories between a user and that Agent during retrieval.

app_id
string

Unique identifier of the App associated with the added message, primarily used to query exclusive memories of a user under that App during retrieval.

tags
string[]
default: []

List of custom tags used to mark the topic or category of the added message.

info
object

Custom metadata field capable of storing any structured data related to the added message, such as location, source, version, etc., primarily for precise filtering or source tracking during retrieval.

allow_public
boolean
default: false

Whether memories generated from the added message are allowed to be written to the public memory store. When enabled, generated memories can be retrieved by other users in the project.

allow_knowledgebase_ids
string[]
default: []

Scope of knowledgebases where memories generated from the added message are allowed to be written.

async_mode
boolean
default: true

Whether to enable asynchronous memory addition. When enabled, memory will be added asynchronously in the background to avoid blocking the call chain.

Response

application/json

Successful Response

code
number
required

API status code. See Error Code for details

Example: 0
data
object

Object representing the result of adding the message.

Show child attributes
message
string
required

API response message, e.g., "Message added successfully".

Example: "ok"