批量创建凭据
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: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>"
}
}以原子方式创建 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: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>"
}
}此页面对您有帮助吗?