SDK SDKs JavaScript / TypeScript Server and browser clients, every method, Funnel/Paywall/experiment entry points and error handling.
API v1 Updated Oct 22, 2026
On this page
Install 1 npm install --save-exact @tinkerlandai/indiana-sdk@0.6.2One package serves Node.js 22+ backends and browsers and ships TypeScript types. Every client defaults to https://api.tinker.cash; set baseUrl explicitly for a test service. See the install page for every entry point.
Related: Install SDKs and CLI
Server client createIndianaServer uses a Server Key and can only be created on a trusted backend; calling it in a browser throws SERVER_ONLY. Each method maps to one HTTP operation, and requests and responses are validated against the public contract.
indiana.server.ts TypeScript Copy 1 import { createIndianaServer, IndianaError } from "@tinkerlandai/indiana-sdk/server" ;2 3 const indiana = createIndianaServer ({4 baseUrl: process.env.INDIANA_API_URL !, 5 apiKey: process.env.INDIANA_API_KEY !, 6 scope: { projectId: process.env.INDIANA_PROJECT_ID !, environment: "sandbox" }, 7 }); 8 9 export async function generateImage (verifiedUserId: string, eventId: string) {10 const { customer } = await indiana.getOrCreateCustomer ({ 11 externalUserId: verifiedUserId, 12 }); 13 const { check } = await indiana.checkEntitlement ({ 14 customerId: customer.id, 15 requirement: { 16 internal_feature_id: process.env.INDIANA_FEATURE_ID !, 17 quantity: "1" , 18 properties: {}, 19 }, 20 }); 21 if (!check.allowed) return { allowed: false as const }; 22 23 try { 24 const { receipts } = await indiana.trackUsage ({ 25 customerId: customer.id, 26 // eventId is persisted before the call and reused on every retry. 27 command: { eventName: "image_generated" , quantity: "1" , idempotencyKey: eventId }, 28 }); 29 for (const receipt of receipts) 30 if (!receipt.accepted) console.warn ("usage refused" , receipt.reason); 31 return { allowed: true as const , receipts }; 32 } catch (error) { 33 if (error instanceof IndianaError ) console.error (error.code, error.recovery, error.requestId); 34 throw error; 35 } 36 } Server methods by area Area Methods Customers, Guests and Sessions getOrCreateCustomer, getCustomer, listCustomers, updateCustomer, createCustomerSession, renewCustomerSession, revokeCustomerSessions, createGuestCustomer, resumeGuestSession, claimGuestCustomerEntitlements and product presentation checkEntitlement, resolveOffering, resolvePaywall, readHoldingsBalances, usage and ledger readBalanceSource, adjustBalance, readUsage, setUsage, manageBalanceGrant, listBalanceGrants, manageUsageEntity, readUsageAnalytics, readCreditAnalytics, submitUsageBatch, readUsageBatch, readLedger, readCreditStatement, quoteBalance, trackUsage, mutateBalanceSeats readSeats, manageSeatSubscriptions and payments setupPayment, readPaymentSetup, verifySubscriptions, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdate, listSubscriptions, listPurchases, listSubscriptionConflicts, retrySubscriptionConflict, manageSubscriptionTrial, readSubscriptionTrialInvoices, refunds and billing listInvoiceTemplates, previewInvoice, createInvoice, manageInvoice, readInvoiceOperation, listInvoices, getInvoice, previewRefund, refund, readRefund, manageBillingLimits, readBillingInvoiceCoupons, rewards and referrals grantOffer, recordCouponRedemptionFeatures, evaluation and events getFeatures, evaluateFeatures, trackEventsNative purchases restoreNativePurchaseAI pricing readAiPricing
Server methods by area
Customers, Guests and Sessions
Methods getOrCreateCustomer, getCustomer, listCustomers, updateCustomer, createCustomerSession, renewCustomerSession, revokeCustomerSessions, createGuestCustomer, resumeGuestSession, claimGuestCustomerEntitlements and product presentation
Methods checkEntitlement, resolveOffering, resolvePaywall, readHoldingsBalances, usage and ledger
Methods readBalanceSource, adjustBalance, readUsage, setUsage, manageBalanceGrant, listBalanceGrants, manageUsageEntity, readUsageAnalytics, readCreditAnalytics, submitUsageBatch, readUsageBatch, readLedger, readCreditStatement, quoteBalance, trackUsage, mutateBalanceSeats
Methods readSeats, manageSeatSubscriptions and payments
Methods setupPayment, readPaymentSetup, verifySubscriptions, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdate, listSubscriptions, listPurchases, listSubscriptionConflicts, retrySubscriptionConflict, manageSubscriptionTrial, readSubscriptionTrialInvoices, refunds and billing
Methods listInvoiceTemplates, previewInvoice, createInvoice, manageInvoice, readInvoiceOperation, listInvoices, getInvoice, previewRefund, refund, readRefund, manageBillingLimits, readBillingInvoiceCoupons, rewards and referrals
Methods grantOffer, recordCouponRedemptionFeatures, evaluation and events
Methods getFeatures, evaluateFeatures, trackEventsNative purchases
Methods restoreNativePurchaseAI pricing
Methods readAiPricingClient options Option Description apiKeyServer Key (gg_sk_) from your backend secret store. scope{ projectId, environment }: the App UUID and sandbox or live, matching the Key.baseUrlAPI origin, default https://api.tinker.cash; without /api/v1. timeoutMsPer-request timeout, default 10000, maximum 120000. fetchInject a custom fetch for proxies or offline tests.
Client options
apiKey
Description Server Key (gg_sk_) from your backend secret store. scope
Description { projectId, environment }: the App UUID and sandbox or live, matching the Key.baseUrl
Description API origin, default https://api.tinker.cash; without /api/v1. timeoutMs
Description Per-request timeout, default 10000, maximum 120000. fetch
Description Inject a custom fetch for proxies or offline tests. Browser client Browsers never hold a Server Key. After your backend verifies the login it issues a Customer Token, and the browser calls identify(token). The token determines the Customer; a browser cannot select another customerId. Call reset() on sign-out or account switch.
server/session.ts TypeScript Copy 1 import { createIndianaServer } from "@tinkerlandai/indiana-sdk/server" ;2 3 const indiana = createIndianaServer ({4 baseUrl: process.env.INDIANA_API_URL !, 5 apiKey: process.env.INDIANA_API_KEY !, 6 scope: { projectId: process.env.INDIANA_PROJECT_ID !, environment: "sandbox" }, 7 }); 8 9 // Call only after your own login check succeeds. 10 export async function issueCustomerToken (verifiedUserId: string) {11 const { customer } = await indiana.getOrCreateCustomer ({ 12 externalUserId: verifiedUserId, 13 }); 14 const { customerToken, expiresAt } = await indiana.createCustomerSession (customer.id); 15 return { customerToken, expiresAt }; 16 }
Browser methods by area Area Methods Entitlements and product presentation checkEntitlement, resolveOffering, resolvePaywall, readHoldingsBalances, usage and ledger readLedger, readCreditStatement, quoteBalanceSubscriptions and payments setupPayment, readPaymentSetup, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdateInvoices, refunds and billing readBillingControls, prepareBillingAuthorization, confirmBillingAuthorization, setBillingCoupons, revokeBillingAuthorization, listBillingInvoices, readBillingInvoiceCoupons, rewards and referrals redeemCoupon, listOffers, claimCoupon, redeemReward, createReferralCodeFeatures, evaluation and events features, track, flushNative purchases restoreNativePurchase
Browser methods by area
Entitlements and product presentation
Methods checkEntitlement, resolveOffering, resolvePaywall, readHoldingsBalances, usage and ledger
Methods readLedger, readCreditStatement, quoteBalanceSubscriptions and payments
Methods setupPayment, readPaymentSetup, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdateInvoices, refunds and billing
Methods readBillingControls, prepareBillingAuthorization, confirmBillingAuthorization, setBillingCoupons, revokeBillingAuthorization, listBillingInvoices, readBillingInvoiceCoupons, rewards and referrals
Methods redeemCoupon, listOffers, claimCoupon, redeemReward, createReferralCodeFeatures, evaluation and events
Methods features, track, flushNative purchases
Methods restoreNativePurchaseRegister website origins in Console under SDK integration → Allowed website origins (one complete origin per line, at most 20). Sandbox also allows HTTP development on localhost, 127.0.0.1 and [::1]; Live accepts HTTPS only. The Key that issues sessions needs sessions:create plus the scopes the browser will use, such as entitlements:read, billing:write or offers:resolve. indiana.forFunnel({ funnelId, versionId }) returns a resource client bound to that Funnel for coupon claims, Offering/Paywall resolution and purchase quotes.Funnels, Paywalls and experiments Other exports Function Entry Purpose createFunnelStartClient/serverStart a Funnel Run from your backend and receive a Run Token createFunnelRunController, showFunnelRunmain Display and advance a Run in the browser createFunnelClientmain Start a Run from a client that holds a Customer Token createLocalFunnelClient, createConfigurationSyncmain / /server Local-mode Funnels and shared public configuration createFunnelDecisionClient, createFunnelCampaignClient/serverServer decisions, Campaign starts and adoption reports createFunnelOrchestrationClient, renewFunnelRun/serverSignal a Run, read its results and rotate its Run Token createPaywallStartClient, createPaywallSession, showPaywall/server / mainStandalone Paywall sessions and display createFeatureClient, indiana.features()main Feature evaluation and subscriptions createPageExperiments/pageURL redirect experiments createVisualExperiments/visualVisual experiments createNativeReceiptClient/serverSubmit native store proofs from your backend createAiUsageMiddleware, createAiPricing/serverAI SDK usage-billing middleware and pricing createOpenRouterUsageClient, trackOpenRouterUsage/openrouterOpenRouter usage billing
Other exports
createFunnelStartClient
Entry /server
Purpose Start a Funnel Run from your backend and receive a Run Token createFunnelRunController, showFunnelRun
Entry main
Purpose Display and advance a Run in the browser createFunnelClient
Entry main
Purpose Start a Run from a client that holds a Customer Token createLocalFunnelClient, createConfigurationSync
Entry main / /server
Purpose Local-mode Funnels and shared public configuration createFunnelDecisionClient, createFunnelCampaignClient
Entry /server
Purpose Server decisions, Campaign starts and adoption reports createFunnelOrchestrationClient, renewFunnelRun
Entry /server
Purpose Signal a Run, read its results and rotate its Run Token createPaywallStartClient, createPaywallSession, showPaywall
Entry /server / main
Purpose Standalone Paywall sessions and display createFeatureClient, indiana.features()
Entry main
Purpose Feature evaluation and subscriptions createPageExperiments
Entry /page
Purpose URL redirect experiments createVisualExperiments
Entry /visual
Purpose Visual experiments createNativeReceiptClient
Entry /server
Purpose Submit native store proofs from your backend createAiUsageMiddleware, createAiPricing
Entry /server
Purpose AI SDK usage-billing middleware and pricing createOpenRouterUsageClient, trackOpenRouterUsage
Entry /openrouter
Purpose OpenRouter usage billing Related: Run Funnels · Payments, subscriptions and billing · Features, experiments and events
Errors and retries Failures throw IndianaError with code, status, requestId, retryable, recovery, and optional reason and retryAfterSeconds. The SDK never retries writes automatically: persist the requestId, eventId or idempotencyKey before sending, and after an unknown result replay the same value and input or read the original operation.
Related: Error codes and recovery