API Version
Product Catalog
Library

This resource allows you to record usage events, which are essential for usage-based billing. These events track customer consumption and calculate charges based on actual usage. You can send usage data to Chargebee using two endpoints: Ingest a Usage Event for individual events and Ingest Usage Events in Batch for bulk submissions.

The usage event resource payload is schema-less, providing the flexibility to adapt to your unique business requirements. Because usage events are not directly tied to a pricing plan, this resource enables independent tracking of feature consumption. Events are processed and associated with relevant features as usage data. This information is used for billing alongside entitlements, items(such as plans or addons), or item prices to generate invoices. This decoupling of usage data from the product catalog provides flexibility in defining and monetizing usage beyond predefined pricing models. Additionally, this API supports feature usage analytics, churn prediction, and other insights.

Note:
  • Learn more about the use cases associated with this resource.
  • Learn more about the Usage-based Billing.

Sample usage event [ JSON ]

{ "usage_timestamp": "179506024062", "subscription_id": "SUB-1", "deduplication_id": "usage-301513005", "properties": { "input_tokens": 1100, "output_tokens": 7400, "token_ratio": 6.73, "model_name": "gpt-3.5", "prompt_type": "code_completion", "temperature": 0.6, "top_p": 0.85, "frequency_penalty": 0.4, "presence_penalty": 0.15, "fine_tuned": false, "response_time_ms": 180, "completion_success_rate_percent": 99.1, "api_endpoints": "generateCompletion", "cpu_usage_percent": 65, "memory_usage_mb": 2200, "webhook_events_sent": 45 } }

API Index URL GET

https://{site}.ingest.chargebee.com/api/v2/usage_events

Model Class

subscription_id
string, max chars=50
The unique identifier of a subscription.
deduplication_id
string, max chars=36

An identifier used by the Chargebee's customer to distinguish between multiple events generated at the same timestamp for a single subscription_id.
The combination of usage_timestamp, subscription_id, and deduplication_id uniquely identifies each event.

Example:

If 3 events are generated for subscription_id = sub-1 at 2025-04-01T00:00:00.000Z, each event must have a distinct deduplication_id.


usage_timestamp
long
The timestamp indicating when this usage occurred, represented as Epoch time in milliseconds.
Example: 1738732394123 represents the timestamp for February 5, 2025, at 05:13:14.123 UTC.
Note: The timestamp must be within the last 12 hours.

properties
jsonobject

A schema-less field that accepts any JSON-formatted data to define the attributes of the ingested event. It is a requirement to structure the data in a flat format wherever possible for better compatibility with downstream processing.

We strongly encourage using unique field names—particularly for fields intended for metering purposes. This approach enhances clarity and maintainability in the future.

For example, a field named status,

  • Can represent string values such as accepted or processing in one context.

  • In another scenario, it might hold numeric values, such as HTTP response codes like 200, 300, or 400.

Note: There is a size limit of 1 KB.

subscription_id subscription_id
string, max chars=50
The unique identifier of a subscription.
deduplication_id deduplication_id
string, max chars=36

An identifier used by the Chargebee's customer to distinguish between multiple events generated at the same timestamp for a single subscription_id.
The combination of usage_timestamp, subscription_id, and deduplication_id uniquely identifies each event.

Example:

If 3 events are generated for subscription_id = sub-1 at 2025-04-01T00:00:00.000Z, each event must have a distinct deduplication_id.


usage_timestamp usage_timestamp
long
The timestamp indicating when this usage occurred, represented as Epoch time in milliseconds.
Example: 1738732394123 represents the timestamp for February 5, 2025, at 05:13:14.123 UTC.
Note: The timestamp must be within the last 12 hours.

properties
jsonobject

A schema-less field that accepts any JSON-formatted data to define the attributes of the ingested event. It is a requirement to structure the data in a flat format wherever possible for better compatibility with downstream processing.

