> ## 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 Algolia pricing

> Rebuild Algolia's pay-as-you-go search pricing in Lago with a metered product, a package rate with free monthly requests and a contract.

This template builds pay-as-you-go billing like Algolia Search with Lago: no platform fee, a free monthly allowance, then a price per bundle of requests. It suits API and infrastructure companies that charge only for what customers consume.

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

## Pricing structure

| Search API | Price |
| - | - |
| Monthly price | \$1.50 / 1,000 requests |
| Free usage each month | 10,000 requests |

## How it maps to Lago

| Pricing element | Lago object |
| - | - |
| Request volume | Billable metric `search_requests` (`sum_agg` on `search_requests_volume`) |
| What you sell | Metered product `search_api` |
| \$1.50 per 1,000 requests, 10,000 free | Rate card `search_api_usd` with a `package` rate |
| The offer | Plan `algolia_payg` with no fixed product |

## 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": "Search API requests",
      "code": "search_requests",
      "aggregation_type": "sum_agg",
      "field_name": "search_requests_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": "Search API",
      "code": "search_api",
      "product_type": "metered",
      "billable_metric_code": "search_requests"
    }
  }'
```

Refer to the [metered products guide](https://getlago.com/docs/v2/guide/product-catalog/metered-products.md).

**4. Create a rate card**

The `package` rate charges `amount` per `package_size` requests. `free_units` sets the free units per billing period.

```bash cURL highlight={14-22} 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": "Search API USD",
      "code": "search_api_usd",
      "product_code": "search_api",
      "currency": "USD",
      "billing_timing": "arrears",
      "proration": false,
      "rates": [
        {
          "code": "search_api_standard",
          "effective_from": "2027-01-01T00:00:00Z",
          "rate_model": "package",
          "rate_properties": {
            "amount": "1.50",
            "package_size": 1000,
            "free_units": 10000
          },
          "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 [package model](https://getlago.com/docs/v2/guide/rate-cards/pricing-models/package.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": "Algolia Search pay as you go",
      "code": "algolia_payg",
      "currency": "USD"
    }
  }'
```

```bash cURL highlight={6} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/plans/algolia_payg/applied_rate_cards" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "applied_rate_card": {
      "rate_card_code": "search_api_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 `algolia_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": "search_requests",
      "external_contract_id": "contract_example",
      "properties": {
        "search_requests_volume": 5000
      }
    }
  }'
```

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 sends 50,000 search requests.

| Line | Calculation | Amount |
| - | - | - |
| Free requests | 10,000 requests | \$0.00 |
| Billable requests | 40,000 requests = 40 packages × \$1.50 | \$60.00 |
| **Total before tax** | | **\$60.00** |

## What changed from v1

* The plan has no fixed product, so there is no platform fee. In v1 this was `amount_cents: 0` on the plan.
* The charge becomes a rate card and a `package` rate with an effective date.
* Events target `external_contract_id` instead of `external_subscription_id`.

> [card] [Package model](https://getlago.com/docs/v2/guide/rate-cards/pricing-models/package.md)
>
> Charge a fixed amount per bundle of units.

> [card] [Metered products](https://getlago.com/docs/v2/guide/product-catalog/metered-products.md)
>
> Products priced from usage events.

> [card] [Contract current usage](https://getlago.com/docs/v2/guide/events/retrieve-usage.md#retrieve-current-usage)
>
> Monitor open billing periods.

> [card] [Create a contract (API)](https://getlago.com/docs/v2/api-reference/contracts/create.md)
>
> `POST /api/v2/contracts`


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