Skip to main content
POST
/
api
/
v1
/
credits
/
consumption
JavaScript
import Stigg from '@stigg/typescript';

const client = new Stigg({
  apiKey: process.env['STIGG_API_KEY'], // This is the default and can be omitted
});

const response = await client.v1.credits.consumption.consume({
  amount: 1,
  currencyId: 'currencyId',
  customerId: 'customerId',
  idempotencyKey: 'x',
});

console.log(response.data);
{
  "data": {
    "customerId": "customer-123",
    "currencyId": "credits",
    "resourceId": null,
    "amount": 10,
    "timestamp": "2024-01-01T00:00:00.000Z",
    "credit": {
      "currencyId": "credits",
      "currentUsage": 10,
      "usageLimit": 1000,
      "timestamp": "2024-01-01T00:00:00.000Z",
      "usagePeriodEnd": null
    }
  }
}

Authorizations

X-API-KEY
string
header
required

Server API Key

Headers

X-ACCOUNT-ID
string

Account ID — optional when authenticating with a user JWT (Bearer token); falls back to the user's first membership. Ignored for API-key auth.

X-ENVIRONMENT-ID
string

Environment ID — required when authenticating with a user JWT (Bearer token) on environment-scoped endpoints. Ignored for API-key auth (env is intrinsic to the key).

Body

application/json

Request body for consuming credits directly from a wallet

customerId
string
required

The customer to consume credits from (required)

Required string length: 1 - 255
Pattern: ^[a-zA-Z0-9][a-zA-Z0-9_|.@-]*$
currencyId
string
required

The credit currency to consume from (required)

Required string length: 1 - 255
Pattern: ^[a-zA-Z0-9][a-zA-Z0-9_|.-]*$
amount
number
required

The amount of credits to consume

Required range: x > 0
idempotencyKey
string
required

A unique key used to deduplicate the consumption (required)

Required string length: 1 - 255
resourceId
string

Optional resource the consumption is attributed to

Required string length: 1 - 255
Pattern: ^[a-zA-Z0-9][a-zA-Z0-9_|.-]*$
dimensions
object

Optional dimensions describing the consumption

createdAt
string<date-time>

Optional timestamp the consumption is attributed to

Response

The result of the credit consumption, including the optimistic balance.

Response object

data
ConsumeCreditResponse · object
required

Result of a synchronous direct credit consumption