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:
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.
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
app.post('/api/chat', async (req, res) => {
const meterSlug = getMeterSlug(req.user.id);
const forwardToken = lava.generateForwardToken({
connection_id: req.user.connectionId,
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:
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,
revenue: parseFloat(cohortA.totals.total_merchant_cost).toFixed(2),
},
B: {
requests: cohortB.totals.total_requests,
revenue: parseFloat(cohortB.totals.total_merchant_cost).toFixed(2),
},
};
}
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.
Next Steps