Run a cost-change diff tree
curl --request POST \
--url https://api.example.com/queries/diff-tree \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"queries": [
{
"type": "cost",
"name": "<string>",
"groupBy": "<string>",
"alias": "<string>",
"filterCel": "<string>",
"metricId": "cost",
"currency": "USD",
"shiftAmount": 123
}
],
"from": "<string>",
"to": "<string>",
"aggBy": "Month",
"forecastDays": 1,
"compare": {
"enabled": true,
"from": "<string>",
"to": "<string>",
"chartType": "WATERFALL"
},
"limit": 500,
"scopeId": "<string>"
}
'import requests
url = "https://api.example.com/queries/diff-tree"
payload = {
"queries": [
{
"type": "cost",
"name": "<string>",
"groupBy": "<string>",
"alias": "<string>",
"filterCel": "<string>",
"metricId": "cost",
"currency": "USD",
"shiftAmount": 123
}
],
"from": "<string>",
"to": "<string>",
"aggBy": "Month",
"forecastDays": 1,
"compare": {
"enabled": True,
"from": "<string>",
"to": "<string>",
"chartType": "WATERFALL"
},
"limit": 500,
"scopeId": "<string>"
}
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({
queries: [
{
type: 'cost',
name: '<string>',
groupBy: '<string>',
alias: '<string>',
filterCel: '<string>',
metricId: 'cost',
currency: 'USD',
shiftAmount: 123
}
],
from: '<string>',
to: '<string>',
aggBy: 'Month',
forecastDays: 1,
compare: {enabled: true, from: '<string>', to: '<string>', chartType: 'WATERFALL'},
limit: 500,
scopeId: '<string>'
})
};
fetch('https://api.example.com/queries/diff-tree', 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.example.com/queries/diff-tree",
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([
'queries' => [
[
'type' => 'cost',
'name' => '<string>',
'groupBy' => '<string>',
'alias' => '<string>',
'filterCel' => '<string>',
'metricId' => 'cost',
'currency' => 'USD',
'shiftAmount' => 123
]
],
'from' => '<string>',
'to' => '<string>',
'aggBy' => 'Month',
'forecastDays' => 1,
'compare' => [
'enabled' => true,
'from' => '<string>',
'to' => '<string>',
'chartType' => 'WATERFALL'
],
'limit' => 500,
'scopeId' => '<string>'
]),
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.example.com/queries/diff-tree"
payload := strings.NewReader("{\n \"queries\": [\n {\n \"type\": \"cost\",\n \"name\": \"<string>\",\n \"groupBy\": \"<string>\",\n \"alias\": \"<string>\",\n \"filterCel\": \"<string>\",\n \"metricId\": \"cost\",\n \"currency\": \"USD\",\n \"shiftAmount\": 123\n }\n ],\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"aggBy\": \"Month\",\n \"forecastDays\": 1,\n \"compare\": {\n \"enabled\": true,\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"chartType\": \"WATERFALL\"\n },\n \"limit\": 500,\n \"scopeId\": \"<string>\"\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.example.com/queries/diff-tree")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"queries\": [\n {\n \"type\": \"cost\",\n \"name\": \"<string>\",\n \"groupBy\": \"<string>\",\n \"alias\": \"<string>\",\n \"filterCel\": \"<string>\",\n \"metricId\": \"cost\",\n \"currency\": \"USD\",\n \"shiftAmount\": 123\n }\n ],\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"aggBy\": \"Month\",\n \"forecastDays\": 1,\n \"compare\": {\n \"enabled\": true,\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"chartType\": \"WATERFALL\"\n },\n \"limit\": 500,\n \"scopeId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/queries/diff-tree")
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 \"queries\": [\n {\n \"type\": \"cost\",\n \"name\": \"<string>\",\n \"groupBy\": \"<string>\",\n \"alias\": \"<string>\",\n \"filterCel\": \"<string>\",\n \"metricId\": \"cost\",\n \"currency\": \"USD\",\n \"shiftAmount\": 123\n }\n ],\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"aggBy\": \"Month\",\n \"forecastDays\": 1,\n \"compare\": {\n \"enabled\": true,\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"chartType\": \"WATERFALL\"\n },\n \"limit\": 500,\n \"scopeId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body[
{
"dimensions": [
{
"key": "<string>",
"value": "<string>"
}
],
"cost": 123,
"previous_cost": 123,
"diff": 123
}
]{
"error": "INVALID_QUERY",
"reason": "<string>",
"details": [
{
"path": [
"<string>"
],
"message": "<string>",
"code": "<string>"
}
]
}{
"error": "<string>"
}{
"error": "SCOPE_NOT_FOUND_OR_FORBIDDEN"
}{
"error": "INTERNAL_SERVER_ERROR"
}Query Costs
Run a cost-change diff tree
Returns a GROUP BY ROLLUP tree of current vs previous cost per node for exactly one cost or usage series. Requires an enabled comparison period, a non-hourly aggBy, and at least one groupBy axis on that series. Pre-condition failures return 400 INVALID_QUERY with today’s message in reason. There is no Hour entitlement gate — hourly is rejected for every organization.
POST
/
queries
/
diff-tree
Run a cost-change diff tree
curl --request POST \
--url https://api.example.com/queries/diff-tree \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"queries": [
{
"type": "cost",
"name": "<string>",
"groupBy": "<string>",
"alias": "<string>",
"filterCel": "<string>",
"metricId": "cost",
"currency": "USD",
"shiftAmount": 123
}
],
"from": "<string>",
"to": "<string>",
"aggBy": "Month",
"forecastDays": 1,
"compare": {
"enabled": true,
"from": "<string>",
"to": "<string>",
"chartType": "WATERFALL"
},
"limit": 500,
"scopeId": "<string>"
}
'import requests
url = "https://api.example.com/queries/diff-tree"
payload = {
"queries": [
{
"type": "cost",
"name": "<string>",
"groupBy": "<string>",
"alias": "<string>",
"filterCel": "<string>",
"metricId": "cost",
"currency": "USD",
"shiftAmount": 123
}
],
"from": "<string>",
"to": "<string>",
"aggBy": "Month",
"forecastDays": 1,
"compare": {
"enabled": True,
"from": "<string>",
"to": "<string>",
"chartType": "WATERFALL"
},
"limit": 500,
"scopeId": "<string>"
}
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({
queries: [
{
type: 'cost',
name: '<string>',
groupBy: '<string>',
alias: '<string>',
filterCel: '<string>',
metricId: 'cost',
currency: 'USD',
shiftAmount: 123
}
],
from: '<string>',
to: '<string>',
aggBy: 'Month',
forecastDays: 1,
compare: {enabled: true, from: '<string>', to: '<string>', chartType: 'WATERFALL'},
limit: 500,
scopeId: '<string>'
})
};
fetch('https://api.example.com/queries/diff-tree', 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.example.com/queries/diff-tree",
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([
'queries' => [
[
'type' => 'cost',
'name' => '<string>',
'groupBy' => '<string>',
'alias' => '<string>',
'filterCel' => '<string>',
'metricId' => 'cost',
'currency' => 'USD',
'shiftAmount' => 123
]
],
'from' => '<string>',
'to' => '<string>',
'aggBy' => 'Month',
'forecastDays' => 1,
'compare' => [
'enabled' => true,
'from' => '<string>',
'to' => '<string>',
'chartType' => 'WATERFALL'
],
'limit' => 500,
'scopeId' => '<string>'
]),
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.example.com/queries/diff-tree"
payload := strings.NewReader("{\n \"queries\": [\n {\n \"type\": \"cost\",\n \"name\": \"<string>\",\n \"groupBy\": \"<string>\",\n \"alias\": \"<string>\",\n \"filterCel\": \"<string>\",\n \"metricId\": \"cost\",\n \"currency\": \"USD\",\n \"shiftAmount\": 123\n }\n ],\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"aggBy\": \"Month\",\n \"forecastDays\": 1,\n \"compare\": {\n \"enabled\": true,\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"chartType\": \"WATERFALL\"\n },\n \"limit\": 500,\n \"scopeId\": \"<string>\"\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.example.com/queries/diff-tree")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"queries\": [\n {\n \"type\": \"cost\",\n \"name\": \"<string>\",\n \"groupBy\": \"<string>\",\n \"alias\": \"<string>\",\n \"filterCel\": \"<string>\",\n \"metricId\": \"cost\",\n \"currency\": \"USD\",\n \"shiftAmount\": 123\n }\n ],\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"aggBy\": \"Month\",\n \"forecastDays\": 1,\n \"compare\": {\n \"enabled\": true,\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"chartType\": \"WATERFALL\"\n },\n \"limit\": 500,\n \"scopeId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/queries/diff-tree")
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 \"queries\": [\n {\n \"type\": \"cost\",\n \"name\": \"<string>\",\n \"groupBy\": \"<string>\",\n \"alias\": \"<string>\",\n \"filterCel\": \"<string>\",\n \"metricId\": \"cost\",\n \"currency\": \"USD\",\n \"shiftAmount\": 123\n }\n ],\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"aggBy\": \"Month\",\n \"forecastDays\": 1,\n \"compare\": {\n \"enabled\": true,\n \"from\": \"<string>\",\n \"to\": \"<string>\",\n \"chartType\": \"WATERFALL\"\n },\n \"limit\": 500,\n \"scopeId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body[
{
"dimensions": [
{
"key": "<string>",
"value": "<string>"
}
],
"cost": 123,
"previous_cost": 123,
"diff": 123
}
]{
"error": "INVALID_QUERY",
"reason": "<string>",
"details": [
{
"path": [
"<string>"
],
"message": "<string>",
"code": "<string>"
}
]
}{
"error": "<string>"
}{
"error": "SCOPE_NOT_FOUND_OR_FORBIDDEN"
}{
"error": "INTERNAL_SERVER_ERROR"
}Authorizations
Send Authorization: Bearer <credential> using either a Clerk session JWT or a Clerk API key (ak_*). API keys may identify a user (user_*) or organization (org_*) principal and are generated in the Clerk Dashboard under API keys.
Body
application/json
Required array length:
1 - 26 elements- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
Show child attributes
Show child attributes
Available options:
TRAILING_90_DAYS, TRAILING_30_DAYS, TRAILING_45_DAYS, TRAILING_7_DAYS, TRAILING_3_DAYS, TRAILING_14_WEEKS, MTD, QTD, YTD, LAST_WEEK, LAST_MONTH, LAST_6_MONTHS, LAST_12_MONTHS, LAST_4_YEARS, LAST_3_MONTHS, LAST_INVOICE_MONTH Pattern:
^\d{4}-\d{2}-\d{2}$Pattern:
^\d{4}-\d{2}-\d{2}$Available options:
Hour, Day, Week, Month, Period Required range:
x >= 0Show child attributes
Show child attributes
Required range:
1 <= x <= 1000Last modified on August 10, 2026
Was this page helpful?
⌘I
