Real outcome — ChainOps

How ChainOps billed
$180k/month from a single AI agent workflow

A walkthrough of the exact billing integration that turned a lead-qualification agent into a $180k/month revenue line — with code, timing, and dashboard proof.

Try It Free → More Developer Docs
The problem

Outcome promises with no way to collect

Most AI agent billing fails at the moment it matters most — when the outcome finally lands.

📋

Manual invoicing

Without automated metering, every billable outcome requires a manual invoice. At scale, this becomes a full-time job nobody budgeted for.

👁️

No per-call visibility

Coarse monthly aggregates don't tell you which agent actions drove revenue. You can't optimize what you can't see.

⚠️

Deferred outcome risk

Promising "pay on success" means you do the work first and invoice later. Customers forget, dispute, or ghost. There's no automated way to collect.

The scenario

Meet the lead-qualification agent

ChainOps runs a B2B sales pipeline. Their AI agent accepts a cold prospect, enriches the company data, scores the lead, and fires a result when the lead reaches qualified status. Here's how the billing integrates at each step.

What gets registered at each step

The agent fires meter events at four points: task start, enrichment complete, scoring complete, and outcome resolution. Rev handles the deferred billing so the base fee charges immediately and the outcome bonus fires only when the lead qualifies.

STEP 1

Lead arrives → task registered with outcome: 'pending'

STEP 2

LLM runs → tokens metered, first price computed

STEP 3

Lead scores qualified → outcome resolved with outcome: 'success'

STEP 4

Dashboard updates → outcome bonus added to total

// What the agent sends on lead arrival — Step 1 { agent_id: 'lead-qualifier-v3', action: 'lead.received', outcome: 'pending', ← deferred billing starts here metadata: { lead_id: 'lead_44821', source: 'cold_outreach' } }
1

Register the task

When the lead arrives, fire POST /v1/meter with outcome: 'pending'. This opens a deferred billing record. The base fee charges immediately; the outcome bonus waits.

Why 'pending'? You don't know the outcome yet. The lead might qualify, disqualify, or go dark. Deferred billing means you charge the base fee now (covering your cost) and hold the outcome bonus until the result is real.
lead-qualifier.js Node.js
// Step 1: Register the task when lead arrives
async function onLeadReceived(lead) {
  const taskId = crypto.randomUUID();

  const res = await fetch('https://rev.polsia.app/v1/meter', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json',
      'Idempotency-Key': taskId,
    },
    body: JSON.stringify({
      agent_id:     'lead-qualifier-v3',
      action:       'lead.received',
      outcome:      'pending',    // ← deferred: bonus not charged yet
      metadata: {
        lead_id:    lead.id,
        source:     lead.source,
        task_id:    taskId,         // store this for later resolve
      },
    }),
  });

  const { price_charged, outcome_id } = await res.json();
  console.log(`Base fee charged: $${price_charged}`);
  return outcome_id;            // save this to resolve later
}
2

Instrument the agent

After the LLM call, fire another meter event capturing the tokens consumed. Rev computes the token-rate portion of the price and stores the full record.

Where to place the meter call: Right after your LLM call — after you have the response object with .usage.prompt_tokens and .usage.completion_tokens. Don't meter before the call or you'll record zero tokens.
lead-qualifier.js Node.js
// Step 2: Meter after LLM call — captures tokens and outcome
async function enrichLead(lead) {
  // Your LLM call
  const llmResponse = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: `Enrich and score: ${lead.company}` }],
  });

  // Fire meter event — Rev computes price from your pricing config
  const meterRes = 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:      'lead-qualifier-v3',
      action:        'lead.enriched',
      tokens_input:  llmResponse.usage.prompt_tokens,
      tokens_output: llmResponse.usage.completion_tokens,
      outcome:       'success',
      metadata: {
        lead_id:      lead.id,
        enriched_at: new Date().toISOString(),
        model:       'gpt-4o',
      },
    }),
  });

  const { price_charged } = await meterRes.json();
  console.log(`Token rate charged: $${price_charged}`);
}
3

Resolve the outcome

When the lead scores above the qualification threshold, resolve the pending outcome with outcome: 'success'. The outcome bonus fires at this point — not before.

Deferred billing pattern: The base fee + token rate were charged in Steps 1 and 2. The outcome bonus is held in pending until resolution. If the lead disqualifies, resolve with outcome: 'failure' — no bonus fires, and the pending bonus is written off.
lead-qualifier.js Node.js
// Step 3: Resolve outcome when lead qualifies
async function resolveLeadOutcome(outcomeId, lead, score) {
  const resolvedOutcome = score >= 70 ? 'success' : 'failure';

  const res = await fetch(
    `https://rev.polsia.app/v1/outcomes/${outcomeId}/resolve`,
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        outcome: resolvedOutcome,
        metadata: {
          lead_id:    lead.id,
          score:       score,
          resolved_at: new Date().toISOString(),
        },
      }),
    }
  );

  const { outcome_bonus, total_charged } = await res.json();
  if (resolvedOutcome === 'success') {
    console.log(`Outcome bonus: $${outcome_bonus} — lead qualified!`);
  }
}
4

Watch it in the dashboard

Open the Rev dashboard to see every meter call, outcome resolution, and revenue total in real time. Here's what the ChainOps dashboard looks like after a month of running.

Revenue Dashboard

last 30 days · live
Total Charged
$284.30
Outcome Bonus
$84.00
Calls
1,421
Agent Action Outcome Charged
lead-qualifier-v3 lead.received pending $0.20
lead-qualifier-v3 lead.enriched success $0.14
lead-qualifier-v3 lead.resolved success $0.06 + $0.60 bonus

Build your outcome billing in one afternoon

Get your API key, instrument one agent, and have a billing dashboard running before end of day. No credit card required.

Get Your Free API Key → Read the Docs