Update a Memory
Changes a file’s path, content, or both, and records the change as a new version.
- Send the file’s current
content_sha256to guard against concurrent writes. A mismatch fails with 409conflict_error. - An update that changes neither path nor content returns the current file without recording a new version.
- Renaming onto another live file’s path returns 409
conflict_error. An archived store rejects writes with 400failed_precondition_error.
curl --request PATCH \
--url https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content": "V29ybGQ=",
"content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
'import requests
url = "https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}"
payload = {
"content": "V29ybGQ=",
"content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
content: 'V29ybGQ=',
content_sha256: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
})
};
fetch('https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'content' => 'V29ybGQ=',
'content_sha256' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}"
payload := strings.NewReader("{\n \"content\": \"V29ybGQ=\",\n \"content_sha256\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"content\": \"V29ybGQ=\",\n \"content_sha256\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"content\": \"V29ybGQ=\",\n \"content_sha256\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}"
response = http.request(request)
puts response.read_body{
"id": "mem_01h455vb4pex5vsknk084sn02q",
"memory_store_id": "mstr_01h455vb4pex5vsknk084sn02q",
"path": "README.md",
"content": "V29ybGQ=",
"content_sha256": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"content_size_bytes": 5,
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-02T00:00:00Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "The `name` parameter is invalid.",
"request_id": "req_01h455vb4pex5vsknk084sn02q",
"param": "name"
}
}{
"error": {
"type": "authentication_error",
"message": "Provide valid credentials before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "resource_not_found_error",
"message": "The requested resource does not exist.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "conflict_error",
"message": "The resource changed since it was read. Reload it before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "rate_limit_reached_error",
"message": "Too many requests. Retry after 60 seconds.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "server_error",
"message": "The platform could not complete the request. Retry later.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}Headers
API version for this request, in YYYY-MM-DD form. Send 2026-09-01-beta
for the version documented here. Required outside /v1/files*: a missing
header there is rejected with 400 invalid_request_error; on /v1/files*
its absence selects the compatibility behavior. An unknown value is
rejected with 400 invalid_request_error on every endpoint.
API versions served by the platform. New dated versions are added as they
ship; a version is removed after its announced Sunset date.
2026-09-01-beta Body
Path and replacement content for the memory file. Include its current content hash to detect concurrent changes.
Partial-update body for updating a memory file: content, path, or both.
content_sha256 is an optimistic-concurrency check on the current file
content.
Response
The file after the update, with its content and new hash.
A file in a Memory Store.
The id stays stable across renames, and deleting the file keeps its ID
and version history readable.
Was this page helpful?
curl --request PATCH \
--url https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"content": "V29ybGQ=",
"content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
'import requests
url = "https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}"
payload = {
"content": "V29ybGQ=",
"content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
content: 'V29ybGQ=',
content_sha256: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
})
};
fetch('https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'content' => 'V29ybGQ=',
'content_sha256' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}"
payload := strings.NewReader("{\n \"content\": \"V29ybGQ=\",\n \"content_sha256\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"content\": \"V29ybGQ=\",\n \"content_sha256\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.ai/v1/memory-stores/{id}/memories/{memory_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"content\": \"V29ybGQ=\",\n \"content_sha256\": \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}"
response = http.request(request)
puts response.read_body{
"id": "mem_01h455vb4pex5vsknk084sn02q",
"memory_store_id": "mstr_01h455vb4pex5vsknk084sn02q",
"path": "README.md",
"content": "V29ybGQ=",
"content_sha256": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"content_size_bytes": 5,
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-02T00:00:00Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "The `name` parameter is invalid.",
"request_id": "req_01h455vb4pex5vsknk084sn02q",
"param": "name"
}
}{
"error": {
"type": "authentication_error",
"message": "Provide valid credentials before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "resource_not_found_error",
"message": "The requested resource does not exist.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "conflict_error",
"message": "The resource changed since it was read. Reload it before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "rate_limit_reached_error",
"message": "Too many requests. Retry after 60 seconds.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "server_error",
"message": "The platform could not complete the request. Retry later.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}