Update project spend limit
Update project consume limits in milli-cent. Each field has three semantics: omitted keeps the current value; null clears the limit (unlimited); a number sets a new limit.
curl --request PATCH \
--url https://api.moonshot.ai/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.ai/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.ai/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.ai/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.ai/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.ai/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.ai/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>"
}
}org:write scope, and the key owner must still be an organization admin at call time (otherwise 403 owner_not_admin).Sending neither field (empty body {}) returns 400 invalid_request; provide at least one field.Tri-state fields and period rules
- Omitted field: keeps the current value for that period;
null: clears that period’s budget (back to unlimited); a number: sets that period’s budget. - Daily and monthly periods are configured independently and do not affect each other; the response returns the complete configuration for both periods.
- Budget semantics match “Get project spend limit”: daily resets at Asia/Shanghai day boundaries and monthly at month boundaries; exceeding the budget does not block API calls and usage beyond the budget is still billed (budgets are for spend management and usage-ratio display, not a hard stop).
Authorizations
Send the Admin API secret as a Bearer token in the Authorization header (Bearer sk-admin-***). Create Admin Keys under Console → Organization → Admin API Keys.
Path Parameters
Project ID.
Body
At least one field must be present.
Daily spend limit (milli-cent). Omit to keep the current value, null to clear the limit (unlimited), or a number to set it.
x >= 0Monthly spend limit (milli-cent). Omit to keep the current value, null to clear the limit (unlimited), or a number to set it.
x >= 0Response
Updated spend limit.
Daily consume limit (milli-cent). Accumulates and resets at Asia/Shanghai day boundaries; exceeding the budget does not block API calls and usage beyond it is still billed (spend management and usage-ratio display, not a hard stop). Null means not configured (unlimited); 0 means a zero budget (over-budget display only).
x >= 0Monthly consume limit (milli-cent). Accumulates and resets at Asia/Shanghai month boundaries; exceeding the budget does not block API calls and usage beyond it is still billed (spend management and usage-ratio display, not a hard stop). Null means not configured (unlimited); 0 means a zero budget (over-budget display only).
x >= 0Was this page helpful?
curl --request PATCH \
--url https://api.moonshot.ai/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.ai/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.ai/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.ai/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.ai/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.ai/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.ai/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>"
}
}