Skip to main content
POST
/
cost-insights
/
compare
Compare costs across periods
curl --request POST \
  --url https://api.cloudcapital.co/v1/cost-insights/compare \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "baselinePeriod": {
    "start": "2026-02-01",
    "end": "2026-02-28"
  },
  "comparisonPeriod": {
    "start": "2026-01-01",
    "end": "2026-01-31"
  },
  "metric": "amortized_cost",
  "groupBy": {
    "dimension": "service",
    "dateGrouping": "daily"
  }
}
'
import requests

url = "https://api.cloudcapital.co/v1/cost-insights/compare"

payload = {
"baselinePeriod": {
"start": "2026-02-01",
"end": "2026-02-28"
},
"comparisonPeriod": {
"start": "2026-01-01",
"end": "2026-01-31"
},
"metric": "amortized_cost",
"groupBy": {
"dimension": "service",
"dateGrouping": "daily"
}
}
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({
baselinePeriod: {start: '2026-02-01', end: '2026-02-28'},
comparisonPeriod: {start: '2026-01-01', end: '2026-01-31'},
metric: 'amortized_cost',
groupBy: {dimension: 'service', dateGrouping: 'daily'}
})
};

fetch('https://api.cloudcapital.co/v1/cost-insights/compare', 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.cloudcapital.co/v1/cost-insights/compare",
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([
'baselinePeriod' => [
'start' => '2026-02-01',
'end' => '2026-02-28'
],
'comparisonPeriod' => [
'start' => '2026-01-01',
'end' => '2026-01-31'
],
'metric' => 'amortized_cost',
'groupBy' => [
'dimension' => 'service',
'dateGrouping' => 'daily'
]
]),
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.cloudcapital.co/v1/cost-insights/compare"

payload := strings.NewReader("{\n \"baselinePeriod\": {\n \"start\": \"2026-02-01\",\n \"end\": \"2026-02-28\"\n },\n \"comparisonPeriod\": {\n \"start\": \"2026-01-01\",\n \"end\": \"2026-01-31\"\n },\n \"metric\": \"amortized_cost\",\n \"groupBy\": {\n \"dimension\": \"service\",\n \"dateGrouping\": \"daily\"\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.cloudcapital.co/v1/cost-insights/compare")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"baselinePeriod\": {\n \"start\": \"2026-02-01\",\n \"end\": \"2026-02-28\"\n },\n \"comparisonPeriod\": {\n \"start\": \"2026-01-01\",\n \"end\": \"2026-01-31\"\n },\n \"metric\": \"amortized_cost\",\n \"groupBy\": {\n \"dimension\": \"service\",\n \"dateGrouping\": \"daily\"\n }\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.cloudcapital.co/v1/cost-insights/compare")

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 \"baselinePeriod\": {\n \"start\": \"2026-02-01\",\n \"end\": \"2026-02-28\"\n },\n \"comparisonPeriod\": {\n \"start\": \"2026-01-01\",\n \"end\": \"2026-01-31\"\n },\n \"metric\": \"amortized_cost\",\n \"groupBy\": {\n \"dimension\": \"service\",\n \"dateGrouping\": \"daily\"\n }\n}"

response = http.request(request)
puts response.read_body
{
  "success": true,
  "data": {
    "comparisons": [
      {
        "dimension_value": "<string>",
        "baseline": {
          "total": 123,
          "by_date": [
            {
              "date": "<string>",
              "value": 123
            }
          ]
        },
        "comparison": {
          "total": 123,
          "by_date": [
            {
              "date": "<string>",
              "value": 123
            }
          ]
        },
        "delta": {
          "absolute": 123,
          "percentage": 123
        }
      }
    ],
    "totals": {
      "baseline": 123,
      "comparison": 123,
      "delta": {
        "absolute": 123,
        "percentage": 123
      }
    },
    "metric_totals": {
      "amortized_cost": {
        "baseline": 123,
        "comparison": 123,
        "delta": {
          "absolute": 123,
          "percentage": 123
        }
      },
      "on_demand_cost": {
        "baseline": 123,
        "comparison": 123,
        "delta": {
          "absolute": 123,
          "percentage": 123
        }
      },
      "total_savings": {
        "baseline": 123,
        "comparison": 123,
        "delta": {
          "absolute": 123,
          "percentage": 123
        }
      },
      "effective_savings_rate": {
        "baseline": 123,
        "comparison": 123,
        "delta": {
          "absolute": 123,
          "percentage": 123
        }
      }
    },
    "metadata": {
      "baseline_period": {
        "start": "2026-01-01",
        "end": "2026-03-31"
      },
      "comparison_period": {
        "start": "2026-01-01",
        "end": "2026-03-31"
      },
      "baseline_label": "<string>",
      "comparison_label": "<string>"
    }
  }
}
{
"success": false,
"error": {
"message": "Invalid request. Please see message details.. Invalid input: expected object, received undefined (at groupBy)"
}
}
{
"message": "Unauthorized"
}
{
"success": false,
"error": {
"message": "Rate limit exceeded. Please retry after the specified time."
}
}

Authorizations

Authorization
string
header
required

API key authentication. Generate an API key from your Cloud Capital dashboard under Settings > API keys. Include it in the Authorization header as a Bearer token.

Body

application/json
baselinePeriod
object
required
comparisonPeriod
object
required
metric
enum<string>
required

Metric to compare across periods

Available options:
amortized_cost,
billed_cost,
cash_cost,
on_demand_cost,
total_savings,
commitment_savings,
spot_savings,
effective_savings_rate
groupBy
object
required
filters
object

Filters for comparison (same structure as Filters but without dateRange/billingPeriods since periods are specified explicitly).

Response

Comparison data retrieved successfully

Successful HTTP responses wrap the endpoint-specific body in data. Each operation's 200 response schema is this object merged (allOf) with a data property referencing the payload schema for that endpoint.

success
enum<boolean>
required

Always true when the HTTP status is 2xx.

Available options:
true
data
object
required