Resources

Spending

Overview

The Spending resource provides visibility into current cloud costs. You can retrieve aggregate summaries, daily and monthly cost breakdowns, and detailed per-service spending in multiple formats (table, chart, CSV, raw).

Methods

Get Spending Summary

Returns an overall spending summary including total costs, forecast, savings, and a breakdown by provider.

summary = client.costs.get_summary()

List Spending

Returns a cost breakdown in one of four formats: table (paginated), chart (aggregated for stacked bar charts), csv (export), or raw (all records).

breakdown = client.costs.list(
    format="table",
    period="2025-03",
    provider_id="aws",
    page=1,
    page_size=50,
    sort_by="cost",
    sort_order="desc",
)

Parameters

ParameterTypeDescription
formatstringResponse format: table, chart, csv, raw
periodstringPeriod in YYYY-MM format (defaults to current month)
provider_idstringFilter by provider: aws, gcp, azure, k8s
granularitystringdaily or monthly (for chart format)
group_bystringGrouping dimension: provider or account_id
startstringStart date (ISO 8601)
endstringEnd date (ISO 8601)
pageintPage number (table format only)
page_sizeintItems per page, max 100 (table format only)
sort_bystringSort field: cost, service, region, account_id, change_percentage
sort_orderstringasc or desc

Get Daily Costs

Returns spending aggregated per day for a given date range.

daily = client.costs.get_daily_costs(
    start="2025-03-01T00:00:00.000Z",
    end="2025-03-31T00:00:00.000Z",
)

Get Monthly Costs

Returns spending aggregated per month across all time.

monthly = client.costs.get_monthly_costs()

Example: Export Spending to CSV

from levelfour import LevelFour

client = LevelFour()

csv_data = client.costs.list(
    format="csv",
    start="2025-01-01T00:00:00.000Z",
    end="2025-03-31T00:00:00.000Z",
)
print(csv_data)