> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Enforce metered feature limits

This guide shows how to enforce a usage limit on a metered feature, such as "10,000 API calls per month", using the [check, act, track](/documentation/introduction/the-problem#common-patterns-for-solving-it-check--act--track) pattern: check the entitlement before the operation, run it, then report the usage.

The examples use the Node.js SDK. The same operations are available in every [backend SDK](/documentation/getting-started/get-started-with-sdks) and in the [REST API](/api-and-sdks/api-reference/rest/introduction).

<Steps>
  <Step title="Check the metered entitlement">
    Pass `requestedUsage` to verify that the customer can consume the amount the operation needs, not just that they have some usage left.

    ```javascript theme={null}
    const entitlement = await stiggClient.getMeteredEntitlement({
      customerId: 'customer-demo-01',
      featureId: 'feature-api-calls',
      options: { requestedUsage: 1 },
    });

    if (!entitlement.hasAccess) {
      // Block the operation and show an upsell experience
    }
    ```
  </Step>

  <Step title="Perform the operation">
    Run the operation in your application.
  </Step>

  <Step title="Report usage or events to Stigg">
    Report either calculated usage or raw events. Calculated usage is reflected in the next check immediately; raw events are aggregated by the metering pipeline and suit high-volume streams.

    <CodeGroup>
      ```javascript Calculated usage theme={null}
      await stiggClient.reportUsage({
        customerId: 'customer-demo-01',
        featureId: 'feature-api-calls',
        value: 1,
        idempotencyKey: 'request-8f2c',
      });
      ```

      ```javascript Raw event theme={null}
      await stiggClient.reportEvent({
        customerId: 'customer-demo-01',
        eventName: 'api_call',
        idempotencyKey: 'request-8f2c',
        dimensions: { endpoint: '/v1/search' },
      });
      ```
    </CodeGroup>
  </Step>
</Steps>


## Related topics

- [Checking metered entitlements](/api-and-sdks/integration/backend/nodejs.md#checking-if-a-customer-has-access-to-a-metered-feature)
- [Getting usage data into Stigg](/documentation/getting-usage-data-into-stigg/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.