View as Markdown

Authorize · Guide

Pay per call with tabs

Use this when one agent calls another's paid API many times a day for small amounts. The buyer opens a tab once; it runs through authorize once and reserves its daily cap from the grant's budget. After that, each call carries the tab token and the seller checks it offline in a few milliseconds, with no call to Provenance per request. The seller bills on its own rail and posts signed usage statements; Provenance never holds the money.

Before you begin: the seller sells to agents (a selling agent with an Identify key), and the buyer has a grant for its agent.

1. Publish a price sheet (seller)

A price sheet is an offer with delivery.kind: "service" and per-unit prices, signed with your agent's key:

import { signOffer } from "@provenanceauth/rails/deals";

const { offer: priceSheet } = await signOffer({
  iss: agentId,
  offer_id: "sheet_company_lookup_v3",
  items: [{ sku: "lookup", name: "Company lookup", quantity: 1, unit: "call", unit_price: 0.002 }],
  total: 0.002,
  currency: "USD",
  delivery: { kind: "service", deadline: "2026-12-01T00:00:00Z" },
  refund_terms: ["none"],
  seller_confirmation: { offered: "never", response_time: "1bd" },
}, privateJwk, { ttlSeconds: 7 * 24 * 3600 });

Hand it to buyers however you like: in a 402, on a pricing endpoint, or in your docs. A buyer must open its tab before the price sheet expires; the tab then keeps those prices for its life.

2. Open a tab (buyer)

curl -s -X POST $PROVENANCE_API/v1/authorize/tabs \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "price_sheet": "'"$PRICE_SHEET"'", "agent_session_id": "sess_scout_7", "grant_id": "'"$MANDATE_ID"'",
        "max_per_call": 0.01, "daily_cap": 40, "expires_at": "2026-11-14T00:00:00Z" }'

The open runs the ordinary authorize path once as tab.open, with the seller as the counterparty and daily_cap as the amount, so your grant's limits and your policy apply. A policy step-up leaves the tab pending_approval until your person approves. Once it's open, tab_token is ready. A tab lives at most 30 days and never past its grant. Opening is free.

3. Send the token on each call (buyer)

import { tabHeaders } from "@provenanceauth/rails/tabs";

await fetch("https://api.saltmarsh.example/lookup?domain=quillstack.example", { headers: tabHeaders(tab.tab_token) });

tabHeaders sets Provenance-Tab: <tab token>.

4. Check each call offline (seller)

Keep the revocation list fresh with RevocationCache, then check each call with verifyTab:

import { RevocationCache, verifyTab } from "@provenanceauth/rails/tabs";

const revocations = new RevocationCache({ apiBase: process.env.PROVENANCE_API!, aud: agentId, jwks });
revocations.start(); // refreshes at each next_update, with If-None-Match

const r = await verifyTab(req.headers["provenance-tab"], { jwks, seller: agentId, revocations: revocations.current(), amount: 0.002 });
if (!r.valid) return res.status(402).json({ error: r.reason });

verifyTab checks our signature and expiry, that the token is for your agent, the call's price against max_per_call, and the list: closed and revoked tabs, revoked grants and agent sessions, and tabs paused for the day. The list is keyless at GET /v1/public/revocations, signed with the key in our JWKS, and refreshes every 60 seconds by default.

The bound after a revoke. Between a revoke and your next refresh, calls on that tab still pass your check. The most that can pass is max_per_call × your call rate × the refresh interval: with max_per_call at 0.01, 20 calls a second and a 60-second refresh, that's 12 in the tab's currency. Subscribe to the authorize.tab.revoked webhook to stop sooner. If your list is older than 3 refresh intervals, verifyTab refuses with revocations_stale: stop serving until it refreshes.

5. Post usage statements (seller)

Post a signed statement at least every 5 minutes while the tab is in use, and whenever usage passes another 20% of the daily cap. createTabMeter tells you when one is due:

import { createTabMeter, signUsageStatement } from "@provenanceauth/rails/tabs";

const meter = createTabMeter({ dailyCap: 40 });
// on each served call:
const period = meter.record(0.002);
if (period) {
  const { statement } = await signUsageStatement({ iss: agentId, tab_id: tabId, ...period }, privateJwk);
  await fetch(`${process.env.PROVENANCE_API}/v1/authorize/tabs/${tabId}/usage`, {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ ...period, statement }),
  });
}

Each period starts at or after the last one's end and stays within one UTC day. A statement that would take the day past daily_cap is refused with tab_cap_exceeded, nothing from it is recorded, and the tab is paused until the next UTC day (the list names it in paused). You pay per 10,000 calls in your statements.

6. Count on your side too (buyer)

Your SDK may post its own count with { period_start, period_end, buyer_calls } to POST /v1/authorize/tabs/{id}/usage. When the day settles, a gap over 2% between the two counts marks the day contested and sends authorize.tab.contested to both sides.

Days and budgets

Each UTC day the tab is used reserves daily_cap from the grant's budget window. The open reserves the first day; the first statement or count of a later day reserves that one. An hour after a day ends, it settles: what the statements didn't use goes back to the budget, and the day is ledgered once (one row per tab per day). When the budget can't cover a day, the tab is paused for that day.

7. Close

Either side closes with POST /v1/authorize/tabs/{id}/close. Revoking the grant, the agent session or the token closes it too, and the seller gets authorize.tab.revoked. Statements for periods before the close are accepted for 10 more minutes.

Errors you might see

CodeWhat to do
offer_invalidThe price sheet must be a signed offer with delivery.kind: "service".
grant_invalidOpen the tab under an active grant of your account.
tab_statement_invalidSign each period after the previous one, within one UTC day, at no more than max_per_call per call.
tab_cap_exceededStop serving on this tab until the next UTC day.
tab_closedThe tab is closed or expired; the buyer opens a new one.

See also