Skip to main content

Send Event

Writes events to a session: user messages, interrupts, tool approvals, and function result backfills. The request body contains only the top-level input field, which is an array of events (length 1-50).

Prerequisites

A session must already be created. For details, see Create Session.

Endpoint

POST /sessions/{session_id}/events The request body contains only one top-level field input, which is an array of events (length 1-50). Each event must contain at least role and type.

Request body structure

{
  "input": [
    { "role": "user", "type": "message", "content": [...] }
  ]
}

Client event types

typeroleRequired fieldsPurpose
messageusercontent (array)Sends a user message, triggering the agent to enter running state
interruptuserrole, typeInterrupts the current turn; the session returns to idle. Optional top-level session_thread_id (in multi-agent scenarios, targets a specific sub-thread)
tool_approval_responseusercontent (exactly one data block)Responds to a tool approval. data must contain batch_id (matches the tool_approval_request batch_id), call_id (the tool call ID to rule on), and result (allow | deny). Optional deny_message (only for deny, passed back to the model as tool output). batch_id and call_id together identify an approval (composite identity, both non-empty, minLength: 1). Multiple tool_approval_response in the same request must belong to the same batch_id. Tool approval is only supported on the main agent, not sub-agents
function_call_outputtoolcontent (single data block with call_id + output)Backfills the result of a self-hosted function. Optional top-level is_error and session_thread_id
tool_call_outputtoolcontent (single data block with call_id + output)Backfills the result of a self-hosted platform built-in tool. Same structure as function_call_output; optional is_error and session_thread_id
During a pending tool approval, mixed inputs are handled on two separate branches and neither approval takes effect (the current batch still exists, pending_call_ids remain unchanged): (1) sending tool_approval_response together with a plain message in the same batch results in a pending_tool_approval_unresolved event/terminal state; (2) sending tool_approval_response together with interrupt is rejected due to control-message conflict, with error code invalid_tool_approval. Neither is a synchronous 4xx of this POST; observe via the SSE event stream or GET /events. interrupt and a plain message may be sent together in the same request (semantics: end the current approval batch first, then start chatting).

ContentBlock: message content

content is an array of ContentBlocks. Each block is distinguished by type and must use exactly one carrier.
typeMutually exclusive fieldsDescription
texttextPlain text
imageimage_url | file_idImage, enters the model's vision channel: public URL or uploaded file ID (dereferenced to a temporary URL, rendered for this turn only, not persisted)
videovideo_url | file_idVideo, enters the model's vision channel: public URL or uploaded file ID
audiodata + format | file_idAudio: only appears in server-side pushes/responses (as a tool output attachment); cannot be sent as client input
filefile_id + filenameFile: uploaded file ID, requires filename (used for the sandbox path and file manifest). Base64 input is not supported. The file is materialized to the session sandbox by the platform, and the model reads it on demand. file_id is the persistent source of truth
datadata (object)Structured data (JSON). Server-side status events also use this carrier
refusalrefusalModel refusal message; only appears in server-side pushes

Example: send a text message

curl -X POST "$AGENTSTUDIO_URL/sessions/sesn_01K8ZQX3/events" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": [
      {
        "role": "user",
        "type": "message",
        "content": [
          {"type": "text", "text": "分析 /mnt/session/uploads/sales.csv 中 Q3 的销售趋势"}
        ]
      }
    ]
  }'

Response

200 OK means the events were accepted (enqueued). It does not mean the agent has started processing or that an approval ruling has taken effect — especially for tool_approval_response, acceptance does not mean the approval has been applied. Observe actual processing results via the SSE event stream or GET /events.
{
  "data": [
    {
      "object": "message",
      "id": "msg_8f2a1c...",
      "created_at": "2025-10-24T08:15:30.123Z",
      "role": "user",
      "type": "message",
      "status": "completed",
      "content": [{"type": "text", "text": "..."}]
    }
  ],
  "request_id": "req_01K8ZQX..."
}

Response fields

FieldTypeDescription
dataarray<object>Array of echoed accepted events, aligned with the request input order; echo only means enqueued, not that it has been processed or that a ruling has taken effect
data[].objectstringObject type, always message
data[].idstringServer-assigned message ID, format msg_&lt;ULID&gt;
data[].created_atstringServer write time, ISO 8601
data[].rolestringEvent role, echoes the user (or tool) from the request
data[].typestringEvent type, echoes the type of the sent event (e.g., sending message echoes message; sending tool_approval_response echoes tool_approval_response), not always message
data[].statusstringWrite status, always completed
data[].contentarray<object>ContentBlock array, same structure as the request
request_idstringUnique identifier for this request
Flow Agent API
Sandbox API
RAG API
Long-term Memory
ParseX API
Security API
Framework Integration