Agentic APIs: Trace-Based Metering
Meter the APIs that AI agents call autonomously — one billable event per request, correlated by distributed trace, priced per endpoint.
What are Agentic APIs#
An Agentic API is an API endpoint that AI agents consume autonomously — without a human clicking a button for each request. Where a standard API sees a developer call POST /search once per user query, an agentic workflow might invoke that same endpoint forty times inside a single planning loop.
Aforo meters this by tying every one of those calls back to the distributed trace that produced them. Each inbound request is a billable event; the trace id correlates the whole agent run so you can see — and price — the endpoints an agent actually hit.
Customer → Team → App → API Key hierarchy. There is no separate agent registration or client-credentials exchange — that model belongs to the and AI Agent product types.Identity & auth#
An Agentic API call authenticates with a Bearer API key — the same sk_live_… key format used everywhere in Aforo. Usage attributes up the hierarchy: the key belongs to an App, the app to a Team, the team to a Customer. That's how a bill run rolls an agent's traffic up to the right customer.
Trace-based metering#
There is no session lifecycle for an Agentic API — no session-start, no idle timeout, no session-end. Aforo aggregates usage by trace id instead. Every inbound request carrying a distributed-trace header becomes one metered event, and Aforo groups events that share a trace id so an entire agent run reads as a single correlated unit.
How the trace id is read
Aforo reads the W3C traceparent header and extracts its 32-character trace-id field. If traceparent is absent, it falls back to a plain x-trace-id header. A malformed traceparent is ignored rather than guessed at — the event still meters, it just isn't trace-correlated.
traceparent format is version-traceId-parentId-flags. Most agent frameworks and OpenTelemetry SDKs set it automatically on outbound calls, so in practice you get trace correlation for free.Per-endpoint pricing#
Not every endpoint costs the same to serve — a lightweight /search is far cheaper than a /code/execute that spins up a sandbox. Agentic API's billing dimension is the endpoint path, so dimension pricing sets a distinct multiplier per endpoint within one rate plan.
Each value is a multiplier on the plan's base rate — /v1/code/execute above bills at 12× the base per-unit price. An endpoint without an entry bills at the base rate (multiplier 1.0). This is the same dimensionPricing mechanism MCP servers use for per-tool rates — Agentic API keys it on endpoint path, MCP keys it on tool name.
endpoint_path on the usage event. Multipliers apply only when the metric's pricing model is PER_UNIT with no included free tier — for tier- or allowance-based models the aggregate rate applies, since per-endpoint fan-out would misprice a shared allowance. See for the full model semantics.Integration#
The zero-code path is a . Every Aforo gateway plugin (Kong, Apigee, AWS, Azure, MuleSoft) detects the traceparent header, classifies the request as an Agentic API event, and emits it with the endpoint path attached — no application code changes.
If you meter in code instead, use the base metering SDK and set the endpoint path as the metric so per-endpoint pricing resolves:
await aforo.shutdown() (or flush()) in your process shutdown handler so no buffered events are lost.