> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新 Session

> 更新 Session 的可变属性。

`POST /api/v1/cloud/sessions/{session_id}`

更新 Session 的可变属性。省略的字段保持不变。

## 路径参数

| 参数           | 类型     | 说明                        |
| ------------ | ------ | ------------------------- |
| `session_id` | string | 以 `sess_` 为前缀的 Session ID |

## 请求头

| 请求头             | 必填 | 说明                  |
| --------------- | -- | ------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT` |
| `Content-Type`  | 是  | `application/json`  |

## 请求体

| 字段         | 类型             | 必填 | 说明                                                                  |
| ---------- | -------------- | -- | ------------------------------------------------------------------- |
| `title`    | string \| null | 否  | 新标题；传 `null` 表示清空                                                   |
| `metadata` | object \| null | 否  | metadata patch。对象内值为 `null` 的 key 会被删除；顶层 `metadata:null` 当前为 no-op |
| `agent`    | object         | 否  | Session 中途 Agent 更新；仅支持 `tools` 和 `mcp_servers`，出现时为完整替换            |

> 提示：`vault_ids` 出现在 Session 公开形态中，但本端点当前不支持写入 —— 携带后请求会被拒绝。仅在读取时使用，请求体不应包含该字段。`delta_flush_interval_ms` 也不支持。

## 示例请求

```bash theme={null}
curl -X POST https://api.qoder.com/api/v1/cloud/sessions/sess_019e3bb1e8c171fd9abbb1477ffb84cc \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "New title",
    "metadata": {"priority": "high", "old_key": null},
    "agent": {
      "tools": [],
      "mcp_servers": []
    }
  }'
```

## 示例响应

**HTTP 200 OK**

返回更新后的 [Session 对象](/zh/cloud-agents/api/sessions/schemas#session-对象)。

## 错误码

| HTTP | 类型                      | 触发条件                         |
| ---- | ----------------------- | ---------------------------- |
| 400  | `invalid_request_error` | 请求体格式错误、字段不支持或 Agent 更新字段不支持 |
| 401  | `authentication_error`  | PAT 无效或过期                    |
| 404  | `not_found_error`       | Session 不存在                  |

**HTTP 400 Bad Request**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "invalid_request_error",
    "message": "metadata must be an object"
  }
}
```

**HTTP 404 Not Found**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "not_found_error",
    "message": "Session 'sess_does_not_exist_0000000000000000000000000000' was not found."
  }
}
```

完整错误信封格式参见 [错误处理](/zh/cloud-agents/api/conventions/errors)。

## 相关

<CardGroup cols={2}>
  <Card title="启动 Session" icon="play" href="/zh/cloud-agents/sessions">
    让 Agent 在环境中以有状态对话的方式运行。
  </Card>
</CardGroup>
