Assistant Billing

Wallet

Manage workspace wallet balance and transaction history. Credits are added via Checkout.

Auth: Session token or platform key with X-Workspace-Id header.

Check Balance

GET /v1/platform/wallet/balance

Returns the current workspace wallet balance.

No parameters.

const balance = await billing.wallet.getBalance()

Response

{
  "currency": "USD",
  "amount": "142.350000"
}
FieldTypeRequiredDescription
currencystringAlwaysCurrency code (USD)
amountstringAlwaysCurrent balance in USD

List Transactions

GET /v1/platform/wallet/transactions

Returns transaction history for the workspace wallet, ordered by created_at DESC, id DESC. The operator endpoint GET /v1/platform/customers/:workspace_id/transactions accepts the same query parameters and returns the same response shape.

Query Parameters

NameTypeRequiredDescription
limitnumberNoResults per page. Default: 50, maximum: 100
offsetnumberNoNumber of results to skip. Default: 0. Cannot be combined with cursor
cursorstringNoOpaque next_cursor from the previous page. Cannot be combined with offset
typestringNoComma-separated list of credit, debit, refund, adjustment to include
exclude_typestringNoComma-separated list of those transaction types to exclude
const { data, next_cursor } = await billing.wallet.getTransactions({
  limit: 10,
  type: ['credit', 'refund'],
})
const nextPage = next_cursor
  ? await billing.wallet.getTransactions({ limit: 10, type: ['credit', 'refund'], cursor: next_cursor })
  : null

Response

{
  "data": [
    {
      "id": "txn_a1b2c3d4",
      "type": "debit",
      "amount_usd": "-0.003420",
      "balance_after": "142.346580",
      "description": "gpt-4o — 150 tokens",
      "reference_type": "api_request",
      "created_at": "2025-01-15T12:30:00.000Z"
    }
  ],
  "next_cursor": null
}
FieldTypeRequiredDescription
idstringAlwaysTransaction ID
typestringAlwayscredit, debit, refund, or adjustment
amount_usdstringAlwaysSigned amount (negative for debits)
balance_afterstringAlwaysBalance after this transaction
descriptionstringAlwaysHuman-readable description
reference_typestringAlwaysapi_request, stripe_checkout, or manual
created_atstringAlwaysISO 8601 timestamp

next_cursor is always present. Pass it as cursor to read the next page. null means there are no more results. Keep the same filters when paging.


Create Checkout

POST /v1/platform/wallet/checkout

Create a Stripe checkout session for topping up the wallet. Redirects the user to Stripe.

Body Parameters

NameTypeRequiredDescription
amountnumberYesTop-up amount in USD
success_urlstringYesRedirect URL after successful payment
cancel_urlstringYesRedirect URL if user cancels
workspace_idstringNoOverride workspace (platform key only)
const checkout = await billing.checkout.create({
  amount: 50,
  successUrl: 'https://app.example.com/billing?status=success',
  cancelUrl: 'https://app.example.com/billing?status=cancelled',
})
// Redirect user to checkout.url

Response

{
  "url": "https://checkout.stripe.com/c/pay/cs_live_...",
  "base_amount": "50.000000",
  "platform_fee": "2.500000",
  "markup": "5.000000",
  "total_amount": "57.500000"
}
FieldTypeRequiredDescription
urlstringAlwaysStripe checkout URL -- redirect the user here
base_amountstringAlwaysThe requested top-up amount
platform_feestringAlwaysFee charged by Assistant Billing
markupstringAlwaysOperator markup
total_amountstringAlwaysTotal charged to customer