# Attach Meter to Plan

<Note>
**Enabled per organization**

Usage-based billing must be enabled for your organization before these endpoints accept requests. Contact your WHITELABEL account manager to enable it. Requests from an organization where it is not enabled return `403 PRODUCT_NOT_ENABLED`.
</Note>

The plan's flat price and existing subscribers' base amount never change when you attach a meter. Every subscription on the plan inherits the metered price and can start reporting usage right away.

<Note>
**Two ways to attach**

- **On creation:** pass `meters[]` (same shape as this request body) to [Create Plan](/reference/plans/create-plan). Duplicated `meter_id` entries are rejected with `409`.
- **On a live plan:** call this endpoint once per meter, or send `{ "meters": [ ... ] }` to `PATCH /subscriptions/plans/{plan_id}` — that PATCH is attach-only and atomic: if any entry in the list is invalid (already attached, unknown or inactive meter, bad price) nothing is attached. Any other plan field in that body (`name`, `base_amount`, …) is silently ignored — plans stay immutable outside `meters[]`.
</Note>

<Note>
**Price inheritance**

If the plan's base currency is `USD` and the meter has a `default_price`, you can omit `price_per_credit`: the meter's default applies and the metered price is returned with `price_per_credit: null`. In any other case (`price_per_credit` currency must always equal the plan's base currency) send it explicitly. Only `ACTIVE` meters can be attached; an archived meter is rejected with `400 METER_NOT_FOUND`.
</Note>

<Note>
**`pricing_strategy` config**

`PER_UNIT` uses `price_per_credit`/`country_prices`. `PACKAGE` uses `package_size`, `package_price` and optionally `package_country_prices`. `TIERED` uses `tiers[]` (ascending `up_to` bounds, last tier `up_to: null`). Sending config fields for a strategy other than the one you selected is rejected with `400 PLAN_METER_PRICING_CONFIG_UNSUPPORTED`. Once attached, `PACKAGE`/`TIERED` config cannot be changed — see [Update Plan Meter](/reference/meters/update-plan-meter).
</Note>

See [The Metered Price Object](/reference/meters/the-metered-price-object) for every field. Refer to [Meter Error Codes](/reference/meters/meter-error-codes) for the possible error outcomes.

**POST** `/subscriptions/plans/{plan_id}/meters`

Base URL: `https://api-sandbox.whitelabel.com/v1`

Usage-based billing must be enabled for your organization before this endpoint accepts requests (otherwise `403 PRODUCT_NOT_ENABLED`). Attaches a meter to an existing plan as a metered price: how many units are included per cycle (`credits`) and what each unit beyond that costs. Attaching does not change the plan's flat price or any existing subscriber's base amount. You can also attach meters inline with `meters[]` when calling Create Plan.

## Authorization

- public-api-key (apiKey in header)
- private-secret-key (apiKey in header)

## Header parameters

- `X-Account-Code` (string, required)
  The `account_id` found in your [WHITELABEL Dashboard](https://dashboard.whitelabel.com/developers) (UUID). Required — omitting it returns `400 BAD_REQUEST` ("Invalid x-account-code header.").
- `X-Idempotency-Key` (string, required)
  Unique identifier used in HTTP headers to ensure that a request is processed only once, even if it is retried due to network issues or timeouts. Optional, as on the rest of the WHITELABEL API.

## Path parameters

- `plan_id` (string, required)
  The unique identifier of the plan.

## Body

Content type: `application/json`

- `meter_id` (string, required)
  The unique identifier of the meter to attach (MAX 64; MIN 36). Must be an existing `ACTIVE` meter of the account — an unknown or `INACTIVE` meter is rejected with `400 METER_NOT_FOUND`. A meter can be attached to a plan only once, else `409 PLAN_METER_ALREADY_ASSIGNED`.
- `credits` (number<float>, required)
  Units included in the plan per billing cycle — the allowance a subscriber can consume before any usage is billed. Must be >= 0. `0` means every unit is billed.
- `pricing_strategy` ("PER_UNIT" | "PACKAGE" | "TIERED", required)
  How usage beyond `credits` is priced: `PER_UNIT` (billable units × `price_per_credit`), `PACKAGE` (bundles of N units, partial bundle counts as a full one) or `TIERED` (graduated tiers, each band at its own rate).
- `price_per_credit` (object)
  - `currency` (string, required)
    MAX 3; MIN 3. Must equal the plan's `base_amount` currency, else `400 INVALID_PARAMETERS`.
  - `value` (number<float>, required)
    Price per unit beyond the included credits (multiple of 0.0001). Optional only when the plan's base currency is `USD` and the meter has a `default_price` — the meter's default then applies and the metered price is returned with `price_per_credit: null`. Required otherwise.
- `country_prices` (object[])
  Optional explicit per-country price per unit. One entry per country — a repeated country is rejected with `400 INVALID_PARAMETERS`. A country not listed falls back to `price_per_credit`.
  - `country` (string, required)
    MAX 2; MIN 2; [ISO 3166-1](/reference/country-reference).
  - `amount` (object, required)
    - `currency` (string, required)
      MAX 3; MIN 3; [ISO 4217](/reference/country-reference).
    - `value` (number<float>, required)
      Multiple of 0.0001.
- `package_size` (number<float>)
  Only for `pricing_strategy: PACKAGE`. The bundle size — billable units are rounded up to the nearest whole multiple. Must be > 0; decimals and scientific notation (`1e3`) are accepted and coerced. Stored rounded to 4 decimal places. Required when `pricing_strategy` is `PACKAGE`; rejected with `400 PLAN_METER_PRICING_CONFIG_UNSUPPORTED` for any other strategy.
- `package_price` (object)
  Only for `pricing_strategy: PACKAGE`. The price per bundle. Same shape as `price_per_credit`. Required when `pricing_strategy` is `PACKAGE`.
  - `currency` (string)
    MAX 3; MIN 3. Must equal the plan's `base_amount` currency.
  - `value` (number<float>)
- `package_country_prices` (object[])
  Only for `pricing_strategy: PACKAGE`. Optional per-bundle price by subscriber country. Same shape as `country_prices`.
  - `country` (string)
    MAX 2; MIN 2; ISO 3166-1.
  - `amount` (object)
    - `currency` (string)
    - `value` (number<float>)
- `tiers` (object[])
  Only for `pricing_strategy: TIERED`. Ordered, graduated pricing bands. Required when `pricing_strategy` is `TIERED` (at least one entry). Every tier but the last needs a strictly-ascending `up_to`; the last tier's `up_to` must be `null` (unbounded). Every tier must share the same currency (and the same `country_rates` countries, if used).
  - `up_to` (number<float>)
    Inclusive upper bound of this tier's billable-unit band, or `null` on the last (unbounded) tier.
  - `rate` (object)
    Price per unit within this band. Same shape as `price_per_credit`.
    - `currency` (string)
    - `value` (number<float>)
  - `country_rates` (object[])
    Optional per-country override of `rate` for this tier. Same shape as `country_prices`.
    - `country` (string)
    - `amount` (object)
      - `currency` (string)
      - `value` (number<float>)

Example:

```json
{
  "meter_id": "string",
  "credits": 0,
  "pricing_strategy": "PER_UNIT",
  "price_per_credit": {
    "currency": "string",
    "value": 0
  },
  "country_prices": [
    {
      "country": "string",
      "amount": {
        "currency": "string",
        "value": 0
      }
    }
  ],
  "package_size": 0,
  "package_price": {
    "currency": "string",
    "value": 0
  },
  "package_country_prices": [
    {
      "country": "string",
      "amount": {
        "currency": "string",
        "value": 0
      }
    }
  ],
  "tiers": [
    {
      "up_to": 0,
      "rate": {
        "currency": "string",
        "value": 0
      },
      "country_rates": [
        {
          "country": "string",
          "amount": {
            "currency": "string",
            "value": 0
          }
        }
      ]
    }
  ]
}
```

## Responses

### 201

201

- `id` (string)
  The unique identifier of the metered price (the plan-meter relation).
- `plan_id` (string)
- `meter_id` (string)
- `credits` (number)
  Units included in the plan per billing cycle.
- `pricing_strategy` ("PER_UNIT" | "PACKAGE" | "TIERED")
- `price_per_credit` (object)
  `null` when inherited from the meter's `default_price` (USD plans).
  - `currency` (string)
  - `value` (number)
- `country_prices` (object[])
  - `country` (string)
  - `amount` (object)
    - `currency` (string)
    - `value` (number)
- `created_at` (string)
  Set by WHITELABEL on creation.
- `updated_at` (string)
  Set by WHITELABEL on every update.

Example:

```json
{
  "id": "string",
  "plan_id": "string",
  "meter_id": "string",
  "credits": 0,
  "pricing_strategy": "PER_UNIT",
  "price_per_credit": {
    "currency": "string",
    "value": 0
  },
  "country_prices": [
    {
      "country": "string",
      "amount": {
        "currency": "string",
        "value": 0
      }
    }
  ],
  "created_at": "string",
  "updated_at": "string"
}
```

### 400

400

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "string",
  "messages": [
    "string"
  ]
}
```

### 403

403

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "PRODUCT_NOT_ENABLED",
  "messages": [
    "string"
  ]
}
```

### 409

409

- `code` (string)
- `messages` (string[])

Example:

```json
{
  "code": "string",
  "messages": [
    "string"
  ]
}
```