Rightshold™ Sign up

Answers · agent controls

How do I meter AI agent API usage with signed per-call usage records for invoicing, separate from human traffic?

Last updated

TL;DR: Bill agents from an append-only usage log, not from CDN page-view counters. On every successful agent API call (after auth), write a usage record that names the agent credential id, route or meter name, units (calls, tokens, rows, bytes), idempotency key, and timestamp, then seal a hash of that record (or a batch) in a signed receipt the customer can verify later. Human HTML and logged-in browser sessions stay on a separate, non-billable path so a shopper refreshing a page never appears on an agent invoice. At period end, aggregate only agent records into line items — the same pattern Stripe Billing Meters use with meter events (event_name, customer mapping, value, unique identifier) and that OpenAI's usage APIs expose per key or project for costs. This page is about metered invoicing evidence, not about rate limits (how fast an agent may call) or about x402 pay-per-call settlement at request time.

What should I check, step by step?

1. Create a meter per billable action (for example agent.api_call, agent.rows_exported) with a clear unit and aggregation (sum of calls, sum of rows). Do not reuse human analytics events.

  1. Identify the payer before you count: map each agent credential id to a customer (tenant or contract id). Reject or park calls that authenticate but have no billing mapping.
  2. On each billable agent response (2xx you intend to charge), emit one usage event with: customer_id, credential_id, meter/event_name, value, timestamp, and a unique idempotency key (request id). Stripe meter events recommend a UUID-like identifier so retries do not double-bill.
  3. Seal evidence: hash the canonical event (or a daily batch) and record it with record_ai_run or your own signed usage receipt so neither side can silently rewrite the period's totals later. Keep the full event store yourself; the seal holds hashes and counts.
  4. Keep humans out: middleware that meters must require an agent credential (or explicit agent API key). Session-cookie browser traffic must not increment agent meters.
  5. At invoice time, aggregate by customer and meter for the closed period, attach the sealed batch id or receipt ids as supporting evidence, and give the customer verify_ai_run / ledger_verify links for the seals.
  6. Handle disputes with the raw events: show the idempotency keys and credential ids for contested lines. If you refund, append a negative adjustment event; do not edit history.
  7. Separate hard rate limits from billing meters. A 429 means try later; a usage record means this successful call is on the next invoice.

Why must AI agent API usage meters exclude human page views?

CDN and product analytics count humans and bots together unless you filter. Invoices for agent API access need a counter that only advances when a verified agent credential (or your agent API key) passed auth on a billable route.

What fields belong in a signed per-call AI agent usage record for invoicing?

Minimum fields: event_name (meter), customer_id, agent credential id, value (integer units), timestamp, idempotency key, route or operation id. Optional: model or tool name, bytes, row count, response class/tier.

How do I turn sealed AI agent usage records into an invoice a customer can dispute?

Close the period, sum events by meter and customer, and generate line items (your invoicing system, Stripe subscription invoices fed by meters, or Rightshold's usage-based invoice helper for agent services). Attach the sealed batch receipt ids.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Record a signed receipt that seals this billing period's agent API usage batch: SHA-256 of the usage export, call count, customer id and meter name, so my customer can verify the invoice support later.”

One-click setup

{
  "tool": "record_ai_run",
  "arguments": {
    "model": "usage-meter/v1",
    "provider": "origin",
    "prompt_sha256": "<sha256 of the export query or period key>",
    "output_sha256": "<sha256 of the usage export file>",
    "params": {
      "customer_id": "cus_<id>",
      "meter": "agent.api_call",
      "call_count": 12840,
      "period_start": "2026-11-01T00:00:00Z",
      "period_end": "2026-12-01T00:00:00Z",
      "export_format": "jsonl, one event per line, sorted by idempotency_key"
    },
    "ran_at": "2026-12-01T01:00:00Z"
  }
}

Rightshold seals the hashes and fields you send and lets anyone verify them later. It does not count your HTTP traffic, charge cards or generate Stripe invoices unless you wire those systems yourself. Not legal advice.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'