/consumption_history/v2/programsRetrieve program consumption metrics
Returns consumption metrics for up to limit programs per page. If program_ids is omitted,
projects in the organization are included across pages (use cursor). If program_ids is
provided, the response is limited to those programs (up to 100). Available for accounts on
Launch, Scale, Agent, Business, and Enterprise plans.
History starts when the account upgrades to an eligible plan.
The metrics query parameter is required. Supported values:
compute_unit_seconds, root_branch_bytes_month, child_branch_bytes_month,
instant_restore_bytes_month, public_network_transfer_bytes, private_network_transfer_bytes,
extra_branches_month, snapshot_storage_bytes_month.
Consumption metrics within each program are returned in ascending time order (oldest first). This request does not wake program computes.
Quick start
curl "https://api.optitech.com/v1/consumption_history/v2/programs?from=$FROM&to=$TO&granularity=$GRANULARITY&org_id=$ORG_ID&metrics=$METRICS" \
-H "Authorization: Bearer $OPTITECH_API_KEY"Every field below is optional. An empty body works too.
import { createOptiTechClient, raw } from '@optitech/sdk';
const optitech = createOptiTechClient({ apiKey: process.env.OPTITECH_API_KEY });
const { data } = await raw.getConsumptionHistoryPerProjectV2({
client: optitech.client,
query: {
from: process.env.FROM,
to: process.env.TO,
granularity: process.env.GRANULARITY,
org_id: process.env.ORG_ID,
metrics: process.env.METRICS
}
});Parameters
cursorCursor from the previous response (pagination.cursor). Pass it to fetch the next page
of programs. Pages are ordered by program creation order (newest first).
limitMaximum number of programs per page. Allowed range: 1 to 100. Default: 10.
program_idsOptional program IDs to filter the response (up to 100). If omitted, programs in the
organization are included across pages (use cursor and limit).
Pass multiple IDs as repeated query parameters or a comma-separated list:
program_ids=cold-poetry-09157238&program_ids=quiet-snow-71788278program_ids=cold-poetry-09157238,quiet-snow-71788278
fromSpecify the start date-time for the consumption period.
The date-time value is rounded according to the specified granularity.
For example, 2024-03-15T15:30:00Z for daily granularity will be rounded to 2024-03-15T00:00:00Z.
The specified date-time value must respect the specified granularity:
- For
hourly, consumption metrics are limited to the last 168 hours. - For
daily, consumption metrics are limited to the last 60 days. - For
monthly, consumption metrics are limited to the last year.
The earliest allowed from value is March 1, 2024, at 00:00:00 UTC.
Metrics are returned from when the account upgraded to an eligible plan, which may be
later than that date.
toSpecify the end date-time for the consumption period.
The date-time value is rounded according to the specified granularity.
For example, 2024-03-15T15:30:00Z for daily granularity will be rounded to 2024-03-15T00:00:00Z.
The specified date-time value must respect the specified granularity:
- For
hourly, consumption metrics are limited to the last 168 hours. - For
daily, consumption metrics are limited to the last 60 days. - For
monthly, consumption metrics are limited to the last year.
granularitySpecify the granularity of consumption metrics. Hourly, daily, and monthly metrics are available for the last 168 hours, 60 days, and 1 year, respectively.
org_idOrganization ID. Metrics are returned for programs in this organization.
metricsRequired. List the metrics to return. Supported values:
compute_unit_secondsroot_branch_bytes_monthchild_branch_bytes_monthinstant_restore_bytes_monthpublic_network_transfer_bytesprivate_network_transfer_bytesextra_branches_monthsnapshot_storage_bytes_month
Pass multiple values as repeated query parameters or a comma-separated list:
metrics=compute_unit_seconds&metrics=extra_branches_monthmetrics=compute_unit_seconds,extra_branches_month
Response
200Program consumption metrics for the OptiTech account.
Errors
Not available for this account. Program consumption history requires a Launch, Scale, Agent, Business, or Enterprise plan.
Account is not a member of the organization specified by org_id.
The from and to range is not valid for the selected granularity. Adjust the range or
choose a different granularity.
Too many requests
General error
This endpoint can return the standard OptiTech API error response.
Response fields
messageRequired. Human-readable error message.codeRequired. Machine-readable error code.request_idOptional. Request identifier for debugging. You can provide one with theX-Request-IDheader.
Retry guidance
If no response is returned, the request may still have reached the server. This is why retry safety depends on the method and status code.
Idempotent methods (GET, HEAD, OPTIONS) are generally safe to retry after a network error or timeout. Non-idempotent methods (POST, PATCH, DELETE, PUT) can change state, so avoid automatic retries unless your workflow can tolerate duplicate effects.
Responses with 423 Locked or 503 Service Unavailable are safe to retry. 423 Locked means the resource is temporarily locked, usually because another operation is in progress.