Costs
Overview
The Costs resource provides visibility into current cloud costs. You can retrieve aggregate summaries, daily and monthly cost breakdowns, per-provider cost views with filtering and pagination, and detailed per-service costs in multiple formats (table, chart, CSV, raw).
Methods
Get Cost Summary
Returns an overall cost summary including total costs, forecast, savings, and a breakdown by provider.
summary = client.costs.get_summary()List Costs
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="2026-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 costs aggregated per day for a given date range.
daily = client.costs.get_daily_costs(
start="2026-03-01T00:00:00.000Z",
end="2026-03-31T00:00:00.000Z",
)Get Monthly Costs
Returns costs aggregated per month across all time.
monthly = client.costs.get_monthly_costs()Get Provider Summary
Returns a per-provider cost summary with monthly costs, forecast, potential savings, and the top 3 services for that provider.
summary = client.costs.get_provider_summary("aws")List By Provider
Returns a paginated per-provider cost breakdown with filtering by service, region, account, environment, and tag. Supports multi-dimension grouping (service, account_id, region, tag), daily/monthly granularity, and date presets. Each row includes previous-period cost and change percentage; the response includes per-date totals across all pages.
breakdown = client.costs.list_by_provider(
"aws",
preset="30D",
granularity="daily",
group_by=["service", "region"],
service=["EC2", "RDS"],
region=["us-east-1"],
page=1,
page_size=20,
sort_by="cost",
sort_order="desc",
)Parameters
| Parameter | Type | Description |
|---|---|---|
format | string | table, chart, csv, or raw (defaults to table) |
start | string | Start date (ISO 8601) |
end | string | End date (ISO 8601) |
preset | string | Date preset: 30D, 6M, or 12M (overrides start/end) |
granularity | string | daily or monthly |
page | int | Page number (1-indexed) |
page_size | int | Items per page (max 100) |
sort_by | string | Sort field: service, environment, region, account_id, cost, previous_cost, change_percentage |
sort_by_date | string | Sort by a specific date column (YYYY-MM-DD or YYYY-MM, overrides sort_by) |
sort_order | string | asc or desc |
group_by | string[] | Multi-dimension grouping: service, account_id, region, tag |
service | string[] | Filter by service |
environment | string[] | Filter by environment |
account_id | string[] | Filter by account ID |
region | string[] | Filter by region |
tag_key | string[] | Filter by tag key (required when group_by includes tag) |
tag_value | string[] | Filter by tag value |
For ready-to-run filter recipes using these parameters, see Filtering and sorting. That guide covers week-over-week cost analysis, multi-dimension grouping, CSV export pipelines, and the full --jq expression surface.
Get Provider Filters
Returns distinct values available for filtering the per-provider cost breakdown (services, regions, accounts, tag keys, tag values) within a date range. Useful for populating autocomplete UIs or validating user-supplied filter values before querying.
filters = client.costs.get_provider_filters(
"aws",
start="2026-01-01T00:00:00.000Z",
end="2026-01-31T00:00:00.000Z",
)Get Provider Timeline
Returns a per-provider cost timeline at the requested granularity. Useful for rendering trend charts of a specific provider's cost over time.
timeline = client.costs.get_provider_timeline(
"aws",
start="2026-01-01T00:00:00.000Z",
end="2026-03-31T00:00:00.000Z",
granularity="daily",
)Example: Export Costs to CSV
from levelfour import LevelFour
client = LevelFour()
csv_data = client.costs.list(
format="csv",
start="2026-01-01T00:00:00.000Z",
end="2026-03-31T00:00:00.000Z",
)
print(csv_data)