Skip to content

Credits Module (Credits)

The Credits module provides low-level credit operation capabilities.

API List

MethodReturn ValueDescription
sdk.credits.getBalance()Promise<{ quota: number }>Query credit balance (network request)
sdk.credits.getCachedBalance()numberGet cached balance (synchronous, 0 before first call)
sdk.credits.onChange(callback)() => voidListen for credit changes

Detailed Usage

Query Balance

typescript
const { quota } = await sdk.credits.getBalance()
console.log('Credits balance:', quota)

// Synchronously get the cached value from the last query
const cached = sdk.credits.getCachedBalance()

WARNING

The return field name is quota (corresponding to the backend /ai/v1/credit/getBalance interface), not balance.

Listen for Changes

typescript
const unsubscribe = sdk.credits.onChange((balance) => {
  updateCreditsDisplay(balance)
})

unsubscribe() // Stop listening

Billing vs Credits

ModulePositioningTypical Use Case
creditsLow-level credit operationsScenarios requiring direct credit query/deduction (e.g., custom actions like AI generation)
billingHigh-level unified billingStandard operations like export and download, automatically handling free quota → credits fallback

The billing module is recommended for most scenarios.

MIT Licensed