Back to Eliza

Conversations API

packages/docs/rest/conversations.md

2.0.110.9 KB
Original Source

The conversations API manages the agent's web-chat interface. Each conversation has its own room in the runtime's memory system, allowing independent message histories. The API supports both streaming (SSE) and synchronous message delivery.

Endpoints

MethodPathDescription
GET/api/conversationsList all conversations
POST/api/conversationsCreate a new conversation
GET/api/conversations/:id/messagesGet messages for a conversation
POST/api/conversations/:id/messagesSend a message (synchronous)
POST/api/conversations/:id/messages/streamSend a message (SSE streaming)
POST/api/conversations/:id/messages/truncateTruncate messages from a point
POST/api/conversations/:id/greetingGenerate a greeting message
PATCH/api/conversations/:idUpdate conversation metadata
DELETE/api/conversations/:idDelete a conversation
POST/api/conversations/cleanup-emptyDelete empty conversations

GET /api/conversations

List all conversations, sorted by most recently updated first.

Response

json
{
  "conversations": [
    {
      "id": "uuid",
      "title": "Morning Chat",
      "roomId": "uuid",
      "createdAt": "2025-06-01T10:00:00.000Z",
      "updatedAt": "2025-06-01T12:30:00.000Z"
    }
  ]
}

POST /api/conversations

Create a new conversation with its own room.

Request Body

FieldTypeRequiredDescription
titlestringNoConversation title (default "New Chat")

Response

json
{
  "conversation": {
    "id": "uuid",
    "title": "New Chat",
    "roomId": "uuid",
    "createdAt": "2025-06-01T12:00:00.000Z",
    "updatedAt": "2025-06-01T12:00:00.000Z"
  }
}

GET /api/conversations/:id/messages

Retrieve up to 200 messages for a conversation, sorted oldest first. Messages with empty text content (such as action-log memories) are automatically filtered out.

Response

json
{
  "messages": [
    {
      "id": "uuid",
      "role": "user",
      "text": "Hello!",
      "timestamp": 1718000000000
    },
    {
      "id": "uuid",
      "role": "assistant",
      "text": "Hey there! How can I help?",
      "timestamp": 1718000001000
    },
    {
      "id": "uuid",
      "role": "user",
      "text": "What's going on in Discord?",
      "timestamp": 1718000002000,
      "source": "discord",
      "from": "Alice",
      "fromUserName": "alice#1234",
      "avatarUrl": "https://cdn.discordapp.com/avatars/..."
    }
  ]
}
FieldTypeDescription
messages[].rolestringuser or assistant
messages[].textstringMessage text content
messages[].timestampnumberUnix timestamp (ms) when the message was created
messages[].sourcestring|undefinedConnector source identifier (e.g. discord, telegram). Omitted for web-chat messages
messages[].fromstring|undefinedDisplay name of the sender entity, when available
messages[].fromUserNamestring|undefinedUsername or handle of the sender (e.g. Discord username), when the connector provides one
messages[].avatarUrlstring|undefinedSender avatar URL when the connector can provide one

Errors

StatusCondition
404Conversation not found

POST /api/conversations/:id/messages

Send a message and get the agent's response synchronously (non-streaming).

Request Body

FieldTypeRequiredDescription
textstringYesUser message text
channelTypestringNoChannel type override
imagesarrayNoAttached image data ([{ data, mimeType }])
conversationModestringNo"simple" or "power"
languagestringNoPreferred response language
sourcestringNoSource identifier for the message
metadataobjectNoArbitrary metadata to attach to the message

Response

json
{
  "text": "Here's what I think...",
  "agentName": "Eliza"
}

Errors

StatusCondition
404Conversation not found
503Agent is not running

POST /api/conversations/:id/messages/stream

Send a message and receive the agent's response via Server-Sent Events (SSE). Each token is streamed as it is generated, followed by a final done event.

Request Body

Same as POST /api/conversations/:id/messages.

SSE Events

Token events (append semantics — each text chunk extends the reply):

data: {"type":"token","text":"Here's"}
data: {"type":"token","text":" what"}
data: {"type":"token","text":" I think..."}

Snapshot events (replace semantics — used when action callbacks update the reply in-place):

data: {"type":"token","fullText":"Here's what I think...\n\nSearching for track..."}

When a fullText field is present, it is authoritative and the client should replace the entire assistant message text rather than appending.

Final event:

data: {"type":"done","fullText":"Here's what I think...","agentName":"Eliza"}

