Neon is expanding into a backend: Object Storage, Functions, and AI Gateway now in beta
/APIs & SDKs/Consumption/Retrieve branch consumption metrics
GET/consumption_history/v2/branchesbeta

Retrieve branch consumption metrics

Returns consumption metrics for each branch across one or more projects listed in project_ids (1 to 100 projects). Available for accounts on paid usage-based Launch, Scale, Agent, and Enterprise plans.

History starts when the account first ingests branch-level consumption data.

The metrics query parameter is required. Only these six values are supported on this endpoint: compute_unit_seconds, root_branch_bytes_month, child_branch_bytes_month, instant_restore_bytes_month, public_network_transfer_bytes, private_network_transfer_bytes.

This endpoint does not support extra_branches_month or snapshot_storage_bytes_month. Use GET /consumption_history/v2/projects for those.

Consumption metrics within each branch are returned in ascending time order (oldest first). This request does not wake project computes.

Markdown for AI context

Quick start

REST API - curl
curl "https://console.neon.tech/api/v2/consumption_history/v2/branches?project_ids=$PROJECT_IDS&from=$FROM&to=$TO&granularity=$GRANULARITY&org_id=$ORG_ID&metrics=$METRICS" \
  -H "Authorization: Bearer $NEON_API_KEY"

Every field below is optional. An empty body works too.

Also available in
import { createNeonClient, raw } from '@neon/sdk';

const neon = createNeonClient({ apiKey: process.env.NEON_API_KEY });
const { data } = await raw.getConsumptionHistoryPerBranchV2({
  client: neon.client,
  query: {
    project_ids: process.env.PROJECT_IDS,
    from: process.env.FROM,
    to: process.env.TO,
    granularity: process.env.GRANULARITY,
    org_id: process.env.ORG_ID,
    metrics: process.env.METRICS
  }
});

Parameters

Cursor
cursor
string

Cursor from the previous response (pagination.cursor). Pass it to fetch the next page of branches. Pages are ordered by project ID, then branch ID.

Limit
limit
integerdefault: 100

Maximum number of branches per page. Allowed range: 1 to 1000. Default: 100.

Project IDs
project_ids
array

Project IDs to include (required, 1 to 100). Returns metrics for branches in these projects.

Pass multiple IDs as repeated query parameters or a comma-separated list:

  • project_ids=cold-poetry-09157238&project_ids=quiet-snow-71788278
  • project_ids=cold-poetry-09157238,quiet-snow-71788278
Branch IDs
branch_ids
array

Optional branch IDs to filter the response (up to 100). If omitted, all branches in the listed projects are included.

Pass multiple IDs as repeated query parameters or a comma-separated list:

  • branch_ids=br-aged-salad-637688&branch_ids=br-sweet-breeze-497520
  • branch_ids=br-aged-salad-637688,br-sweet-breeze-497520
From
from
string

Specify 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.

Branch-level metrics are returned from when the account first ingests branch-level consumption data. Periods before that time contain no branch metrics.

To
to
string

Specify 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.
Granularity
granularity
string

Specify the granularity of consumption metrics. Hourly, daily, and monthly metrics are available for the last 168 hours, 60 days, and 1 year, respectively.

Organization
org_id
string

Organization ID. Metrics are returned for projects in this organization.

Metrics
metrics
array

Required. List the metrics to return. Only these values are supported:

  • compute_unit_seconds
  • root_branch_bytes_month
  • child_branch_bytes_month
  • instant_restore_bytes_month
  • public_network_transfer_bytes
  • private_network_transfer_bytes

Not supported on this endpoint: extra_branches_month, snapshot_storage_bytes_month. Use GET /consumption_history/v2/projects for those.

Pass multiple values as repeated query parameters or a comma-separated list:

  • metrics=compute_unit_seconds&metrics=public_network_transfer_bytes
  • metrics=compute_unit_seconds,public_network_transfer_bytes

Response

200

Branch consumption metrics for the Neon account.

Depth

Errors

403

Not available for this account. Branch consumption history requires a paid usage-based Launch, Scale, Agent, or Enterprise plan.

404

Account is not a member of the organization specified by org_id.

406

The from and to range is not valid for the selected granularity. Adjust the range or choose a different granularity.

429

Too many requests

default

General error

This endpoint can return the standard Neon API error response.

Response fields

  • message Required. Human-readable error message.
  • code Required. Machine-readable error code.
  • request_id Optional. Request identifier for debugging. You can provide one with the X-Request-ID header.

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.

Was this page helpful?

On this page

Copy neon init command