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

# 更新 Memory

> 更新一条 memory 的内容。

`POST /api/v1/cloud/memory_stores/{memory_store_id}/memories/{memory_id}`

更新一条 memory。系统会自动创建一个新的版本快照。

## 路径参数

| 参数                | 说明                              |
| ----------------- | ------------------------------- |
| `memory_store_id` | Memory Store ID（`memstore_...`） |
| `memory_id`       | Memory ID（`mem_...`）            |

## 请求头

| 头部              | 必选 | 说明                 |
| --------------- | -- | ------------------ |
| `Authorization` | 是  | `Bearer <PAT>`     |
| `Content-Type`  | 是  | `application/json` |

## 请求体

| 字段               | 类型     | 必选 | 说明                                           |
| ---------------- | ------ | -- | -------------------------------------------- |
| `content`        | string | 是  | 新内容，最大 100 KB                                |
| `content_sha256` | string | 否  | 用于乐观并发控制的期望 SHA-256。不匹配时返回 409               |
| `metadata`       | object | 否  | 自定义键值元数据。最多 16 对；key 1–64 字符；value 最长 512 字符 |

## 示例请求

```bash theme={null}
curl -X POST "https://api.qoder.com/api/v1/cloud/memory_stores/memstore_xxx/memories/mem_xxx" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "# 更新后的内容",
    "content_sha256": "a1b2c3..."
  }'
```

## 响应

返回更新后、包含 `content` 的 [Memory 对象](/zh/cloud-agents/api/memory-stores/schemas#memory-对象)。

## 错误码

| HTTP | type                    | 触发条件                    |
| ---- | ----------------------- | ----------------------- |
| 400  | `invalid_request_error` | `content` 为空或超限         |
| 404  | `not_found_error`       | Store 或 memory 不存在      |
| 409  | `invalid_request_error` | Store 已归档，或 SHA-256 不匹配 |

完整错误信封说明详见 [错误参考](/zh/cloud-agents/api/conventions/errors)。
