<span id="创建-ui-协议会话记录"></span>

# Create a UI protocol session record

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

Save a session record for the current user. This request does not call a model.


```http
POST https://api.moi.matrixorigin.cn/v5/sessions
```

<span id="调用前准备"></span>

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`; use the corresponding product API URL for a dedicated deployment.

[Configure identity, workspace, and numeric record IDs in the same environment](objects.md#prepare). This entry point uses ordinary product authentication and rejects additional task-runtime authorization headers.

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

## Request

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

```bash
curl --request POST \
  "$BASE_URL/sessions" \
  --header "X-API-Key: $MOI_KEY" \
  --header "X-Workspace-ID: $WORKSPACE_ID" \
  --header "Content-Type: application/json" \
  --data-raw '{"title":"临时会话","config":"{}"}'
```

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

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Workspace-ID` | Headers | string | Yes | Target workspace ID. |
| `title` | Body | string | No | Session title, default empty string. |
| `source` | Body | string | No | Application source. Omission, null, or an empty string uses moi. |
| `config` | Body | string | No | Configuration text; JSON configuration must also be a string. |
| `tags` | Body | array (strings) | No | Request binding accepts this field, but the current creation operation does not save tag relationships. |

Success returns HTTP 200, unlike the workspace LLM creation API's 201. Save the numeric ID returned. There is no business request_id deduplication; if the outcome is unknown, query first to avoid duplicate creation.

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

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

## Successful response

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

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 41,
    "title": "临时会话",
    "source": "moi",
    "user_id": "user-example",
    "config": "{}",
    "tags": [],
    "created_at": 1794445200,
    "updated_at": 1794445200
  }
}
```

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

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | OK on success; HTTP status 200. |
| `msg` | string | OK on success. |
| `data` | object | [Session object](objects.md#session-object). |

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

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

## Error responses

[Error formats and result confirmation](objects.md#error-contract) distinguishes session-detail not-found errors from generic service errors at other entry points.
