Recording Usage Metrics

What is happening in your API?

Usage Metrics are at the core of usage-based billing. They define how customers are billed and what should be displayed in dashboards. You'll send usage metrics to Kable as things happen inside your API. There are two ways to send usage metrics to Kable:

Kable SDKs

Libraries are the best way to record usage metrics in Kable. They are easy to implement, and are instrumented to minimize latency impacts to your API.

Configuring the Library

When initializing a Kable instance in your application, a few configurations are available to you to tune Kable to your desired settings:

  • debug: When set to true, the library will print helpful messages to your logs. These messages can be noisy, so we don't recommend this setting for production, but it can be very helpful when first setting up Kable.
  • maxQueueSize / max_queue_size: As mentioned above, Kable libraries buffer events before posting data back to Kable's servers. By default, maxQueueSize is set to 10. But you may choose to decrease or increase this setting to send events to Kable more or less often, respectively.
const kable = new Kable({
  kableClientId: '<YOUR_KABLE_CLIENT_ID>',
  kableClientSecret: '<YOUR_KABLE_CLIENT_SECRET>',
  baseUrl: '',
  debug: true,
  maxQueueSize: 3
kable = Kable({
  'kable_client_id': '<YOUR_KABLE_CLIENT_ID>',
  'kable_client_secret': '<YOUR_KABLE_CLIENT_SECRET>',
  'base_url': '',
  'debug': True,
  'max_queue_size': 3

Recording Metrics

record is at the heart of each Kable library. It wraps the events API and uses a buffer to collect many events before posting data back to Kable. A sample record call may look like the following:

  clientId: 'yourcompanyuser_1234567890', 
  userId: 'xyz123',
  messageId: 'msg_ABC123XYZ456', 
  objectCount: 12, 
  transactionCost: 399.99
  "clientId": "yourcompanyuser_1234567890", 
  "userId": "xyz123",
  "messageId": "msg_ABC123XYZ456", 
  "objectCount": 12, 
  "transactionCost": 399.99

You should always include a customer's clientId in calls to record. The client ID tells Kable to which customer to attribute the event.


Kable currently supports libraries for Node and Python. We are working to support additional languages, and if your language of choice is not yet supported, you can call the Kable API directly.

If you decide to write a library for a language we don't yet offer, we would happily support it moving forward. You can find examples of our existing libraries for inspiration on GitHub.

Kable API

If we don't yet support your chosen programming language, you can record usage metrics to Kable through the events API. Additional details can be found in the API Reference.

Did this page help you?