> ## 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.

# Deduct credits directly

This guide shows how to deduct credits for an operation directly, without mapping it to a metered feature, using the [check, act, track](/documentation/introduction/the-problem#common-patterns-for-solving-it-check--act--track) pattern. Use it when you calculate the cost of an operation yourself. It works with or without an active subscription.

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 credit entitlement">
    Pass the expected cost as `requestedUsage`. `hasAccess` is `true` when the remaining balance covers it, or when the currency has a soft limit.

    ```javascript theme={null}
    const credits = await stiggClient.getCreditEntitlement({
      customerId: 'customer-demo-01',
      currencyId: 'currency-ai-credits',
      options: { requestedUsage: estimatedCost },
    });

    if (!credits.hasAccess) {
      // Block the operation or prompt for a top-up
    }
    ```
  </Step>

  <Step title="Deduct credits">
    Run the operation and calculate the number of credits it consumed, then deduct them. Use `consumeCredits` for strict, real-time enforcement (when synchronous credit consumption is enabled, the response includes the optimistic balance in `credit`), or `consumeCreditsAsync` for high-volume, eventually consistent consumption.

    ```javascript theme={null}
    await stiggClient.consumeCredits({
      customerId: 'customer-demo-01',
      currencyId: 'currency-ai-credits',
      amount: actualCost,
      idempotencyKey: 'generation-41a7',
    });
    ```
  </Step>
</Steps>


## Related topics

- [Consume credits directly](/api-and-sdks/integration/backend/usage-and-billing.md#consume-credits-directly)
- [Credit consumption modes](/documentation/modeling-your-pricing-in-stigg/credits/credits-core-concepts.md#credit-consumption-modes)


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