We strongly encourage using unique field names—particularly for fields intended for metering purposes. This approach enhances clarity and maintainability in the future.

For example, a field named status,

  • Can represent string values such as accepted or processing in one context.

  • In another scenario, it might hold numeric values, such as HTTP response codes like 200, 300, or 400.

Note: There is a size limit of 1 KB.

This endpoint ingests a usage event into Chargebee.

Note:
  • A single event can be of 1 KB in size.

  • Limit: 10,000 events per minute.

Notes

Sample Request
Try in API Explorer
curl  https://{site}.ingest.chargebee.com/api/v2/usage_events \
     -u {site_api_key}:\
     --header 'Content-Type: application/json;charset=UTF-8' \
     --data '{
     "deduplication_id": "usage-6315161283",
     "subscription_id": "S-300000001",
     "usage_timestamp": "1737612931000",
     "properties": {
          "input_tokens": 1200,
          "output_tokens": 7200,
          "token_ratio": 6,
          "model_name": "gpt-4",
          "prompt_type": "text_completion",
          "temperature": 0.8,
          "top_p": 0.9,
          "frequency_penalty": 0.2,
          "presence_penalty": 0.1,
          "fine_tuned": false,
          "response_time_ms": 150,
          "completion_success_rate_percent": 98.6,
          "api_endpoints": "generateCompletion",
          "cpu_usage_percent": 68,
          "memory_usage_mb": 2100,
          "webhook_events_sent": 42
     }
}'
copy
Click to Copy

Sample Response [ JSON ]

Show more...
{
    "usage_event": {
        "deduplication_id": "usage-6315161283",
        "subscription_id": "S-300000001",
        "usage_timestamp": "1737612931000",
        "properties": {
            "input_tokens": 1200,
            "output_tokens": 7200,
            "token_ratio": 6,
            "model_name": "gpt-4",
            "prompt_type": "text_completion",
            "temperature": 0.8,
            "top_p": 0.9,
            "frequency_penalty": 0.2,
            "presence_penalty": 0.1,
            "fine_tuned": false,
            "response_time_ms": 150,
            "completion_success_rate_percent": 98.6,
            "api_endpoints": "generateCompletion",
            "cpu_usage_percent": 68,
            "memory_usage_mb": 2100,
            "webhook_events_sent": 42
        }
    }
}

URL Format POST

https://{site}.ingest.chargebee.com/api/v2/usage_events

Method

deduplication_id[]
required, string, max chars=36

An identifier used by the Chargebee's customer to distinguish between multiple events generated at the same timestamp for a single subscription_id.
The combination of usage_timestamp, subscription_id, and deduplication_id uniquely identifies each event.

Example:

If 3 events are generated for subscription_id = sub-1 at 2025-04-01T00:00:00.000Z, each event must have a distinct deduplication_id.

subscription_id[]
required, string, max chars=50

The unique identifier of a subscription.

Note:
  • If an existing subscription_id is provided, usage data is recorded against it.
  • If the subscription does not exist yet in Chargebee, a new subscription_id can be used, and the subscription can be imported later, once the usage is successfully recorded.
  • During invoice generation, recorded usage linked to the subscription_id will be applied to the invoice.
usage_timestamp[]
required, long
The timestamp indicating when this usage occurred, represented as Epoch time in milliseconds.
Example: 1738732394123 represents the timestamp for February 5, 2025, at 05:13:14.123 UTC.
Note: The timestamp must be within the last 12 hours.
properties[]
required, jsonobject

A schema-less field that accepts any JSON-formatted data to define the attributes of the ingested event. It is a requirement to structure the data in a flat format wherever possible for better compatibility with downstream processing.

We strongly encourage using unique field names—particularly for fields intended for metering purposes. This approach enhances clarity and maintainability in the future.

For example, a field named status,

  • Can represent string values such as accepted or processing in one context.

  • In another scenario, it might hold numeric values, such as HTTP response codes like 200, 300, or 400.

