添加会话资源
curl --request POST \
--url https://api.moonshot.cn/v1/sessions/{id}/resources \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "file",
"file_id": "file_01h455vb4pex5vsknk084sn02q"
}
'import requests
url = "https://api.moonshot.cn/v1/sessions/{id}/resources"
payload = {
"type": "file",
"file_id": "file_01h455vb4pex5vsknk084sn02q"
}
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({type: 'file', file_id: 'file_01h455vb4pex5vsknk084sn02q'})
};
fetch('https://api.moonshot.cn/v1/sessions/{id}/resources', 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/sessions/{id}/resources",
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([
'type' => 'file',
'file_id' => 'file_01h455vb4pex5vsknk084sn02q'
]),
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/sessions/{id}/resources"
payload := strings.NewReader("{\n \"type\": \"file\",\n \"file_id\": \"file_01h455vb4pex5vsknk084sn02q\"\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/sessions/{id}/resources")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"file\",\n \"file_id\": \"file_01h455vb4pex5vsknk084sn02q\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/sessions/{id}/resources")
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 \"type\": \"file\",\n \"file_id\": \"file_01h455vb4pex5vsknk084sn02q\"\n}"
response = http.request(request)
puts response.read_body{
"type": "file",
"id": "sres_01h455vb4pex5vsknk084sn02q",
"file_id": "file_01h455vb4pex5vsknk084sn02q"
}{
"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>"
}
}将一个已上传的文件绑定到会话,并返回该绑定。
创建后只能添加文件。凭据库(Vault)与记忆库的绑定在会话创建时即已固定。重复绑定同一文件,或文件名在工作区中冲突,将返回 409 conflict_error。
POST
/
v1
/
sessions
/
{id}
/
resources
添加会话资源
curl --request POST \
--url https://api.moonshot.cn/v1/sessions/{id}/resources \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"type": "file",
"file_id": "file_01h455vb4pex5vsknk084sn02q"
}
'import requests
url = "https://api.moonshot.cn/v1/sessions/{id}/resources"
payload = {
"type": "file",
"file_id": "file_01h455vb4pex5vsknk084sn02q"
}
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({type: 'file', file_id: 'file_01h455vb4pex5vsknk084sn02q'})
};
fetch('https://api.moonshot.cn/v1/sessions/{id}/resources', 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/sessions/{id}/resources",
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([
'type' => 'file',
'file_id' => 'file_01h455vb4pex5vsknk084sn02q'
]),
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/sessions/{id}/resources"
payload := strings.NewReader("{\n \"type\": \"file\",\n \"file_id\": \"file_01h455vb4pex5vsknk084sn02q\"\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/sessions/{id}/resources")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"type\": \"file\",\n \"file_id\": \"file_01h455vb4pex5vsknk084sn02q\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/sessions/{id}/resources")
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 \"type\": \"file\",\n \"file_id\": \"file_01h455vb4pex5vsknk084sn02q\"\n}"
response = http.request(request)
puts response.read_body{
"type": "file",
"id": "sres_01h455vb4pex5vsknk084sn02q",
"file_id": "file_01h455vb4pex5vsknk084sn02q"
}{
"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:
^sesn_[0-9a-hjkmnp-tv-z]{26}$请求体
application/json
响应
已创建的资源绑定,携带分配的 id。
此页面对您有帮助吗?