Create a budget
Creates a budget over a saved cost filter (the same key:value filters as the cost query, virtual tags included) for the current month, quarter or year in UTC. Alerts go to the organization owners and the listed owners when spend crosses each threshold percent, and once when the forecast goes over budget if forecastAlert is on. Thresholds default to 50, 80 and 100; basis defaults to gross (before credits). The currency must match the currency the scope is billed in. enforce (off by default) makes AutoPilot for sandboxes refuse to start sandboxes while the budget is over for the period: a budget with no filters covers every sandbox, and one filtered by provider covers sandboxes on those providers. Only those two kinds can enforce. The budget counts as over from the daily evaluation that finds spend at 100% or more, which also sends the 100% alert, until an evaluation finds it back under 95%.
curl --request POST \
--url https://api.costgraph.ai/api/v1/tenant/budgets \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--header 'X-CostGraph-Tenant-ID: <x-costgraph-tenant-id>' \
--data '
{
"amount": 123,
"currency": "<string>",
"name": "<string>",
"enforce": true,
"filters": [
"<string>"
],
"forecastAlert": true,
"ownerUserIds": [
"<string>"
],
"thresholds": [
123
]
}
'import requests
url = "https://api.costgraph.ai/api/v1/tenant/budgets"
payload = {
"amount": 123,
"currency": "<string>",
"name": "<string>",
"enforce": True,
"filters": ["<string>"],
"forecastAlert": True,
"ownerUserIds": ["<string>"],
"thresholds": [123]
}
headers = {
"X-CostGraph-Tenant-ID": "<x-costgraph-tenant-id>",
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-CostGraph-Tenant-ID': '<x-costgraph-tenant-id>',
Authorization: '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 123,
currency: '<string>',
name: '<string>',
enforce: true,
filters: ['<string>'],
forecastAlert: true,
ownerUserIds: ['<string>'],
thresholds: [123]
})
};
fetch('https://api.costgraph.ai/api/v1/tenant/budgets', 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.costgraph.ai/api/v1/tenant/budgets",
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([
'amount' => 123,
'currency' => '<string>',
'name' => '<string>',
'enforce' => true,
'filters' => [
'<string>'
],
'forecastAlert' => true,
'ownerUserIds' => [
'<string>'
],
'thresholds' => [
123
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json",
"X-CostGraph-Tenant-ID: <x-costgraph-tenant-id>"
],
]);
$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.costgraph.ai/api/v1/tenant/budgets"
payload := strings.NewReader("{\n \"amount\": 123,\n \"currency\": \"<string>\",\n \"name\": \"<string>\",\n \"enforce\": true,\n \"filters\": [\n \"<string>\"\n ],\n \"forecastAlert\": true,\n \"ownerUserIds\": [\n \"<string>\"\n ],\n \"thresholds\": [\n 123\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-CostGraph-Tenant-ID", "<x-costgraph-tenant-id>")
req.Header.Add("Authorization", "<api-key>")
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.costgraph.ai/api/v1/tenant/budgets")
.header("X-CostGraph-Tenant-ID", "<x-costgraph-tenant-id>")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": 123,\n \"currency\": \"<string>\",\n \"name\": \"<string>\",\n \"enforce\": true,\n \"filters\": [\n \"<string>\"\n ],\n \"forecastAlert\": true,\n \"ownerUserIds\": [\n \"<string>\"\n ],\n \"thresholds\": [\n 123\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.costgraph.ai/api/v1/tenant/budgets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-CostGraph-Tenant-ID"] = '<x-costgraph-tenant-id>'
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": 123,\n \"currency\": \"<string>\",\n \"name\": \"<string>\",\n \"enforce\": true,\n \"filters\": [\n \"<string>\"\n ],\n \"forecastAlert\": true,\n \"ownerUserIds\": [\n \"<string>\"\n ],\n \"thresholds\": [\n 123\n ]\n}"
response = http.request(request)
puts response.read_body{
"message": "some message",
"status": "success",
"data": {
"amount": 123,
"basis": "gross",
"createdAt": "<string>",
"currency": "<string>",
"enforce": true,
"evaluation": {
"actual": 123,
"excludedCurrencies": [
"<string>"
],
"forecast": {
"method": "regression",
"pctOfBudget": 123,
"point": 123,
"reason": "<string>"
},
"pctUsed": 123,
"periodEnd": "<string>",
"periodStart": "<string>",
"status": "on_track"
},
"filters": [
"<string>"
],
"forecastAlert": true,
"id": "<string>",
"layer": "billed",
"name": "<string>",
"ownerUserIds": [
"<string>"
],
"period": "monthly",
"thresholds": [
123
],
"updatedAt": "<string>"
}
}{
"message": "some message",
"status": "error"
}{
"code": "subscription_required",
"message": "some message",
"status": "error"
}{
"message": "some message",
"status": "error"
}Body
Budget
Was this page helpful?
curl --request POST \
--url https://api.costgraph.ai/api/v1/tenant/budgets \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--header 'X-CostGraph-Tenant-ID: <x-costgraph-tenant-id>' \
--data '
{
"amount": 123,
"currency": "<string>",
"name": "<string>",
"enforce": true,
"filters": [
"<string>"
],
"forecastAlert": true,
"ownerUserIds": [
"<string>"
],
"thresholds": [
123
]
}
'import requests
url = "https://api.costgraph.ai/api/v1/tenant/budgets"
payload = {
"amount": 123,
"currency": "<string>",
"name": "<string>",
"enforce": True,
"filters": ["<string>"],
"forecastAlert": True,
"ownerUserIds": ["<string>"],
"thresholds": [123]
}
headers = {
"X-CostGraph-Tenant-ID": "<x-costgraph-tenant-id>",
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-CostGraph-Tenant-ID': '<x-costgraph-tenant-id>',
Authorization: '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 123,
currency: '<string>',
name: '<string>',
enforce: true,
filters: ['<string>'],
forecastAlert: true,
ownerUserIds: ['<string>'],
thresholds: [123]
})
};
fetch('https://api.costgraph.ai/api/v1/tenant/budgets', 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.costgraph.ai/api/v1/tenant/budgets",
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([
'amount' => 123,
'currency' => '<string>',
'name' => '<string>',
'enforce' => true,
'filters' => [
'<string>'
],
'forecastAlert' => true,
'ownerUserIds' => [
'<string>'
],
'thresholds' => [
123
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json",
"X-CostGraph-Tenant-ID: <x-costgraph-tenant-id>"
],
]);
$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.costgraph.ai/api/v1/tenant/budgets"
payload := strings.NewReader("{\n \"amount\": 123,\n \"currency\": \"<string>\",\n \"name\": \"<string>\",\n \"enforce\": true,\n \"filters\": [\n \"<string>\"\n ],\n \"forecastAlert\": true,\n \"ownerUserIds\": [\n \"<string>\"\n ],\n \"thresholds\": [\n 123\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-CostGraph-Tenant-ID", "<x-costgraph-tenant-id>")
req.Header.Add("Authorization", "<api-key>")
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.costgraph.ai/api/v1/tenant/budgets")
.header("X-CostGraph-Tenant-ID", "<x-costgraph-tenant-id>")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"amount\": 123,\n \"currency\": \"<string>\",\n \"name\": \"<string>\",\n \"enforce\": true,\n \"filters\": [\n \"<string>\"\n ],\n \"forecastAlert\": true,\n \"ownerUserIds\": [\n \"<string>\"\n ],\n \"thresholds\": [\n 123\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.costgraph.ai/api/v1/tenant/budgets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-CostGraph-Tenant-ID"] = '<x-costgraph-tenant-id>'
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"amount\": 123,\n \"currency\": \"<string>\",\n \"name\": \"<string>\",\n \"enforce\": true,\n \"filters\": [\n \"<string>\"\n ],\n \"forecastAlert\": true,\n \"ownerUserIds\": [\n \"<string>\"\n ],\n \"thresholds\": [\n 123\n ]\n}"
response = http.request(request)
puts response.read_body{
"message": "some message",
"status": "success",
"data": {
"amount": 123,
"basis": "gross",
"createdAt": "<string>",
"currency": "<string>",
"enforce": true,
"evaluation": {
"actual": 123,
"excludedCurrencies": [
"<string>"
],
"forecast": {
"method": "regression",
"pctOfBudget": 123,
"point": 123,
"reason": "<string>"
},
"pctUsed": 123,
"periodEnd": "<string>",
"periodStart": "<string>",
"status": "on_track"
},
"filters": [
"<string>"
],
"forecastAlert": true,
"id": "<string>",
"layer": "billed",
"name": "<string>",
"ownerUserIds": [
"<string>"
],
"period": "monthly",
"thresholds": [
123
],
"updatedAt": "<string>"
}
}{
"message": "some message",
"status": "error"
}{
"code": "subscription_required",
"message": "some message",
"status": "error"
}{
"message": "some message",
"status": "error"
}