In this article, you will learn how to offer free upfront credits for new users on a ‘pay-as-you-go’ pricing model. This template is fitted for infra companies, like this BigQuery example, but is also widely used among AI companies to let new users try their products easily. Mistral or Perplexity are other great examples.

Pricing structure

BigQuery offers customers the possibility to subscribe for free and only pay based on usage. For new customers, the platform offers $300 worth of credits during 90 days to try the product completely for free.
PlanCost per volume of data scanned
On-Demand pricing$6.25 per TiB (a measure of compute capacity)

Get started

1

Set up Lago

LAGO_URL="https://api.getlago.com"
API_KEY="__API_KEY__"
2

Create a billable metric

Create a billable metric to track data processing volume.
  1. Set the aggregation_type to sum_agg to sum all data processed
  2. Set the field_name to data_processed_volume for tracking usage
  3. Set recurring to false for metered billing
curl --location --request POST "$LAGO_URL/api/v1/billable_metrics" \
  --header 'Authorization: Bearer __API_KEY__' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "billable_metric": {
      "name": "BigQuery Data Processing",
      "code": "__BILLABLE_METRIC_CODE__",
      "description": "Data processing volume in TiB",
      "aggregation_type": "sum_agg",
      "field_name": "data_processed_volume",
      "recurring": false
    }
  }'
Refer to the API reference to create a billable metric.
3

Create a plan

Create a plan with graduated pricing to include free tier usage.
  1. Set the amount_cents to 0 since there is no subscription fee
  2. Use graduated charge model with BigQuery’s $6.25 per TiB rate
  3. Configure first 10 TiB as free, then $6.25 per TiB after that
curl --location --request POST "$LAGO_URL/api/v1/plans" \
  --header 'Authorization: Bearer __API_KEY__' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "plan": {
      "name": "BigQuery On-Demand",
      "code": "__PLAN_CODE__",
      "interval": "monthly",
      "description": "Pay-as-you-go BigQuery pricing with free tier",
      "amount_cents": 0,
      "amount_currency": "USD",
      "charges": [
        {
          "billable_metric_code": "__BILLABLE_METRIC_CODE__",
          "charge_model": "graduated",
          "properties": {
            "graduated_ranges": [
              {
                "from_value": 0,
                "to_value": 10000,
                "per_unit_amount": "0",
                "flat_amount": "0"
              },
              {
                "from_value": 10001,
                "to_value": null,
                "per_unit_amount": "6.25",
                "flat_amount": "0"
              }
            ]
          }
        }
      ]
    }
  }'
Refer to the API reference and guide on graduated pricing to learn more.
4

Create a customer

Create a customer with a unique external_id.
curl --location --request POST "$LAGO_URL/api/v1/customers" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "customer": {
      "external_id": "__EXTERNAL_CUSTOMER_ID__",
      "name": "Acme Inc",
      "email": "john@acme.com",
      "currency": "USD",
      "timezone": "America/New_York"
    }
  }'
Refer to the API reference to create a customer.
5

Create a wallet with free credits

BigQuery lets new users try its product for free by offering upfront credits valid for 90 days. We can replicate this logic using Lago’s wallet feature.
  1. Create a wallet with $300 of free credits for the customer
  2. Set expiration_at to 90 days from now for the trial period
curl --location --request POST "$LAGO_URL/api/v1/wallets" \
  --header 'Authorization: Bearer __API_KEY__' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "wallet": {
      "external_customer_id": "__EXTERNAL_CUSTOMER_ID__",
      "name": "BigQuery Trial Credits",
      "rate_amount": "1.0",
      "paid_credits": "300.0",
      "granted_credits": "0.0",
      "expiration_at": "2024-12-31T23:59:59Z"
    }
  }'
Refer to the API reference to create a wallet.
  1. Create a subscription for the customer with the plan’s code.
curl --location --request POST "$LAGO_URL/api/v1/subscriptions" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "subscription": {
      "external_customer_id": "__EXTERNAL_CUSTOMER_ID__",
      "plan_code": "__PLAN_CODE__",
      "external_id": "__EXTERNAL_SUBSCRIPTION_ID__"
    }
  }'
Refer to the API reference to create a subscription.
6

Ingest usage via events

Send usage events to Lago to track usage.
  1. Reference your billable metric with code
  2. Reference the customer’s subscription with external_subscription_id
  3. Include usage and filters data in properties
curl --location --request POST "$LAGO_URL/api/v1/events" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "event": {
      "transaction_id": "__TRANSACTION_ID__",
      "code": "__BILLABLE_METRIC_CODE__",
      "external_subscription_id": "__EXTERNAL_SUBSCRIPTION_ID__",
      "properties": {
        "data_processed_volume": 10
      }
    }
  }'
Refer to the API reference to create an event.
7

Monitor current usage

Track real-time customer usage for the current billing period.
curl --location --request GET "$LAGO_URL/api/v1/customers/__EXTERNAL_CUSTOMER_ID__/current_usage?external_subscription_id=__EXTERNAL_SUBSCRIPTION_ID__" \
--header 'Authorization: Bearer __API_KEY__' \
--header 'Content-Type: application/json'
Refer to the API reference to get the current usage.

Wrap-up

Offering free upfront credits is a popular strategy among AI and infra companies with pay-as-you-go models like BigQuery. With Lago, you can adapt this template to your products and services using:
  1. Configure your pay-as-you-go pricing by aggregate using a billable metric;‍
  2. Add this billable metric as graduated charges to a plan; and‍
  3. Create a wallet and add prepaid free credits.
Give it a try, click here to get started!