const { result, error } = await unprice.analytics.getUsage({
  projectId: "project_1234567890",
  range: "24h",
  customerId: "cus_1234567890" // optional
});

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}

console.log(result);
{
  "usage": [
    {
      "projectId": "project_1234567890",
      "customerId": "cus_1234567890",
      "entitlementId": "ent_1234567890",
      "featureSlug": "feature_1",
      "count": 100,
      "sum": 1000,
      "max": 50,
      "last_during_period": 30
    }
  ]
}
const { result, error } = await unprice.analytics.getUsage({
  projectId: "project_1234567890",
  range: "24h",
  customerId: "cus_1234567890" // optional
});

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}

console.log(result);
{
  "usage": [
    {
      "projectId": "project_1234567890",
      "customerId": "cus_1234567890",
      "entitlementId": "ent_1234567890",
      "featureSlug": "feature_1",
      "count": 100,
      "sum": 1000,
      "max": 50,
      "last_during_period": 30
    }
  ]
}

Request

projectId
string
required

The ID of the project to get usage for

range
string
required

The time range to get usage for (last hour, day, week, month, or 3 months)

customerId
string

The ID of the customer to get usage for (optional)

Response

usage
array
required

Array of usage data points

usage[].projectId
string
required

The ID of the project

usage[].customerId
string

The ID of the customer

usage[].entitlementId
string

The ID of the entitlement

usage[].featureSlug
string
required

The slug of the feature

usage[].count
number
required

The number of usage events

usage[].sum
number
required

The sum of all usage values

usage[].max
number
required

The maximum usage value

usage[].last_during_period
number
required

The last usage value during the period