Tracking Usage
You will learn the following:
- Track usage events and apply fallback charges
- Retrieve usage summaries and apply fallback charges
- Track usage and apply fallback charges in your own backend
Before you start
Endpoint: Post Usage Events
This endpoint allows you to submit usage events for your customers.
HTTP Method
POST
URL
https://api.plandalf.com/v1/usage/events
Headers
Authorization: Bearer <API_KEY>
Content-Type: application/json
orapplication/x-www-form-urlencoded
Request Body
The request body can be either JSON-encoded or form-encoded. It should contain either a single event object or an array of event objects.
Event Structure
Field | Type | Optional | Description |
---|---|---|---|
event | string | No | The type of event. In this case, it should be "FeatureUsageEvent". |
id | string | No | A unique identifier for the event (any format). |
user | string | No | The user identifier associated with the event. |
quantity | number | Yes | The quantity of the event (default is 1). |
customer | string | No | The customer identifier from your Billing Service Provider. |
properties | object | Yes | Additional properties related to the event. |
timestamp | number | Yes | The Unix timestamp of when the event occurred. |
Example Request
POST /v1/usage/events HTTP/1.1
Host: api.plandalf.com
Authorization: Bearer your_api_key_here
Content-Type: application/json
[
{
"event": "FeatureUsageEvent",
"id": "6f8978aa-8676-11ef-b864-0242ac120002",
"user": "6706dca2efcdee6a019840e5",
"quantity": 1,
"customer": "cust_oyN54LsjNtr9uC00",
"properties": {
"greeting": "hello"
},
"timestamp": 1728502852
}
]
Response
The API response structure is not specified in the provided information. Typically, a successful response would include a status code (e.g., 200 OK) and potentially a JSON body with details about the processed events.
Usage Summary API
The Usage Summary endpoint allows you to retrieve a detailed report of usage and associated fees for a given customer within a specified date range. This endpoint is useful for tracking customer usage, calculating fees, and applying fallback charges if minimum thresholds are not met.
HTTP Method
GET
URL
https://api.plandalf.com/v1/customers/\{customer_id}/usage
Replace {customer_id}
with the ID of the customer whose usage summary you wish to retrieve.
Headers
Authorization: Bearer <API_KEY>
Content-Type: application/json
Response Structure
The response will contain an object with the following fields:
Field | Type | Description |
---|---|---|
period_start_at | integer | The start timestamp of the usage period in Unix format. |
period_end_at | integer | The end timestamp of the usage period in Unix format. |
amount | integer | The total charge amount for the period. |
currency | string | The currency of the charge (e.g., USD , AUD ). |
fees | array | An array of fee details applied to the usage, each with charge and metric information. |
Field | Type | Description |
---|---|---|
amount | string | The amount charged for the usage. |
description | string | A description of the fee. |
charge | object | Details about the associated charge, including name, type, and currency. |
metric | object | Details about the metric used, such as event name, aggregation type, and metric type. |
Example Resposne
{
"period_start_at": 1728502852,
"period_end_at": 1728502852,
"amount": 500,
"currency": "USD",
"fees": [
{
"amount": "500",
"description": null,
"usage": 123,
"charge": {
"name": "fallback charge",
"invoicing_interval": null,
"currency": "AUD",
"type": "standard",
"amount_minimum_spend": "500",
"minimum_billable_usage": null,
"amount": "5",
"mode": "in_arrears"
},
"metric": {
"id": "metric_1CH9XvWgnP4kjdfQvQSLGY",
"event_name": "fallback_video_sent",
"aggregation": "COUNT",
"type": "persistent"
}
}
]
}
Error Handling
Error responses are not specified in the provided information. Common HTTP status codes for errors might include:
- 400 Bad Request: Invalid input
- 401 Unauthorized: Invalid or missing API key
- 429 Too Many Requests: Rate limit exceeded
- 500 Internal Server Error: Server-side issues
For more detailed information about error responses, please refer to the full API documentation or contact the API provider.