<span id="发送访客消息并读取事件流"></span>

# Send a visitor message and read the event stream

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

Create a conversation first. message/send, task control, Provider interaction responses, and feedback data branches are unsupported. Preadmission failures may return regular public JSON or JSON-RPC errors. After SSE opens, errors appear in frames. HTTP 200 does not mean task completion. Stream disconnection after persistent admission does not cancel the task; read messages/events again.


```http
POST https://api.moi.matrixorigin.cn/v5/public/webapp/a2a
```

<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.

[Prepare links and visitor identity in the same environment](identity-lifecycle.md#prepare). Do not supply a product PAT or Workspace request header.

<span id="请求"></span>

## Request

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

```bash
curl --no-buffer --request POST \
  "$BASE_URL/public/webapp/a2a?webapp=$AGENT_ID&t=$WEBAPP_TOKEN&s=$WEBAPP_SESSION" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{"jsonrpc": "2.0", "id": "request-example", "method": "message/stream", "params": {"message": {"messageId": "message-example", "contextId": "${CONVERSATION_ID}", "role": "user", "parts": [{"kind": "text", "text": "你好"}]}, "idempotencyKey": "example-turn-key"}}
JSON
```

:::::
:::::{tab-item} Parameters

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `webapp` | Query | string | Yes | Agent ID corresponding to the link. |
| `t` | Query | string | Yes | Current valid publication token. For short-code links, resolve first and use the short code as t. |
| `s` | Query | string | Yes | Visitor session credentials under the same publication. |
| `jsonrpc` | Body | string | Yes | Fixed2.0. |
| `method` | Body | string | Yes | message/stream only. |
| `id` | Body | JSON | No | JSON-RPC request identifier. |
| `params.message` | Body | object | Yes | Includes messageId, an already-created conversation contextId, role=user, and nonempty parts containing nonempty text or attachments. |
| `params.idempotencyKey` | Body | string | No | Reuse when retrying the same logical request. Changed content requires a new message ID/key. |
| `params.model` | Body | string | No | Model selection, still constrained by agent/runtime configuration. |
| `params.llm_backend_id` | Body | integer | No | Backend selection; verify actual compatibility during execution. |
| `params.metadata` | Body | object | No | Metadata and canonical attachment credentials, not arbitrary file authorization. |

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

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

## Successful response

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

Response is `text/event-stream`. Each `data:` frame carries a JSON-RPC result/error. Determine results from task states and terminal frames.

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

This entry point returns byte/event streams. Follow this page and [stream and file boundaries](streams-files.md).

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

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

## Error response

[Public errors and identity handling](identity-lifecycle.md#errors) distinguishes unavailable links, disablement, invalid sessions, parameters, and system failures.
