Send usage events to Metering & Billing using the CloudEvents format.
Each event represents a user interaction in your application.
The meter counts each unique user_id value once per billing period.
To validate, we’ll send events for three distinct users: alice, bob, and carol.
Important: When you send events, they must have a unique id. Metering & Billing deduplicates events with the same id.
- Export the current time:
export EVENT_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
Metering & Billing only invoices and meters events that are sent after the subscription is created.
-
Send an event for alice:
curl -X POST "https://us.api.konghq.com/v3/openmeter/events" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/cloudevents+json" \
--json '{
"specversion": "1.0",
"type": "user_activity",
"id": "57B5F342-B8D5-49AE-9D6C-350C1D92155C",
"source": "acme-platform",
"time": "'$EVENT_TIME'",
"datacontenttype": "application/json",
"subject": "acme-inc",
"data": {
"user_id": "alice"
}
}'
-
Send an event for bob:
curl -X POST "https://us.api.konghq.com/v3/openmeter/events" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/cloudevents+json" \
--json '{
"specversion": "1.0",
"type": "user_activity",
"id": "F388B902-7A82-4C40-BC89-448CFA5DDC1B",
"source": "acme-platform",
"time": "'$EVENT_TIME'",
"datacontenttype": "application/json",
"subject": "acme-inc",
"data": {
"user_id": "bob"
}
}'
-
Send an event for carol:
curl -X POST "https://us.api.konghq.com/v3/openmeter/events" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/cloudevents+json" \
--json '{
"specversion": "1.0",
"type": "user_activity",
"id": "46C16EE0-6174-4336-A539-AEC3AD1E0485",
"source": "acme-platform",
"time": "'$EVENT_TIME'",
"datacontenttype": "application/json",
"subject": "acme-inc",
"data": {
"user_id": "carol"
}
}'
-
Now, send a second event for alice to confirm that UNIQUE_COUNT doesn’t duplicate repeated users:
curl -X POST "https://us.api.konghq.com/v3/openmeter/events" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN"\
-H "Content-Type: application/cloudevents+json" \
--json '{
"specversion": "1.0",
"type": "user_activity",
"id": "2843D4B1-C8F8-408E-9F28-6D4EB44E5A8B",
"source": "acme-platform",
"time": "'$EVENT_TIME'",
"datacontenttype": "application/json",
"subject": "acme-inc",
"data": {
"user_id": "alice"
}
}'
Even though four events were sent, the meter counted only three unique users. Now check the invoice:
- In the Konnect sidebar, click Metering & Billing.
- In the Metering & Billing sidebar, click Billing.
- Click Acme Inc.
- Click the Invoicing tab.
- Click Preview Invoice.
You’ll see active-users listed in Lines with a quantity of 3, reflecting three unique active users.
In this guide, you’re using the sandbox for invoices.
To deploy your subscription in production, configure a payments integration in Metering & Billing > Settings, like Stripe.