批量创建凭据
以原子方式创建 1–20 条凭据:任一条目校验失败则全部不创建。
每个条目遵循单条创建规则,并计入凭据库(Vault)的 20 条活跃凭据上限。批次内出现重复键返回 400 invalid_request_error。响应按请求顺序列出已创建的凭据。
POST
/
v1
/
vaults
/
{id}
/
credentials
/
batch
批量创建凭据
curl --request POST \
--url https://api.moonshot.cn/v1/vaults/{id}/credentials/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"display_name": "MCP access",
"auth": {
"type": "static_bearer",
"mcp_server_url": "https://example.invalid/mcp",
"token": "sk-example"
}
}
]
}
'import requests
url = "https://api.moonshot.cn/v1/vaults/{id}/credentials/batch"
payload = { "items": [
{
"display_name": "MCP access",
"auth": {
"type": "static_bearer",
"mcp_server_url": "https://example.invalid/mcp",
"token": "sk-example"
}
}
] }
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({
items: [
{
display_name: 'MCP access',
auth: {
type: 'static_bearer',
mcp_server_url: 'https://example.invalid/mcp',
token: 'sk-example'
}
}
]
})
};
fetch('https://api.moonshot.cn/v1/vaults/{id}/credentials/batch', 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/vaults/{id}/credentials/batch",
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([
'items' => [
[
'display_name' => 'MCP access',
'auth' => [
'type' => 'static_bearer',
'mcp_server_url' => 'https://example.invalid/mcp',
'token' => 'sk-example'
]
]
]
]),
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/vaults/{id}/credentials/batch"
payload := strings.NewReader("{\n \"items\": [\n {\n \"display_name\": \"MCP access\",\n \"auth\": {\n \"type\": \"static_bearer\",\n \"mcp_server_url\": \"https://example.invalid/mcp\",\n \"token\": \"sk-example\"\n }\n }\n ]\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/vaults/{id}/credentials/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"display_name\": \"MCP access\",\n \"auth\": {\n \"type\": \"static_bearer\",\n \"mcp_server_url\": \"https://example.invalid/mcp\",\n \"token\": \"sk-example\"\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/vaults/{id}/credentials/batch")
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 \"items\": [\n {\n \"display_name\": \"MCP access\",\n \"auth\": {\n \"type\": \"static_bearer\",\n \"mcp_server_url\": \"https://example.invalid/mcp\",\n \"token\": \"sk-example\"\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"id": "vcrd_01h455vb4pex5vsknk084sn02q",
"vault_id": "vlt_01h455vb4pex5vsknk084sn02q",
"display_name": "MCP access",
"auth": {
"type": "static_bearer",
"mcp_server_url": "https://example.invalid/mcp"
},
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-01T00:00:00Z"
}
]
}{
"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>"
}
}请求头
本次请求使用的 API 版本,格式为 YYYY-MM-DD。发送 2026-09-01-beta 即使用本文档所述版本。/v1/files* 之外必传:未携带请求头将被拒绝并返回 400 invalid_request_error;在 /v1/files* 上缺省时选择兼容行为。所有端点对未知取值均返回 400 invalid_request_error。
平台当前支持的 API 版本。新的日期版本发布时加入;版本在公告的 Sunset 日期后移除。
可用选项:
2026-09-01-beta 路径参数
凭据库(Vault)ID。
请求体
application/json
在单个原子请求中一并创建的凭据。
本次批量创建的凭据(1–20 条),按相同顺序返回。
Required array length:
1 - 20 elementsShow child attributes
Show child attributes
响应
按请求顺序创建的凭据,秘密值不返回。
原子批量请求创建的凭据,按请求顺序排列。
按请求顺序创建的凭据。
Show child attributes
Show child attributes
此页面对您有帮助吗?
⌘I
批量创建凭据
curl --request POST \
--url https://api.moonshot.cn/v1/vaults/{id}/credentials/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"items": [
{
"display_name": "MCP access",
"auth": {
"type": "static_bearer",
"mcp_server_url": "https://example.invalid/mcp",
"token": "sk-example"
}
}
]
}
'import requests
url = "https://api.moonshot.cn/v1/vaults/{id}/credentials/batch"
payload = { "items": [
{
"display_name": "MCP access",
"auth": {
"type": "static_bearer",
"mcp_server_url": "https://example.invalid/mcp",
"token": "sk-example"
}
}
] }
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({
items: [
{
display_name: 'MCP access',
auth: {
type: 'static_bearer',
mcp_server_url: 'https://example.invalid/mcp',
token: 'sk-example'
}
}
]
})
};
fetch('https://api.moonshot.cn/v1/vaults/{id}/credentials/batch', 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/vaults/{id}/credentials/batch",
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([
'items' => [
[
'display_name' => 'MCP access',
'auth' => [
'type' => 'static_bearer',
'mcp_server_url' => 'https://example.invalid/mcp',
'token' => 'sk-example'
]
]
]
]),
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/vaults/{id}/credentials/batch"
payload := strings.NewReader("{\n \"items\": [\n {\n \"display_name\": \"MCP access\",\n \"auth\": {\n \"type\": \"static_bearer\",\n \"mcp_server_url\": \"https://example.invalid/mcp\",\n \"token\": \"sk-example\"\n }\n }\n ]\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/vaults/{id}/credentials/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"display_name\": \"MCP access\",\n \"auth\": {\n \"type\": \"static_bearer\",\n \"mcp_server_url\": \"https://example.invalid/mcp\",\n \"token\": \"sk-example\"\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/vaults/{id}/credentials/batch")
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 \"items\": [\n {\n \"display_name\": \"MCP access\",\n \"auth\": {\n \"type\": \"static_bearer\",\n \"mcp_server_url\": \"https://example.invalid/mcp\",\n \"token\": \"sk-example\"\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"items": [
{
"id": "vcrd_01h455vb4pex5vsknk084sn02q",
"vault_id": "vlt_01h455vb4pex5vsknk084sn02q",
"display_name": "MCP access",
"auth": {
"type": "static_bearer",
"mcp_server_url": "https://example.invalid/mcp"
},
"created_at": "2026-01-01T00:00:00Z",
"updated_at": "2026-01-01T00:00:00Z"
}
]
}{
"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>"
}
}