Skip to content
Indiana
Dashboard
Docs
Browse docs / JavaScript / TypeScript

JavaScript / TypeScript

Server and browser clients, every method, Funnel/Paywall/experiment entry points and error handling.

API v1Updated

Install

terminalShell
npm install --save-exact @tinkerlandai/indiana-sdk@0.6.2

One 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.tsTypeScript
import { createIndianaServer, IndianaError } from "@tinkerlandai/indiana-sdk/server"; const indiana = createIndianaServer({  baseUrl: process.env.INDIANA_API_URL!,  apiKey: process.env.INDIANA_API_KEY!,  scope: { projectId: process.env.INDIANA_PROJECT_ID!, environment: "sandbox" },}); export async function generateImage(verifiedUserId: string, eventId: string) {  const { customer } = await indiana.getOrCreateCustomer({    externalUserId: verifiedUserId,  });  const { check } = await indiana.checkEntitlement({    customerId: customer.id,    requirement: {      internal_feature_id: process.env.INDIANA_FEATURE_ID!,      quantity: "1",      properties: {},    },  });  if (!check.allowed) return { allowed: false as const };   try {    const { receipts } = await indiana.trackUsage({      customerId: customer.id,      // eventId is persisted before the call and reused on every retry.      command: { eventName: "image_generated", quantity: "1", idempotencyKey: eventId },    });    for (const receipt of receipts)      if (!receipt.accepted) console.warn("usage refused", receipt.reason);    return { allowed: true as const, receipts };  } catch (error) {    if (error instanceof IndianaError) console.error(error.code, error.recovery, error.requestId);    throw error;  }}
Server methods by area
AreaMethods
Customers, Guests and SessionsgetOrCreateCustomer, getCustomer, listCustomers, updateCustomer, createCustomerSession, renewCustomerSession, revokeCustomerSessions, createGuestCustomer, resumeGuestSession, claimGuestCustomer
Entitlements and product presentationcheckEntitlement, resolveOffering, resolvePaywall, readHoldings
Balances, usage and ledgerreadBalanceSource, adjustBalance, readUsage, setUsage, manageBalanceGrant, listBalanceGrants, manageUsageEntity, readUsageAnalytics, readCreditAnalytics, submitUsageBatch, readUsageBatch, readLedger, readCreditStatement, quoteBalance, trackUsage, mutateBalance
SeatsreadSeats, manageSeat
Subscriptions and paymentssetupPayment, readPaymentSetup, verifySubscriptions, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdate, listSubscriptions, listPurchases, listSubscriptionConflicts, retrySubscriptionConflict, manageSubscriptionTrial, readSubscriptionTrial
Invoices, refunds and billinglistInvoiceTemplates, previewInvoice, createInvoice, manageInvoice, readInvoiceOperation, listInvoices, getInvoice, previewRefund, refund, readRefund, manageBillingLimits, readBillingInvoice
Coupons, rewards and referralsgrantOffer, recordCouponRedemption
Features, evaluation and eventsgetFeatures, evaluateFeatures, trackEvents
Native purchasesrestoreNativePurchase
AI pricingreadAiPricing

Server methods by area

  • Customers, Guests and Sessions

    Methods
    getOrCreateCustomer, getCustomer, listCustomers, updateCustomer, createCustomerSession, renewCustomerSession, revokeCustomerSessions, createGuestCustomer, resumeGuestSession, claimGuestCustomer
  • Entitlements and product presentation

    Methods
    checkEntitlement, resolveOffering, resolvePaywall, readHoldings
  • Balances, usage and ledger

    Methods
    readBalanceSource, adjustBalance, readUsage, setUsage, manageBalanceGrant, listBalanceGrants, manageUsageEntity, readUsageAnalytics, readCreditAnalytics, submitUsageBatch, readUsageBatch, readLedger, readCreditStatement, quoteBalance, trackUsage, mutateBalance
  • Seats

    Methods
    readSeats, manageSeat
  • Subscriptions and payments

    Methods
    setupPayment, readPaymentSetup, verifySubscriptions, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdate, listSubscriptions, listPurchases, listSubscriptionConflicts, retrySubscriptionConflict, manageSubscriptionTrial, readSubscriptionTrial
  • Invoices, refunds and billing

    Methods
    listInvoiceTemplates, previewInvoice, createInvoice, manageInvoice, readInvoiceOperation, listInvoices, getInvoice, previewRefund, refund, readRefund, manageBillingLimits, readBillingInvoice
  • Coupons, rewards and referrals

    Methods
    grantOffer, recordCouponRedemption
  • Features, evaluation and events

    Methods
    getFeatures, evaluateFeatures, trackEvents
  • Native purchases

    Methods
    restoreNativePurchase
  • AI pricing

    Methods
    readAiPricing
Client options
OptionDescription
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.tsTypeScript
import { createIndianaServer } from "@tinkerlandai/indiana-sdk/server"; const indiana = createIndianaServer({  baseUrl: process.env.INDIANA_API_URL!,  apiKey: process.env.INDIANA_API_KEY!,  scope: { projectId: process.env.INDIANA_PROJECT_ID!, environment: "sandbox" },}); // Call only after your own login check succeeds.export async function issueCustomerToken(verifiedUserId: string) {  const { customer } = await indiana.getOrCreateCustomer({    externalUserId: verifiedUserId,  });  const { customerToken, expiresAt } = await indiana.createCustomerSession(customer.id);  return { customerToken, expiresAt };}
Browser methods by area
AreaMethods
Entitlements and product presentationcheckEntitlement, resolveOffering, resolvePaywall, readHoldings
Balances, usage and ledgerreadLedger, readCreditStatement, quoteBalance
Subscriptions and paymentssetupPayment, readPaymentSetup, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdate
Invoices, refunds and billingreadBillingControls, prepareBillingAuthorization, confirmBillingAuthorization, setBillingCoupons, revokeBillingAuthorization, listBillingInvoices, readBillingInvoice
Coupons, rewards and referralsredeemCoupon, listOffers, claimCoupon, redeemReward, createReferralCode
Features, evaluation and eventsfeatures, track, flush
Native purchasesrestoreNativePurchase

Browser methods by area

  • Entitlements and product presentation

    Methods
    checkEntitlement, resolveOffering, resolvePaywall, readHoldings
  • Balances, usage and ledger

    Methods
    readLedger, readCreditStatement, quoteBalance
  • Subscriptions and payments

    Methods
    setupPayment, readPaymentSetup, previewAttach, attach, readSubscriptionOperation, previewUpdate, update, readSubscriptionUpdate
  • Invoices, refunds and billing

    Methods
    readBillingControls, prepareBillingAuthorization, confirmBillingAuthorization, setBillingCoupons, revokeBillingAuthorization, listBillingInvoices, readBillingInvoice
  • Coupons, rewards and referrals

    Methods
    redeemCoupon, listOffers, claimCoupon, redeemReward, createReferralCode
  • Features, evaluation and events

    Methods
    features, track, flush
  • Native purchases

    Methods
    restoreNativePurchase
  • Register 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
FunctionEntryPurpose
createFunnelStartClient/serverStart a Funnel Run from your backend and receive a Run Token
createFunnelRunController, showFunnelRunmainDisplay and advance a Run in the browser
createFunnelClientmainStart a Run from a client that holds a Customer Token
createLocalFunnelClient, createConfigurationSyncmain / /serverLocal-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()mainFeature 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