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.
Problem
You want to show customers a log of their AI requests — model used, tokens consumed, cost, and status — with pagination and optional filtering.
Solution
Use requests.list() with a customer_id filter and map the results into a display-friendly format.
import { Lava } from '@lavapayments/nodejs';
const lava = new Lava();
async function getRequestHistory(customerId: string, cursor?: string) {
const response = await lava.requests.list({
customer_id: customerId,
limit: 20,
cursor,
});
return {
requests: response.data.map((req) => ({
id: req.request_id,
date: req.created_at,
provider: req.provider,
model: req.model,
tokens: req.model_usage.total_tokens,
cost: parseFloat(req.cost).toFixed(4),
status: req.status,
})),
hasMore: response.has_more,
nextCursor: response.next_cursor,
};
}
app.get('/api/requests', async (req, res) => {
const { cursor } = req.query;
const history = await getRequestHistory(
req.user.customerId,
cursor as string | undefined
);
res.json(history);
});
Filter by Feature
Use metadata headers when making AI requests, then filter on them later:
// When making requests — tag with metadata
headers['X-Lava-Metadata-Feature'] = 'chat';
headers['X-Lava-Metadata-Session'] = sessionId;
// When querying — filter by metadata
const chatRequests = await lava.requests.list({
customer_id: customerId,
metadata_filters: { feature: 'chat' },
limit: 50,
});
Export to CSV
async function exportToCSV(customerId: string) {
const allRequests = [];
let cursor: string | undefined;
do {
const response = await lava.requests.list({
customer_id: customerId,
limit: 100,
cursor,
});
allRequests.push(...response.data);
cursor = response.next_cursor;
} while (cursor);
const lines = [
'Date,Provider,Model,Tokens,Cost',
...allRequests.map((r) =>
[r.created_at, r.provider, r.model, r.model_usage.total_tokens, r.cost].join(',')
),
];
return lines.join('\n');
}
Next Steps
Usage Analytics
Aggregate usage data for dashboards and billing reports
Forward Proxy
Learn how to attach metadata headers to proxy requests