The conversation title is auto-generated in the background if it is still "New Chat", and a conversation-updated WebSocket event is broadcast. If AI title generation fails, the title falls back to the first five words of the user's message.

<Info> Action callbacks (e.g. from music playback, wallet flows) use **replace** semantics by default: each successive callback replaces the callback portion of the message rather than appending. Callbacks can optionally set `merge: "append"` or `merge: "replace"` on the callback content when a plugin needs to override that default. See [Action callbacks and SSE streaming](/runtime/action-callback-streaming) for details. </Info>

Error recovery

If the model provider fails after tokens have already been streamed to the client, the server preserves the streamed text. The done event's fullText contains the text that was already delivered rather than a generic error message. This prevents the client from losing a partially complete reply.

If the failure occurs before any text is streamed, the done event's fullText contains a fallback error description (e.g. provider connectivity issue) so the user still receives feedback.

In both cases, an error SSE event may also be emitted if the reply cannot be persisted:

data: {"type":"error","message":"Failed to persist message"}

POST /api/conversations/:id/messages/truncate

Truncate (delete) messages in a conversation starting from a specific message. By default, deletes messages after the specified message; set inclusive to also delete the specified message itself.

Request Body

FieldTypeRequiredDescription
messageIdstringYesID of the message to truncate from
inclusivebooleanNoIf true, also delete the specified message (default: false)

Response

json
{
  "ok": true,
  "deletedCount": 5
}

Errors

StatusCondition
400Missing messageId
404Conversation not found
503Agent is not running

POST /api/conversations/:id/greeting

Generate a greeting message for a new conversation. Picks a random postExample from the agent's character definition — no model call, no latency. The greeting is stored as an agent message for persistence.

Response

json
{
  "text": "gm. ready to go viral today or what.",
  "agentName": "Eliza",
  "generated": true
}
FieldTypeDescription
textstringThe greeting text (empty if no post examples exist)
agentNamestringAgent's display name
generatedbooleantrue if post examples were available

PATCH /api/conversations/:id

Update conversation metadata: rename, auto-generate a title, or update structured metadata.

Request Body

FieldTypeRequiredDescription
titlestringNoNew conversation title
generatebooleanNoAuto-generate a title from the last user message using the AI model
metadataobject|nullNoStructured metadata to attach to the conversation (set to null to clear)

Response

json
{
  "conversation": {
    "id": "uuid",
    "title": "Updated Title",
    "roomId": "uuid",
    "createdAt": "2025-06-01T10:00:00.000Z",
    "updatedAt": "2025-06-01T14:00:00.000Z"
  }
}

Errors

StatusCondition
404Conversation not found

POST /api/conversations/:id/messages/truncate

Truncate messages in a conversation starting from a given message ID. Useful for "edit and regenerate" flows where the user wants to discard messages from a certain point onward.

Request Body

FieldTypeRequiredDescription
messageIdstringYesID of the message to truncate from
inclusivebooleanNoWhether to also delete the specified message (default: false)

Response

json
{
  "ok": true,
  "deletedCount": 3
}

Errors

StatusCondition
400Missing messageId
404Conversation not found
503Agent is not running

DELETE /api/conversations/:id

Delete a conversation. Messages remain in the runtime memory but the conversation metadata is removed.

Response

json
{
  "ok": true
}

POST /api/conversations/cleanup-empty

Delete all conversations that have no messages. Optionally keep a specific conversation.

Request Body

FieldTypeRequiredDescription
keepIdstringNoConversation ID to exclude from cleanup

Response

json
{
  "deleted": ["uuid1", "uuid2"]
}

POST /api/conversations/cleanup-empty

Delete all conversations that have no user messages. Useful for clearing auto-created conversations that were never used. Optionally keep a specific conversation.

Request Body

FieldTypeRequiredDescription
keepIdstringNoConversation ID to preserve even if empty

Response

json
{
  "deleted": ["uuid-1", "uuid-2"]
}
FieldTypeDescription
deletedstring[]IDs of conversations that were deleted

Common Error Codes

StatusCodeDescription
400INVALID_REQUESTRequest body is malformed or missing required fields
401UNAUTHORIZEDMissing or invalid authentication token
404NOT_FOUNDRequested resource does not exist
404CONVERSATION_NOT_FOUNDConversation with specified ID does not exist
503SERVICE_UNAVAILABLEAgent service is not currently running
500INTERNAL_ERRORUnexpected server error