Note: There is a size limit of 1 KB.
usage_event usage_event
always returned
Resource object representing usage_event

Sample admin console URL

https://{site}.chargebee.com/admin-console/usage_events/123x

This endpoint ingests a batch of usage events into Chargebee.

Note:
  • You can ingest 500 events in a batch ingestion, each 1 KB in size. This means a single API request will efficiently handle 500 KB of data.

  • Limit: 10,000 events per minute.

Notes

Sample Request
Try in API Explorer
curl  https://{site}.ingest.chargebee.com/api/v2/batch/usage_events \
     -u {site_api_key}:\
     --header 'Content-Type: application/json;charset=UTF-8' \
     --data '{
     "events": [
          {
               "deduplication_id": "70bf7765-a0a6-457b-8786-9f20378b0t14",
               "subscription_id": "S-300000001",
               "usage_timestamp": "1736076560644",
               "properties": {
                    "input_tokens": 1340,
                    "output_tokens": 6800,
                    "token_ratio": 5.07,
                    "model_name": "gpt-4-turbo",
                    "prompt_type": "chat_completion",
                    "temperature": 0.7,
                    "top_p": 0.8,
                    "frequency_penalty": 0.3,
                    "presence_penalty": 0.2,
                    "fine_tuned": true,
                    "response_time_ms": 140,
                    "completion_success_rate_percent": 96.2,
                    "api_endpoints": "generateSummary",
                    "cpu_usage_percent": 72,
                    "memory_usage_mb": 1950,
                    "webhook_events_sent": 38
               }
          },
          {
               "deduplication_id": "70bf7765-a0a6-457b-8786-9f20378b0f09",
               "subscription_id": "S-300000007",
               "usage_timestamp": "1736076560644",
               "properties": {
                    "input_tokens": 1100,
                    "output_tokens": 7400,
                    "token_ratio": 6.73,
                    "model_name": "gpt-3.5",
                    "prompt_type": "code_completion",
                    "temperature": 0.6,
                    "top_p": 0.85,
                    "frequency_penalty": 0.4,
                    "presence_penalty": 0.15,
                    "fine_tuned": false,
                    "response_time_ms": 180,
                    "completion_success_rate_percent": 99.1,
                    "api_endpoints": "generateCompletion",
                    "cpu_usage_percent": 65,
                    "memory_usage_mb": 2200,
                    "webhook_events_sent": 45
               }
          }
     ]
}'
copy
Click to Copy

Sample Response [ JSON ]

Show more...
{
    "batch_id": "178be7d4-9723-480e-ac18-cf7916181646",
    "failed_events": [
        {
            "subscription_id": "448000000002",
            "usage_timestamp": "1736076560644",
            "properties": {
                "input_tokens": 1340,
                "output_tokens": 6800,
                "token_ratio": 5.07,
                "model_name": "gpt-4-turbo",
                "prompt_type": "chat_completion",
                "temperature": 0.7,
                "top_p": 0.8,
                "frequency_penalty": 0.3,
                "presence_penalty": 0.2,
                "fine_tuned": true,
                "response_time_ms": 140,
                "completion_success_rate_percent": 96.2,
                "api_endpoints": "generateSummary",
                "cpu_usage_percent": 72,
                "memory_usage_mb": 1950,
                "webhook_events_sent": 38
            }
        },
        {..}
    ]
}

URL Format POST

https://{site}.ingest.chargebee.com/api/v2/batch/usage_events

Method

deduplication_id
required, string, max chars=36
subscription_id
required, string, max chars=50
usage_timestamp
required, timestamp(UTC) in seconds
properties
required, jsonobject
batch_id batch_id
required, string, max chars=36
The unique identifier for the batch of usage events processed.
failed_events failed_events
required, jsonarray
A detailed list of events that failed during the batch ingestion process.

Sample admin console URL

https://{site}.chargebee.com/admin-console/usage_events/123x