AI agent and MCP metering
Record completed MCP tool calls or agent runs as usage events, route them through the customer subscription and tool-specific meter/product-item keys you configure, and keep a retry-safe ledger before pricing or payment logic gets involved.
A tool invocation, completed run or another outcome can be the usage signal. Decide that policy in your application, then report the numeric event consistently instead of inferring it later from logs.
Use a customer subscription ingest key, then route distinct billable tool streams through the product item and meter keys you configure. The usage endpoint stays the same across those streams.
Derive or store a stable idempotency key for the logical billable event. If a producer retries delivery, reuse the same key rather than creating another unit of usage.
UsageBox records the values you send; it does not decide whether a partial or failed agent action should be billable. Emit usage according to the commercial policy your product actually promises.
Use the retained events and rollups as the quantity layer, then let Stripe, another billing system or your own code apply per-call prices, subscriptions, credits or invoice rules.
OAuth, API keys, rate limiting and MCP transport concerns can evolve independently from the usage ledger. The metering contract only needs the authenticated producer and the usage event.
Implementation pattern
Use the customer subscription plus the product item and meter that represent the tool stream. Your application decides whether a call is billable before it emits the usage event.
A transport retry of this same tool-call event should reuse the same idempotency key so it cannot become a second unit of usage.
curl -X POST 'https://api.usagebox.com/api/v1/usage' \
-H 'x-api-key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-H "Idempotency-Key: $(uuidgen)" \
-d '[{"subscription":"sub_customer-acme-...","product_item":"item_search-tool-...","meter":"meter_tool-calls-...","value":1}]'Product boundary
The product deliberately owns usage evidence and aggregation. MCP authentication, authorization, quotas, rate limiting, pricing, invoices and payments remain separate concerns.
Choose the usage signal, inspect the exact payload, then create a free key only when the contract fits your integration.