---
title: "Record a metered usage event"
description: "Send an Idempotency-Key header or a body idempotency_key."
canonical_url: "https://twominutebilling.com/help/developers/api-reference/subscriptions/record-a-metered-usage-event"
---
# Record a metered usage event

> Send an Idempotency-Key header or a body idempotency_key.

<api-operation method="POST" path="/v1/businesses/{biz}/subscriptions/{sub}/usage">
<template v-slot:docs="">

Send an `Idempotency-Key` header or a body `idempotency_key`. Without a header, the body key is used as the request key for this item. A repeat with the same key and the same values returns the first record. A repeat with the same key and different values is refused with 409.

`timestamp` must be in the period that the next invoice bills: from the start of the current billing period (or of the open pending invoice's usage window, when that is earlier) to 5 minutes after the current time. A timestamp in a period that is already invoiced, before the subscription starts, or more than 5 minutes in the future is refused with 400. The error message gives the accepted window. For a time-travelled test business, the current time is its simulated time.

## Path parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        biz
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <strong>
        yes
      </strong>
    </td>
    
    <td>
      Business id (biz_…)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sub
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <strong>
        yes
      </strong>
    </td>
    
    <td>
      Subscription id (sub_…)
    </td>
  </tr>
</tbody>
</table>

## Headers

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        Idempotency-Key
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      Safely retry writes — repeats return the original response. If a write FAILED after it had already taken effect, that failure is what repeats: the key is spent, and a new attempt needs a new key.
    </td>
  </tr>
</tbody>
</table>

## Body

The request body is **required**.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        item
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <strong>
        yes
      </strong>
    </td>
    
    <td>
      The subscription item's id (si_…).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quantity
      </code>
    </td>
    
    <td>
      <code>
        integer
      </code>
    </td>
    
    <td>
      <strong>
        yes
      </strong>
    </td>
    
    <td>
      From -10^12 to 10^12. Negative only for a recurring sum or a weighted_sum price (a delta that lowers the level).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        unique_key
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      For <code>
        unique
      </code>
      
       aggregation (e.g. distinct user id)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        operation
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      <code>
        remove
      </code>
      
       takes <code>
        unique_key
      </code>
      
       off a unique metric (a seat leaves). Only for a unique price, and needs <code>
        unique_key
      </code>
      
      . One of <code>
        add
      </code>
      
      , <code>
        remove
      </code>
      
      . Defaults to <code>
        "add"
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        timestamp
      </code>
    </td>
    
    <td>
      <code>
        string · ISO-8601
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      When the usage happened (ISO-8601 UTC). Default: now. It must be in the period that the next invoice bills, and not more than 5 minutes in the future.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        idempotency_key
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      Identifies this usage event on this item. It is the request key when there is no <code>
        Idempotency-Key
      </code>
      
       header. A reuse with different values is refused with 409.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        note
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      no
    </td>
    
    <td>
      Operator note, returned by the usage API and never printed on a customer document. Echoed in this response only when set.
    </td>
  </tr>
</tbody>
</table>

## Response

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        object
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The object type; always <code>
        usage_record
      </code>
      
      . One of <code>
        usage_record
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The usage record id.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        item
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The subscription item id.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quantity
      </code>
    </td>
    
    <td>
      <code>
        integer
      </code>
    </td>
    
    <td>
      The quantity recorded.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        operation
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Present only for a remove.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        timestamp
      </code>
    </td>
    
    <td>
      <code>
        string · ISO-8601
      </code>
    </td>
    
    <td>
      When the usage happened.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        note
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      The note on the event, if you sent one.
    </td>
  </tr>
</tbody>
</table>

## Status codes

<table>
<thead>
  <tr>
    <th>
      Status
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        201
      </code>
    </td>
    
    <td>
      Usage recorded
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        400
      </code>
    </td>
    
    <td>
      The body is not correct, the timestamp is outside the accepted window, or there is no idempotency key
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        404
      </code>
    </td>
    
    <td>
      No such subscription/item
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        409
      </code>
    </td>
    
    <td>
      The idempotency key is in progress, or was used before with different values
    </td>
  </tr>
</tbody>
</table>
</template>

<template v-slot:request="">

```bash [Request]
curl -X POST "$TMBILLING_URL/v1/businesses/biz_XXXXXXXXXXXX01/subscriptions/sub_XXXXXXXXXXXX01/usage" \
  -H "Authorization: Bearer $TMBILLING_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "item": "si_XXXXXXXXXXXX01",
    "quantity": 1
  }'
```

</template>

<template v-slot:response="">
<code-group>

```json [201 Created]
{
  "object": "usage_record",
  "id": "ur_XXXXXXXXXXXX01",
  "item": "si_XXXXXXXXXXXX01",
  "quantity": 250,
  "operation": "remove",
  "timestamp": "2026-03-14T09:30:00Z",
  "note": "Requested by the customer."
}
```

```json [400 Bad Request]
{
  "error": {
    "type": "idempotency_error",
    "message": "The body is not correct, the timestamp is outside the accepted window, or there is no idempotency key"
  }
}
```

```json [404 Not Found]
{
  "error": {
    "type": "invalid_request_error",
    "message": "No such subscription/item"
  }
}
```

```json [409 Conflict]
{
  "error": {
    "type": "idempotency_error",
    "message": "The idempotency key is in progress, or was used before with different values"
  }
}
```

</code-group>
</template>
</api-operation>


## Sitemap

See the full [sitemap](https://twominutebilling.com/sitemap.md) for all pages.
