Choices API
The Choices API (RundotGameAPI.choices) provides an authorized partner-integration namespace for checking and spending the current user's Choices diamond currency balance from an authenticated RUN game.
Access Requirements
Calling /v1/choices/* requires two server-enforced conditions:
The
run_tv_choices_diamonds_enabledStatsig feature gate must be enabled.The calling game's game-session-token
gidclaim must be explicitly allowlisted (e.g.run-tv). Unauthorized games will receive a403 FORBIDDENerror.
Linking a user account (uid → altId) is handled exclusively out-of-band by the platform ingress deeplink handler (POST /v1/choices/link). Games only check whether a player is linked or unlinked; they do not perform account linking directly.
Quick Start
import RundotGameAPI from '@series-inc/rundot-game-sdk/api'
// 1. Fetch current diamond balance
try {
const { diamonds } = await RundotGameAPI.choices.getBalance()
console.log(`Current Choices diamonds: ${diamonds}`)
} catch (err: any) {
if (err.code === 'NOT_LINKED') {
// Player has not linked a Choices account; hide spend UI
hideChoicesOption()
} else if (err.code === 'SERVICE_UNAVAILABLE') {
// Integration gate is disabled
console.warn('Choices integration unavailable')
}
}
// 2. Spend diamonds with idempotency
async function unlockEpisode(episodeId: string) {
const clientRequestId = crypto.randomUUID() // Stable ID across retries
try {
const result = await RundotGameAPI.choices.spend({
amount: 15,
reason: `episode_unlock:${episodeId}`,
clientRequestId,
})
console.log(`Deducted ${result.amountDebited} diamonds. New balance: ${result.newDiamonds}`)
if (result.alreadyProcessed) {
console.log('Replayed prior transaction:', result.transactionRef)
}
} catch (err: any) {
if (err.code === 'INSUFFICIENT_FUNDS') {
showInsufficientDiamondsModal()
} else if (err.code === 'IN_PROGRESS') {
// Transaction currently pending; retry with the same clientRequestId
await retrySpend(clientRequestId)
}
}
}Methods
getBalance()
Fetches the authenticated user's current Choices diamond balance.
Errors
NOT_LINKED(403): User has not linked their Choices account.SERVICE_UNAVAILABLE(503): Integration feature gate is disabled.FORBIDDEN(403): Calling game is not allowlisted.UPSTREAM_ERROR(502): Choices upstream mapping or reachability failure.RATE_LIMITED(429): Request throttled (checkRetry-After).
spend(request)
Debits diamonds from the current user's Choices wallet. Server idempotency guarantees that reusing the same clientRequestId across network retries replays the original outcome without double-charging.
Errors
INSUFFICIENT_FUNDS(402): Balance is lower than requested spend amount.INVALID_AMOUNT(400): Amount is non-positive or exceeds the server per-call ceiling.MALFORMED_REQUEST(400): Empty or missingreasonorclientRequestId.IN_PROGRESS(409): Prior transaction with the sameclientRequestIdis processing; retry with backoff.NOT_LINKED/SERVICE_UNAVAILABLE/FORBIDDEN/UPSTREAM_ERROR/RATE_LIMITED: Same semantics asgetBalance().
Data Types
ChoicesBalance
ChoicesSpendRequest
ChoicesSpendResult
Best Practices
Generate a fresh UUID per distinct purchase action: Never generate a new UUID on network retry of the same purchase attempt.
Handle
INSUFFICIENT_FUNDSgracefully: This is an expected business outcome, not a fatal exception. Direct users to purchase more diamonds or select another payment option.
Last updated