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
| Parameter | Type | Description |
|---|---|---|
format | string | Response format: table, chart, csv, raw |
period | string | Period in YYYY-MM format (defaults to current month) |
provider_id | string | Filter by provider: aws, gcp, azure, k8s |
granularity | string | daily or monthly (for chart format) |
group_by | string | Grouping dimension: provider or account_id |
start | string | Start date (ISO 8601) |
end | string | End date (ISO 8601) |
page | int | Page number (table format only) |
page_size | int | Items per page, max 100 (table format only) |
sort_by | string | Sort field: cost, service, region, account_id, change_percentage |
sort_order | string | asc 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)