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

# A/B Test Pricing

> Run pricing experiments by routing different user cohorts to different meters

## Problem

You want to test whether a 20% markup or a flat \$0.05/1K-token fee converts better, without changing your integration code.

## Solution

Create two meters with different pricing, then include the appropriate meter slug in each user's forward token based on their cohort.

### Step 1: Create Two Meters in the Dashboard

In your Lava dashboard, go to **Meters** and create two meters with different pricing:

|                    | Meter A                     | Meter B                   |
| ------------------ | --------------------------- | ------------------------- |
| **Name**           | Pricing Test A – 20% Markup | Pricing Test B – Flat Fee |
| **Fee type**       | Percentage                  | Fixed                     |
| **Fixed fee**      | \$0                         | \$0.05 per 1K tokens      |
| **Percentage fee** | 20%                         | 0%                        |
| **Billing basis**  | input-output                | input-output              |

Copy each meter's secret and add them to your environment:

```bash theme={null}
METER_SLUG_A=markup-20pct       # 20% markup meter
METER_SLUG_B=flat-fee           # flat fee meter
```

### Step 2: Assign Cohorts

Route users to meters based on any criteria — random split, user ID hash, feature flag, etc.

```typescript theme={null}
import { Lava } from '@lavapayments/nodejs';

const lava = new Lava();

function getMeterSlug(userId: string): string {
  // Simple 50/50 split based on user ID hash
  const hash = userId.split('').reduce((a, c) => a + c.charCodeAt(0), 0);
  return hash % 2 === 0
    ? process.env.METER_SLUG_A!
    : process.env.METER_SLUG_B!;
}
```

### Step 3: Generate Forward Tokens per Cohort

```typescript theme={null}
app.post('/api/chat', async (req, res) => {
  const meterSlug = getMeterSlug(req.user.id);

  const forwardToken = lava.generateForwardToken({
    customer_id: req.user.customerId,
    meter_slug: meterSlug,
  });

  const response = await fetch(
    lava.providers.openai + '/chat/completions',
    {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${forwardToken}`,
        'Content-Type': 'application/json',
        'X-Lava-Metadata-Cohort': meterSlug === process.env.METER_SLUG_A! ? 'A' : 'B',
      },
      body: JSON.stringify(req.body),
    }
  );

  // stream or return response...
});
```

### Step 4: Compare Results

Use metadata filters to compare cohort usage:

```typescript theme={null}
async function compareCohorts() {
  const start = new Date();
  start.setDate(start.getDate() - 7);

  const [cohortA, cohortB] = await Promise.all([
    lava.usage.retrieve({
      start: start.toISOString(),
      metadata_filters: { cohort: 'A' },
    }),
    lava.usage.retrieve({
      start: start.toISOString(),
      metadata_filters: { cohort: 'B' },
    }),
  ]);

  return {
    A: {
      requests: cohortA.totals.total_requests,
      totalCharge: parseFloat(cohortA.totals.total_charge).toFixed(2),
    },
    B: {
      requests: cohortB.totals.total_requests,
      totalCharge: parseFloat(cohortB.totals.total_charge).toFixed(2),
    },
  };
}
```

<Tip>
  Meter slugs are safe to include in forward tokens on the client side — they only specify which pricing to apply and don't grant access on their own.
</Tip>

## Next Steps

<CardGroup cols={2}>
  <Card title="Meters & Pricing" icon="gauge" href="/monetize/meters">
    Full reference for fee structures, tiers, and billing basis options
  </Card>

  <Card title="Usage Analytics" icon="chart-line" href="/cookbook/usage-analytics">
    Build dashboards to track experiment results
  </Card>
</CardGroup>
