Skip to main content

usage_costs

Creates, updates, deletes, gets or lists a usage_costs resource.

Overview

Nameusage_costs
TypeResource
Idclickhouse.organizations.usage_costs

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
data_warehouse_idstring (uuid)ID of the dataWarehouse this entity belongs to (or is). (wire: dataWarehouseId)
entity_idstring (uuid)Unique ID of the entity. (wire: entityId)
service_idstring (uuid)ID of the service this entity belongs to (or is). Set to null for dataWarehouse entities. (wire: serviceId)
entity_namestringName of the entity. (wire: entityName)
datestring (date)Date of the usage. ISO-8601 date, based on the UTC timezone.
entity_typestringType of the entity. (datawarehouse, service, clickpipe) (wire: entityType)
lockedbooleanWhen true, the record is immutable. Unlocked records are subject to change until locked.
metricsobject
total_chcnumberTotal cost of usage in ClickHouse Credits (CHCs) for this entity. (wire: totalCHC)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectfrom_date, to_date, organization_idfilterReturns a grand total and a list of daily, per-entity organization usage cost records for the organization in the queried time period (maximum 31 days). All days in both the request and the response are evaluated based on the UTC timezone.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
from_datestring (date)Start date for the report, e.g. 2024-12-19.
organization_idstringClickHouse Cloud organization ID. Resolved from the CLICKHOUSE_ORG_ID environment variable when it is set (x-stackQL-envVar); otherwise it must be supplied on every query as WHERE organization_id = <uuid>. A WHERE value always takes precedence over the environment. (x-stackQL-envVar: CLICKHOUSE_ORG_ID)
to_datestring (date)End date (inclusive) for the report, e.g. 2024-12-20. This date cannot be more than 30 days after from_date (for a maximum queried period of 31 days).
filterarrayFilter criteria to apply when retrieving the usage cost report. Currently, only filtering by resource tags is supported. (example: [tag:Environment=Production, tag:Department=Engineering, tag:isActive])

SELECT examples

Returns a grand total and a list of daily, per-entity organization usage cost records for the organization in the queried time period (maximum 31 days). All days in both the request and the response are evaluated based on the UTC timezone.

SELECT
data_warehouse_id,
entity_id,
service_id,
entity_name,
date,
entity_type,
locked,
metrics,
total_chc
FROM clickhouse.organizations.usage_costs
WHERE from_date = '{{ from_date }}' -- required
AND to_date = '{{ to_date }}' -- required
AND organization_id = '{{ organization_id }}' -- required unless CLICKHOUSE_ORG_ID is set
AND filter = '{{ filter }}'
;