更新项目支出限额
更新项目支出限额(单位毫分)。每个字段三种语义:不传表示保持当前值;传 null 表示清除限额(不限);传数值表示设置新限额。
PATCH
/
v1
/
admin
/
organizations
/
projects
/
{pid}
/
spend_limits
设置项目支出限额
curl --request PATCH \
--url https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"daily_consume_limit": 1,
"monthly_consume_limit": 1
}
'import requests
url = "https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits"
payload = {
"daily_consume_limit": 1,
"monthly_consume_limit": 1
}
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({daily_consume_limit: 1, monthly_consume_limit: 1})
};
fetch('https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits', 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/admin/organizations/projects/{pid}/spend_limits",
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([
'daily_consume_limit' => 1,
'monthly_consume_limit' => 1
]),
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/admin/organizations/projects/{pid}/spend_limits"
payload := strings.NewReader("{\n \"daily_consume_limit\": 1,\n \"monthly_consume_limit\": 1\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.cn/v1/admin/organizations/projects/{pid}/spend_limits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"daily_consume_limit\": 1,\n \"monthly_consume_limit\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits")
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 \"daily_consume_limit\": 1,\n \"monthly_consume_limit\": 1\n}"
response = http.request(request)
puts response.read_body{
"daily_consume_limit": 1,
"monthly_consume_limit": 1
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}本接口要求 Admin Key 具备
org:write 作用域,且调用时 key 持有者仍是组织管理员(否则返回 403 owner_not_admin)。两个字段都不传(空请求体 {})会返回 400 invalid_request,请至少提供一个字段。三态字段与周期规则
- 字段省略:保持该周期当前值;
null:清除该周期预算(恢复不限);数值:设置该周期预算。 - 日/月两个周期独立设置、互不影响;响应返回两个周期的完整配置。
- 预算口径同「查询项目消费预算」页:日按 Asia/Shanghai 自然日、月按自然月重置;超出预算不阻断调用、超出部分仍计费(支出限额用于支出管理与消费占比展示,非强制刹车)。
授权
Authorization 请求头携带 Admin API secret 作为 Bearer 令牌,格式为 Bearer sk-admin-***。Admin Key 可在「控制台 → 组织管理 → Admin API Keys」创建。
路径参数
项目 ID。
请求体
application/json
响应
更新后的消费预算。
日支出限额(毫分)。按 Asia/Shanghai 自然日累计重置;超出预算不阻断调用、超出部分仍计费(预算用于支出管理与占比展示,非强制刹车)。null 表示未设置(不限),0 表示预算为 0(仅展示超支)。
必填范围:
x >= 0月支出限额(毫分)。按 Asia/Shanghai 自然月累计重置;超出预算不阻断调用、超出部分仍计费(预算用于支出管理与占比展示,非强制刹车)。null 表示未设置(不限),0 表示预算为 0(仅展示超支)。
必填范围:
x >= 0此页面对您有帮助吗?
⌘I
设置项目支出限额
curl --request PATCH \
--url https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"daily_consume_limit": 1,
"monthly_consume_limit": 1
}
'import requests
url = "https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits"
payload = {
"daily_consume_limit": 1,
"monthly_consume_limit": 1
}
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({daily_consume_limit: 1, monthly_consume_limit: 1})
};
fetch('https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits', 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/admin/organizations/projects/{pid}/spend_limits",
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([
'daily_consume_limit' => 1,
'monthly_consume_limit' => 1
]),
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/admin/organizations/projects/{pid}/spend_limits"
payload := strings.NewReader("{\n \"daily_consume_limit\": 1,\n \"monthly_consume_limit\": 1\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.cn/v1/admin/organizations/projects/{pid}/spend_limits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"daily_consume_limit\": 1,\n \"monthly_consume_limit\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/admin/organizations/projects/{pid}/spend_limits")
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 \"daily_consume_limit\": 1,\n \"monthly_consume_limit\": 1\n}"
response = http.request(request)
puts response.read_body{
"daily_consume_limit": 1,
"monthly_consume_limit": 1
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "<string>",
"request_id": "<string>",
"param": "<string>"
}
}