POST /v1/billing/deduct to deduct credits from a user’s available balance in a single request.
This is the right choice for fixed-price image generation, fixed-cost API calls, and other one-time operations where cost is known upfront.
If cost is unknown in advance, or you need to reserve credits before settlement, use staged deduction instead.
Minimal Example
Parameters
The unique identifier for this customer. The customer must already exist and have enough available credits.
Unique ID for this charge transaction. Also serves as the idempotency key — repeating a request with the same
transaction_id returns the original result without double-charging.Credits to deduct. Must be greater than 0.
Restrict deduction to these wallet categories only. If omitted, the system may draw from any active credits. If provided and the selected categories have insufficient credits, the request fails.
Transaction category for reporting. Examples:
TASK, ORDER, TOKEN_USAGE.A human-readable note for this transaction.
Response
The unique transaction ID passed in the request.
Total credits actually deducted.
Deduction breakdown. Credits may be consumed from multiple wallet categories when the amount spans more than one account.
ISO 8601 timestamp when the deduction completed.
true when the response was returned from a previous request with the same transaction_id.Deduction Rules and Wallet Categories
- The system automatically deducts from all available credits.
- If
credit_typesis provided, deduction is limited to those wallet categories only. - Callers do not choose which wallet category to consume from.
- Credits that expire sooner are consumed first; if expiry is the same, older accounts are consumed first.
- Only credits that are currently active are eligible for deduction. Credits that have not started yet or have already expired are ignored.
- Use the customer balance API to inspect remaining credits by
credit_type.
Insufficient Balance
Returns400 if the customer doesn’t have enough available credits:
credit_types is provided, the error message becomes insufficient balance in selected credit_types when the selected wallet categories do not have enough credits.
Failed requests do not produce a partial deduction and do not leave behind a half-completed state.
Idempotency
Sametransaction_id -> same result, is_idempotent_replay: true, no double charge.
Verify the Result
- whether
balance.availabledecreased - which
accounts[].credit_typeentries were consumed - whether each
accounts[].availablevalue changed as expected
Error Format
All API errors return an HTTP error status and a structurederror object:
Human-readable description of the error.
High-level error category.
Stable machine-readable error code for programmatic handling.