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

> Rebuild Segment's hybrid pricing in Lago: a fixed product billed in advance plus graduated usage on monthly tracked users, applied with a contract.

This template builds hybrid pricing like Segment's with Lago: a fixed monthly platform fee plus a graduated usage component. Use it when a recurring fee covers base access and usage above an included volume grows revenue with your customers.

Legacy (v1): [Clone Segment pricing with subscriptions](https://getlago.com/docs/templates/hybrid/segment.md).

## Pricing structure

Segment's Team plan combines a platform fee with usage on monthly tracked users (MTUs), the number of unique users whose data is stored each month.

| Team plan | Price |
| - | - |
| Platform fee | \$120/month |
| Included consumption | 10,000 MTUs |
| 10,001 to 25,000 MTUs | \$0.012/MTU |
| 25,001 to 100,000 MTUs | \$0.011/MTU |
| 100,001+ MTUs | \$0.010/MTU |

## How it maps to Lago

| Pricing element | Lago object |
| - | - |
| Platform fee | Fixed product `team_platform_fee`, rate card `team_platform_fee_usd` (advance), `standard` rate at \$120/month, applied with `units: "1"` |
| MTU usage | Billable metric `mtu` (`unique_count_agg` on `user_id`), metered product `monthly_tracked_users` |
| Tiered MTU price | Rate card `mtu_usd` (arrears) with a `graduated` rate |
| The offer | Plan `segment_team` |

## 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**

Count unique users per billing period.

```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": "Monthly tracked users",
      "code": "mtu",
      "aggregation_type": "unique_count_agg",
      "field_name": "user_id",
      "recurring": false
    }
  }'
```

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

**3. Create the products**

Create a fixed product for the platform fee. Fixed products reject `billable_metric_code`.

```bash cURL highlight={7} 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": "Team platform fee",
      "code": "team_platform_fee",
      "product_type": "fixed"
    }
  }'
```

Create a metered product for MTUs.

```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": "Monthly tracked users",
      "code": "monthly_tracked_users",
      "product_type": "metered",
      "billable_metric_code": "mtu"
    }
  }'
```

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

**4. Create the rate cards**

The platform fee is billed in advance with a `standard` rate of \$120 per month. Fixed products support `standard`, `graduated` and `volume` only.

```bash cURL highlight={9,14-19} 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": "Team platform fee USD",
      "code": "team_platform_fee_usd",
      "product_code": "team_platform_fee",
      "currency": "USD",
      "billing_timing": "advance",
      "proration": false,
      "rates": [
        {
          "code": "team_fee_standard",
          "effective_from": "2027-01-01T00:00:00Z",
          "rate_model": "standard",
          "rate_properties": { "amount": "120" },
          "billing_interval_count": 1,
          "billing_interval_unit": "month"
        }
      ]
    }
  }'
```

MTUs are billed in arrears with a `graduated` rate. Each tier sets an upper bound with `to_value`. Do not send `from_value`. The last tier has `to_value: null`.

```bash cURL expandable highlight={9,14-25} 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": "Monthly tracked users USD",
      "code": "mtu_usd",
      "product_code": "monthly_tracked_users",
      "currency": "USD",
      "billing_timing": "arrears",
      "proration": false,
      "rates": [
        {
          "code": "mtu_graduated",
          "effective_from": "2027-01-01T00:00:00Z",
          "rate_model": "graduated",
          "rate_properties": {
            "graduated_ranges": [
              { "to_value": "10000", "per_unit_amount": "0", "flat_amount": "0" },
              { "to_value": "25000", "per_unit_amount": "0.012", "flat_amount": "0" },
              { "to_value": "100000", "per_unit_amount": "0.011", "flat_amount": "0" },
              { "to_value": null, "per_unit_amount": "0.010", "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 cards**

```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": "Segment Team",
      "code": "segment_team",
      "currency": "USD"
    }
  }'
```

Apply the platform fee with one fixed unit:

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

Apply the MTU rate card:

```bash cURL highlight={6} theme={"dark"}
curl --location --request POST "$LAGO_URL/api/v2/plans/segment_team/applied_rate_cards" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "applied_rate_card": {
      "rate_card_code": "mtu_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 `segment_team`.

```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**

Send one event per tracked user. Repeated `user_id` values in the same period count once.

```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": "mtu",
      "external_contract_id": "contract_example",
      "properties": {
        "user_id": "user_001"
      }
    }
  }'
```

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 tracks 30,000 unique users. The platform fee is billed in advance for the period. The MTU fee is billed in arrears at the end of the period.

| Line | Quantity | Calculation | Amount |
| - | - | - | - |
| Team platform fee | 1 unit | 1 × \$120 | \$120.00 |
| MTUs, tier 1 | 10,000 | 10,000 × \$0 | \$0.00 |
| MTUs, tier 2 | 15,000 | 15,000 × \$0.012 | \$180.00 |
| MTUs, tier 3 | 5,000 | 5,000 × \$0.011 | \$55.00 |
| **Total for the period before tax** | | | **\$355.00** |

## What changed from v1

* The plan's subscription fee becomes a fixed product, a rate card with `billing_timing: "advance"` and a `standard` rate, applied with `units`.
* The v1 template used a 14-day trial. v2 has no trial setting, and rate phases count billing cycles, not days. To offer an introductory price, use [plan phases](https://getlago.com/docs/v2/guide/plans/plan-phases.md) with a `rate_override`.
* Events target `external_contract_id` instead of `external_subscription_id`.

> [card] [Fixed products](https://getlago.com/docs/v2/guide/product-catalog/fixed-products.md)
>
> Price configured quantities without usage events.

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

> [card] [Plan phases](https://getlago.com/docs/v2/guide/plans/plan-phases.md)
>
> Introductory pricing measured in billing cycles.

> [card] [Apply a rate card to a plan (API)](https://getlago.com/docs/v2/api-reference/plan-applied-rate-cards/create.md)
>
> `POST /api/v2/plans/{plan_code}/applied_rate_cards`


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