创建记忆
curl --request POST \
--url https://api.moonshot.cn/v1/memory-stores/{id}/memories \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "README.md"
}
'import requests
url = "https://api.moonshot.cn/v1/memory-stores/{id}/memories"
payload = { "path": "README.md" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: 'README.md'})
};
fetch('https://api.moonshot.cn/v1/memory-stores/{id}/memories', 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.cn/v1/memory-stores/{id}/memories",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'path' => 'README.md'
]),
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.cn/v1/memory-stores/{id}/memories"
payload := strings.NewReader("{\n \"path\": \"README.md\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://api.moonshot.cn/v1/memory-stores/{id}/memories")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"README.md\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/memory-stores/{id}/memories")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"README.md\"\n}"
response = http.request(request)
puts response.read_body{
"id": "mem_01h455vb4pex5vsknk084sn02q",
"memory_store_id": "mstr_01h455vb4pex5vsknk084sn02q",
"path": "README.md",
"content": "SGVsbG8=",
"content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"content_size_bytes": 5,
"created_at": "2026-01-01T00:00:00.000Z",
"updated_at": "2026-01-01T00:00:00.000Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}在记忆库中创建一个文件,并记录为第一个版本。
content为 base64 编码,解码后不超过 20 MiB。省略时创建空文件。- 相同
path上已有未删除的文件时返回 409conflict_error。重新创建此前删除过的路径会成功,并生成新的文件 ID。 - 已归档的记忆库拒绝写入,返回 400
failed_precondition_error。
POST
/
v1
/
memory-stores
/
{id}
/
memories
创建记忆
curl --request POST \
--url https://api.moonshot.cn/v1/memory-stores/{id}/memories \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "README.md"
}
'import requests
url = "https://api.moonshot.cn/v1/memory-stores/{id}/memories"
payload = { "path": "README.md" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: 'README.md'})
};
fetch('https://api.moonshot.cn/v1/memory-stores/{id}/memories', 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.cn/v1/memory-stores/{id}/memories",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'path' => 'README.md'
]),
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.cn/v1/memory-stores/{id}/memories"
payload := strings.NewReader("{\n \"path\": \"README.md\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://api.moonshot.cn/v1/memory-stores/{id}/memories")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"README.md\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/memory-stores/{id}/memories")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"README.md\"\n}"
response = http.request(request)
puts response.read_body{
"id": "mem_01h455vb4pex5vsknk084sn02q",
"memory_store_id": "mstr_01h455vb4pex5vsknk084sn02q",
"path": "README.md",
"content": "SGVsbG8=",
"content_sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"content_size_bytes": 5,
"created_at": "2026-01-01T00:00:00.000Z",
"updated_at": "2026-01-01T00:00:00.000Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}路径参数
记忆库 ID。
Pattern:
^mstr_[0-9a-hjkmnp-tv-z]{26}$请求体
application/json
响应
已创建的文件,携带其内容与哈希。
记忆库中的一个文件。
id 在重命名后保持不变。删除文件后,其 ID 和版本历史仍可读取。
记忆文件 ID。文件重命名时保持不变。
Pattern:
^mem_[0-9a-hjkmnp-tv-z]{26}$所属记忆库的 ID。
Pattern:
^mstr_[0-9a-hjkmnp-tv-z]{26}$相对于记忆库根目录的路径。
解码后内容的 SHA-256 哈希。更新时回传用作乐观并发检查。
解码后内容的大小,单位为字节。
创建时间戳。
最近一次内容或路径更新的时间戳。
文件内容,经 base64 编码。在创建/获取/更新响应中存在。列表响应中省略。该字段存在与否可区分空文件与内容未加载两种情况。
此页面对您有帮助吗?