Credits API (BETA)
Read the player's AI Creator credits and drive a plan paywall. When a game is player-billed, the AI generation it triggers (ai, imageGen, videoGen) is charged to the signed-in player's Creator credits instead of the game owner's. This API lets you show the player their balance and plan, and resolve a deficit when they run out.
Note: Creator credits are not the same as RUN Bits. RUN Bits are the in-game hard currency, handled by the Purchases API (
RundotGameAPI.iap). Creator credits are the AI credits that power generation in player-billed games. This API (RundotGameAPI.credits) only deals with Creator credits.
Is My Game Player-Billed?
A game's billing mode is set by the platform, not by your game. getBillingContext() tells you how the current session bills AI generation. It is informational only — it never gates the other methods, so you can call any method regardless of billing mode and decide what to render yourself.
import RundotGameAPI from '@series-inc/rundot-game-sdk/api'
const ctx = await RundotGameAPI.credits.getBillingContext()
if (ctx.billedTo === 'player') {
// The player pays for AI generation — show their balance / a top-up entry point.
if (ctx.playerChargesEnabled) {
// Charges are actively enforced right now.
}
}Quick Start
import RundotGameAPI from '@series-inc/rundot-game-sdk/api'
// Show the player's spendable Creator credits.
const balance = await RundotGameAPI.credits.getBalance()
console.log(`${balance.available} / ${balance.total} credits`)
// Quote a generation without running a model or spending credits.
const estimate = await RundotGameAPI.credits.estimateGenerationCost({
kind: 'image',
model: 'gemini-3-pro-image-preview',
imageSize: '4K',
})
console.log(`${estimate.credits} credits${estimate.exact ? ' (exact)' : ''}`)
// Let the player upgrade their plan.
const result = await RundotGameAPI.credits.openPaywall()
if (result.outcome === 'purchased') {
updateCreditsUI(result.balance)
}Handling Exhaustion
When a player-billed game runs the player out of credits mid-generation, the host can automatically open the paywall and retry the call — so for most games you don't have to do anything. Two flags (both on by default) control this:
setAutoPaywallOnExhaustion(enabled)— on exhaustion, automatically open the paywall.setAutoRetryOnPurchase(enabled)— after a paywall purchase, automatically retry the original generation once and resolve it with the result.
true (default)
true (default)
Paywall opens. On purchase, the original call retries and resolves with the result. On cancel, it rejects with CreditsExhaustedError.
true
false
Paywall opens. On purchase, the call rejects (paywallOutcome: 'purchased') so you can retry it yourself. On cancel, it rejects.
false
(ignored)
The call rejects immediately (paywallShown: false).
These setters are synchronous — they update local SDK state and push it to the host fire-and-forget.
Reacting to Balance Changes
onBalanceChanged fires whenever the player's spendable balance changes — both when they buy credits at the paywall and when they spend credits on AI generation. It returns an unsubscribe function.
Rapid changes are coalesced, so a burst of generations finishing together may deliver a single update; that update always reflects the final balance.
It does not currently fire for free-daily resets, for top-ups made outside the game, or for streaming AI completions.
API Reference
getBillingContext()
Promise<CreditsBillingContext>
How the current game bills AI generation. Informational only — never gates other calls.
getBalance()
Promise<CreditBalance>
The player's spendable / total Creator credits and free-daily info.
getSubscription()
Promise<CreditSubscription>
The player's current Creator plan (paid tier), if any.
getPlans()
Promise<CreditPlansCatalog>
The available plans, top-up packs, and the free-daily grant.
openPaywall(options?)
Promise<CreditsPurchaseResult>
Open the host paywall. Resolves once the player closes it.
setAutoPaywallOnExhaustion(enabled)
void
Toggle the automatic exhaustion paywall (default true). Synchronous.
getAutoPaywallOnExhaustion()
boolean
Current auto-paywall setting.
setAutoRetryOnPurchase(enabled)
void
Toggle automatic retry after an exhaustion purchase (default true). Synchronous.
getAutoRetryOnPurchase()
boolean
Current auto-retry setting.
onBalanceChanged(listener)
Unsubscribe
Subscribe to balance changes. Returns an unsubscribe function.
estimateGenerationCost(request): Promise<GenerationCostEstimate> returns an unbilled quote from the canonical server pricing endpoint. It supports image, music, sfx, video, tts, text, and upscale requests.
upscale prices the Topaz upscale exactly as billing brackets it: pass the source contentType — 'image/*' quotes the flat image rate; 'video/*' quotes per second by resolution ('720p' or '1080p') × durationSeconds. Passing outputMp (output megapixels) selects the tiered advanced-upscale pricing instead.
quantity multiplies the quote for a batch of identical generations (default 1) — a batch of N scene clips is { kind: 'video', …, quantity: N }. Text ranges scale bound-for-bound; the percent bounds are unchanged. Pass the per-unit options (model, mode, duration, size) exactly as generation will send them, or the quote prices a different product than the one you dispatch.
Types
These types are exported from the package root, @series-inc/rundot-game-sdk (not the /api subpath).
CreditsBillingContext
billedTo
'owner' | 'player'
Who AI generation in this game is billed to.
playerChargesEnabled
boolean
true only when billedTo === 'player' AND charge enforcement is live.
GenerationCostEstimate
Text estimate requests include the same model, messages, system, and output-token cap used for generation. The result contains credits, lowCredits, highCredits, lowerPercent, upperPercent, exact, and a human-readable reason. Exact quotes use the same value for low, estimate, and high. The server is the only pricing source; estimating never runs a model or debits credits.
CreditBalance
available
number
Credits the player can spend right now.
total
number
The "available / total" denominator.
freeDaily
CreditFreeDailyInfo | null
Free-daily grant info, or null when the player isn't eligible (e.g. a paid plan).
CreditFreeDailyInfo: { dailyCredits: number; availableCredits: number; nextResetAt: string } (nextResetAt is an ISO timestamp).
CreditSubscription
status
'active' | 'none'
Whether the player has an active Creator plan.
tier
string | null
The paid plan tier (e.g. 'plus'), or null.
monthlyCredits
number | null
Credits granted per period for the active plan.
creditsRemaining
number | null
Credits remaining in the current period.
renewsAt
string | null
ISO renewal/expiry timestamp.
willRenew
boolean
Whether the plan will auto-renew.
CreditPlansCatalog
plans
CreditPlan[]
Available subscription plans.
plansUnavailable
boolean
When true, the plan catalog couldn't be resolved right now and plans is empty — show "temporarily unavailable", not "no plans exist". topUpPacks and freeDailyCredits stay valid.
topUpPacks
CreditTopUpPack[]
One-time top-up packs (purchase UI is a future release).
freeDailyCredits
number
The free-daily grant amount.
CreditPlan: { tier: string; productId: string; monthlyCredits: number; rolloverDays: number }. CreditTopUpPack: { productId: string; credits: number }.
OpenPaywallOptions
focus
'plans' | 'topup'
No
Which surface to focus. 'topup' is a future surface (currently shows plans).
highlightTier
string
No
A tier id to visually highlight in the plan picker.
screenName
string
No
Screen/route name for analytics attribution.
CreditsPurchaseResult
outcome
'purchased' | 'cancelled' | 'pending'
What the player did in the paywall.
balance
CreditBalance | null
The refreshed balance after the paywall closed, or null if it couldn't be read.
CreditsExhaustedError
Thrown from ai / imageGen / videoGen calls when a player-billed game runs the player out of credits and the deficit wasn't resolved. Use the exported isCreditsExhaustedError(err) / asCreditsExhaustedError(err) helpers to detect and narrow it.
code
'CREDITS_EXHAUSTED'
Stable discriminator.
billedTo
'owner' | 'player'
Who the generation was billed to.
paywallShown
boolean
Whether the host opened the paywall before giving up.
paywallOutcome
'purchased' | 'cancelled' | 'pending' | null
The paywall result (null when paywallShown is false).
Best Practices
Treat
getBillingContext()as a hint for what to render — never as a gate. Any method works regardless of billing mode.Leave the auto-paywall on for the simplest experience; only turn it off when you want a custom out-of-credits UX.
Use
onBalanceChangedto keep your credits UI in sync rather than pollinggetBalance().Always handle the
'cancelled'outcome — players will dismiss the paywall.
Last updated