> ## Documentation Index
> Fetch the complete documentation index at: https://getlago.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Clone Google BigQuery pricing

> Rebuild BigQuery's pay-as-you-go pricing in Lago with a metered product, a graduated rate with a free first tier and a contract.

This template builds pay-as-you-go billing like Google BigQuery with Lago: no platform fee, a free first tier, then a price per unit of data processed. It suits data and infrastructure companies that charge on volume processed.

Legacy (v1): [Clone Google BigQuery pricing with subscriptions](https://getlago.com/docs/templates/payg/bigquery.md).

## Pricing structure

| Plan | Cost per volume of data scanned |
| - | - |
| On-demand pricing | \$6.25 per TiB scanned |

This template makes the first 10 TiB of each month free.

## How it maps to Lago

| Pricing element | Lago object |
| - | - |
| Data processed, in TiB | Billable metric `data_processed` (`sum_agg` on `data_processed_volume`) |
| What you sell | Metered product `bigquery_on_demand` |
| Free tier, then \$6.25 per TiB | Rate card `bigquery_on_demand_usd` with a `graduated` rate |
| The offer | Plan `bigquery_payg` |

## Get started

**1. Set up Lago**

```bash cURL theme={"dark"}
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
```

Use `https://api.eu.getlago.com` for the EU cluster. API endpoints live under `/api/v2` and require the product catalog to be enabled on your organization.

**2. Create a billable metric**

```bash cURL highlight={6,8-10} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/billable_metrics" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "billable_metric": {
      "name": "Data processed",
      "code": "data_processed",
      "description": "Data processed in TiB",
      "aggregation_type": "sum_agg",
      "field_name": "data_processed_volume",
      "recurring": false
    }
  }'
```

Refer to the [API reference](https://getlago.com/docs/v2/api-reference/billable-metrics/create.md).

**3. Create a metered product**

```bash cURL highlight={7-8} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/products" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "product": {
      "name": "BigQuery on-demand",
      "code": "bigquery_on_demand",
      "product_type": "metered",
      "billable_metric_code": "data_processed"
    }
  }'
```

**4. Create a rate card**

The `graduated` rate prices the first 10 TiB at $0 and every TiB above at $6.25. Do not send `from_value`. The last tier has `to_value: null`.

```bash cURL highlight={14-23} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/rate_cards" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "rate_card": {
      "name": "BigQuery on-demand USD",
      "code": "bigquery_on_demand_usd",
      "product_code": "bigquery_on_demand",
      "currency": "USD",
      "billing_timing": "arrears",
      "proration": false,
      "rates": [
        {
          "code": "bigquery_on_demand_standard",
          "effective_from": "2027-01-01T00:00:00Z",
          "rate_model": "graduated",
          "rate_properties": {
            "graduated_ranges": [
              { "to_value": "10", "per_unit_amount": "0", "flat_amount": "0" },
              { "to_value": null, "per_unit_amount": "6.25", "flat_amount": "0" }
            ]
          },
          "billing_interval_count": 1,
          "billing_interval_unit": "month"
        }
      ]
    }
  }'
```

Refer to the [API reference](https://getlago.com/docs/v2/api-reference/rate-cards/create.md) and the [graduated model](https://getlago.com/docs/v2/guide/rate-cards/pricing-models/graduated.md).

**5. Create a plan and apply the rate card**

```bash cURL highlight={6-7} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/plans" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "plan": {
      "name": "BigQuery on-demand",
      "code": "bigquery_payg",
      "currency": "USD"
    }
  }'
```

```bash cURL highlight={6} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/plans/bigquery_payg/applied_rate_cards" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "applied_rate_card": {
      "rate_card_code": "bigquery_on_demand_usd"
    }
  }'
```

Refer to the [API reference](https://getlago.com/docs/v2/api-reference/plan-applied-rate-cards/create.md) and the [plans guide](https://getlago.com/docs/v2/guide/plans/overview.md).

**6. Create a customer**

```bash cURL highlight={6} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/customers" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "customer": {
      "external_id": "customer_example",
      "name": "Acme Corp",
      "email": "billing@example.com",
      "currency": "USD"
    }
  }'
```

An existing `external_id` returns `422` instead of updating the customer. Refer to the [API reference](https://getlago.com/docs/v2/api-reference/customers/create.md) to create a customer.

**7. Create a contract**

Replace `__PLAN_CODE__` with `bigquery_payg`.

```bash cURL highlight={6-10} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/contracts" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "contract": {
      "external_id": "contract_example",
      "external_customer_id": "customer_example",
      "plan_code": "__PLAN_CODE__",
      "started_at": "2027-01-01T00:00:00Z",
      "billing_anchor_date": "2027-02-01"
    }
  }'
```

The plan supplies the contract's initial applied rate cards. A future `started_at` creates a `pending` contract that becomes `active` on that date. Only one pending or active contract can use a given `external_id` at a time. Refer to the [API reference](https://getlago.com/docs/v2/api-reference/contracts/create.md) to create a contract.

> [!NOTE]
>
> The example dates are in the future. To test right away, set each rate's `effective_from` to today and omit `started_at`, which defaults to now.

**8. Ingest usage via events**

```bash cURL highlight={7-10} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/events" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "event": {
      "transaction_id": "__TRANSACTION_ID__",
      "code": "data_processed",
      "external_contract_id": "contract_example",
      "properties": {
        "data_processed_volume": 10
      }
    }
  }'
```

Refer to the [API reference](https://getlago.com/docs/v2/api-reference/events/create.md) and the [usage ingestion guide](https://getlago.com/docs/v2/guide/events/ingesting-usage.md).

**9. Monitor current usage**

Track usage across the contract's open billing periods.

```bash cURL highlight={1} theme={"dark"}
curl --location --request GET "$LAGO_URL/api/v2/contracts/contract_example/current_usage" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json'
```

The response returns `amount_cents`, `taxes_amount_cents`, `total_amount_cents` and a `rate_cards` array with usage per applied rate card. Pending contracts have no usage. Totals can span several invoices, so this is not a preview of one invoice. Filter with `rate_card_code`, `product_code`, `product_filter_code` or `product_type`. Refer to the [API reference](https://getlago.com/docs/v2/api-reference/contracts/retrieve-current-usage.md) to get current usage.

## Worked example

Over one full monthly period, the customer processes 25 TiB.

| Line | Quantity | Calculation | Amount |
| - | - | - | - |
| Tier 1 | 10 TiB | 10 × \$0 | \$0.00 |
| Tier 2 | 15 TiB | 15 × \$6.25 | \$93.75 |
| **Total before tax** | | | **\$93.75** |

## What changed from v1

* The v1 template granted \$300 of free credits through a wallet that expired after 90 days. The v2 API does not document wallets, so this template omits the credit grant.
* The charge becomes a rate card and a `graduated` rate. Tiers set `to_value` only.
* Events target `external_contract_id` instead of `external_subscription_id`.

> [card] [Graduated model](https://getlago.com/docs/v2/guide/rate-cards/pricing-models/graduated.md)
>
> Price quantity across tiers.

> [card] [Rate cards](https://getlago.com/docs/v2/guide/rate-cards/overview.md)
>
> Currency, billing timing and proration per product or filter.

> [card] [Contracts](https://getlago.com/docs/v2/guide/contracts/overview.md)
>
> Apply a plan to a customer.

> [card] [Retrieve current usage (API)](https://getlago.com/docs/v2/api-reference/contracts/retrieve-current-usage.md)
>
> `GET /api/v2/contracts/{external_id}/current_usage`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.