const { result, error } = await unprice.customers.reportUsage({
  customerId: "cus_1234567890",
  featureSlug: "tokens",
  usage: 30,
  idempotenceKey: "123e4567-e89b-12d3-a456-426614174000",
  metadata: {
    action: "create",
    country: "US"
  }
});

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);
{
  "success": true,
  "message": "Usage reported successfully",
  "cacheHit": false,
  "remaining": 970
}
const { result, error } = await unprice.customers.reportUsage({
  customerId: "cus_1234567890",
  featureSlug: "tokens",
  usage: 30,
  idempotenceKey: "123e4567-e89b-12d3-a456-426614174000",
  metadata: {
    action: "create",
    country: "US"
  }
});

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);
{
  "success": true,
  "message": "Usage reported successfully",
  "cacheHit": false,
  "remaining": 970
}

Request

customerId
string
required

The ID of the customer to report usage for

featureSlug
string
required

The slug of the feature to report usage for

usage
number
required

The amount of usage to report

idempotenceKey
string
required

A unique key to prevent duplicate usage reports

metadata
object

Additional metadata about the usage report

Response

success
boolean
required

Whether the usage was reported successfully

message
string

A message describing the result of the operation

cacheHit
boolean

Whether the request was served from cache

remaining
number

The remaining usage limit for the feature