Before you begin
- An application instrumented with Monocle via
setup_monocle_telemetry(...) - A Paygentic account (or sandbox account for testing)
- An API key with
events:createpermission
Step 1: Define a Product and Billable Metric
In the Paygentic dashboard, create a product (for example, “Monocle Agent”) and a billable metric that matches the Monocle span you want to bill on. The Paygentic exporter derives the eventtype from the span’s entity.1.type attribute, prefixed with ai.. For example, an OpenAI chat completion (entity.1.type = "inference.openai") arrives at Paygentic with type = "ai.inference.openai".
Map Monocle spans to billable-metric fields as follows:
| Field | Value for Monocle | Example |
|---|---|---|
eventType | ai. + the Monocle entity type | ai.inference.openai |
valueProperty | JSONPath into the span’s metadata event | $.total_tokens |
groupBy | Optional dimensions you care about | { "model": "$.model_name" } |
eventType has no matching metric are rejected with 422 and suppressed for an hour.
When you use a framework like LangChain or LlamaIndex, the event type still reflects the underlying provider — a LangChain
ChatOpenAI call emits ai.inference.openai, a ChatAnthropic call emits ai.inference.anthropic, and so on. Unknown or unmapped LLM clients fall back to ai.inference.generic.data payload contains the attributes from the span’s metadata event (plus span_id, trace_id, and name). Common metadata fields across Monocle’s provider integrations include total_tokens, completion_tokens, prompt_tokens, and model_name.
See Meter Events for the full list of aggregation options and JSONPath rules.
Monocle spans can also feed a cost metric alongside your billable metric, so the same event drives both customer billing and internal margin tracking.
Step 2: Enable the Paygentic Exporter
Configure the exporter via environment variables:sk_test_ and live keys sk_live_. When targeting the sandbox, also set PAYGENTIC_SANDBOX=true so events are routed to api.sandbox.paygentic.io. See Environments for details.
Then add the paygentic exporter to your Monocle setup call:
By default the exporter only exports
inference spans — other Monocle span types are filtered out. The event source field defaults to "monocle"; override it per-app with PAYGENTIC_SOURCE=my-app.Step 3: Attach Subscriptions via Trace Scopes
The exporter sets each event’ssubject from a Monocle trace scope. It checks subscriptionId first, then falls back to customerId. If neither scope is set on the span, the event is dropped.
Create a customer, subscribe them to a plan with a price on your Monocle metric, then tag traces with the subscription id before your instrumented workload runs:
Troubleshooting
- Events aren’t showing up in the Meters view. Confirm your billable metric’s
eventTypematches theai.-prefixed type the exporter emits (e.g.ai.inference.openai, notinference.openai). Events with an unknowntypeare rejected with422and temporarily suppressed by the exporter. - No subject resolved errors in application logs. The span has no
subscriptionIdorcustomerIdscope — wrap the traced call inmonocle_trace_scope(...). - Sandbox key with live endpoint (or vice versa). Set
PAYGENTIC_SANDBOX=truewhen using ansk_test_key.
Next steps
- Billable Metrics — pricing models and aggregation options for metered usage
- Cost Tracking — track provider costs alongside customer billing
- Customer Lifecycle — how subscriptions activate and renew