Deduct Credits
Deduct credits when a user performs a paid action.
typescript
import { InsufficientCreditsError } from 'settlesettle'
try {
await settle.wallet.debit('user_123', {
amount: 10,
description: 'AI Image Generation',
})
} catch (err) {
if (err instanceof InsufficientCreditsError) {
// This is expected — not a bug
// Show a paywall, prompt a top-up, or trigger an ad
console.log(`Balance: ${err.currentBalance}, Needed: ${err.requestedAmount}`)
}
}InsufficientCreditsError is expected behaviour, not a bug. Always catch it and decide what your app should do — show a paywall, trigger an ad, or gracefully downgrade the action.