You've built an AI agent that works. Now you need to charge for it — reliably, accurately, and without spending the next three weeks building billing infrastructure. This is the guide for that. We'll cover exactly what Rev instruments, how the pricing engine processes it, and how to go from zero to a working billing integration in under an hour.
What Rev actually captures
Every time your agent fires, Rev expects a meter call. That call carries five things:
- agent_id — what ran (e.g.,
outreach-agent-v2) - action — what it did (
email.sent,task.complete,lead.qualified) - tokens_input / tokens_output — LLM consumption, read directly from the API response
- outcome —
success,failure, orpending(for deferred billing) - metadata — arbitrary key-value pairs for your own analytics and dispute resolution
These five fields are the entire telemetry contract. That's intentional — the system is designed to be instrumented in one line of code, not configured through a multi-step setup wizard.
await fetch('https://rev.polsia.app/v1/meter', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
agent_id: 'my-agent-v1',
action: 'email.sent',
tokens_input: 1200,
tokens_output: 340,
outcome: 'pending', // resolves to success/failure later
expires_at: new Date(Date.now() + 7 * 86400000).toISOString(),
metadata: { recipient: 'prospect@acme.com', campaign: 'q2-outreach' }
}),
});
The response includes price_charged — computed by Rev against your configured pricing tier — and outcome_id if you're using deferred billing.
How pricing is actually computed
Rev runs a three-component pricing model on every meter call:
| Component | What it charges | Example |
|---|---|---|
| Base fee | Flat fee per call — covers your fixed overhead | $0.01 per call |
| Token rate | Per-token charge — covers LLM compute | $0.0001 per token |
| Outcome bonus | Charged only when outcome resolves to success | $2.50 per qualified lead |
Each component is independently configurable per pricing tier. Set any component to zero if it doesn't apply to your model. The price is computed at meter time and stored with the event — your historical pricing is immutable regardless of future rate changes.
Deferred outcomes are the key pattern for anything async. When you send an email, you don't know yet if the prospect will reply. You register the call as pending with an expires_at window (typically 7 days). Only when the reply comes in and you call /v1/outcomes/:id/resolve does the outcome bonus get charged. If the window expires, Rev charges just the base + token fee — no outcome bonus.
Wiring it up in under an hour
The full integration has four steps:
Step 1: Get your API key
Sign up at rev.polsia.app/signup. Key lands in your dashboard immediately.
Step 2: Configure your pricing tier
In the dashboard → Pricing, set your base fee, token rate, and outcome bonus. Use the revenue calculator to model expected revenue before you lock in rates.
Step 3: Instrument your agent
Add one fetch call after each LLM execution — before you return to the caller. Capture token counts from the LLM response object, not estimates. Always meter failures (they consumed compute) but never charge outcome bonuses on them.
async function runAgent(input) {
const llmResponse = await openai.chat.completions.create({
model: 'gpt-4o',
messages: buildPrompt(input),
});
const result = parseAgentOutput(llmResponse);
// One line to meter — price computed by Rev's pricing engine
await fetch('https://rev.polsia.app/v1/meter', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.REV_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
agent_id: 'my-agent-v1',
action: 'task.complete',
tokens_input: llmResponse.usage.prompt_tokens,
tokens_output: llmResponse.usage.completion_tokens,
outcome: result.success ? 'success' : 'failure',
metadata: { customer_id: input.customerId }
}),
});
return result;
}
Step 4: Set up outcome resolution
If you're using deferred outcomes, wire up the detection point (webhook, email inbox, calendar check) and call /v1/outcomes/:id/resolve when the result is confirmed. Rev handles the billing and stores the resolved price.
// When prospect replies to outreach email
await fetch(`https://rev.polsia.app/v1/outcomes/${outcome_id}/resolve`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.REV_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
outcome: 'success',
metadata: { reply_type: 'positive', meeting_booked: true }
}),
});
// Outcome bonus ($2.50) charged now
What you get automatically
After the meter call, Rev handles: per-customer usage aggregation, Stripe invoicing, a customer-facing usage dashboard, and an immutable audit trail of every billing event with timestamp, token counts, outcome, and price charged. You don't build any of that.
Idempotency is built in — pass an Idempotency-Key header on the meter call and Rev deduplicates. Safe to retry on network failures without double-billing.
price_charged and shows up in your dashboard within seconds, your integration is working. The rest of the hour is wiring up the full agent flow.
Meter your first agent call in 5 minutes. Revenue analytics and Stripe billing included. Get Your API Key Free →
What to read next
- How to Build a Usage-Based Billing System for AI Agents — full step-by-step implementation with edge cases
- AI Agent Pricing Models Compared — per-token vs per-call vs outcome-based with a decision framework
- API reference — every endpoint and response field