Account API methods that let you interact with the user's account. Can be accessed via sogni.account. Look for more samples below.

const balance = await sogni.account.refreshBalance();
console.log(balance);

Hierarchy (View Summary)

Constructors

Properties

client: ApiClient
currentAccount: CurrentAccount = ...

Current account data.

eip712: EIP712Helper
listeners: {} = {}

Methods

  • Get the account balance of the current account. This method returns the account balance of the current user, including settled, credit, debit, and unclaimed earnings amounts.

    Returns Promise<FullBalances>

    const balance = await sogni.account.accountBalance();
    console.log(balance);
  • Create a Stripe checkout session to subscribe to a plan.

    Returns a url to which the user should be redirected to complete payment. After a successful checkout Stripe will redirect back to your configured return URL and the subscription entitlement will become active.

    Pass options.startTrial to control free-trial behavior: true starts a trial when the account is eligible, while false is sent verbatim to subscribe immediately with no trial even if the account is eligible. Host applications may pass options.deviceId when their integration requires the corresponding server-side context.

    Parameters

    Returns Promise<SubscriptionCheckoutResult>

    const { url } = await sogni.account.createSubscriptionCheckout('unlimited', 'monthly');
    window.location.href = url;
  • Create a Stripe customer portal session for managing an existing subscription.

    Returns a url to which the user should be redirected. The portal lets them update payment methods, cancel, or view invoices.

    Returns Promise<SubscriptionPortalSession>

    const { url } = await sogni.account.createSubscriptionPortalSession();
    window.location.href = url;
  • Deposit tokens from wallet to account

    Parameters

    • password: string

      account password

    • amount: string | number

      amount to transfer

    • provider: string = 'base'

      blockchain provider, 'base' or 'etherlink' defaults to 'base'

    Returns Promise<void>

    await sogni.account.deposit('your-account-password', 100, 'base');
    
  • Dispatch an event to all listeners

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • data: {}[T]

    Returns void

  • Fetch the list of available subscription plans.

    This is a public endpoint; no authentication is required.

    Returns Promise<SubscriptionPlan[]>

    const plans = await sogni.account.getSubscriptionPlans();
    plans.forEach(p => console.log(p.displayName, p.priceUsd));
  • Fetch the current user's subscription entitlement snapshot.

    Returns an object describing whether the account has an effective subscription entitlement, the tier, period boundaries, usage, limits, and enabled capabilities. When no subscription exists, active is false and status is 'none'.

    Also updates currentAccount.subscription so callers can read the snapshot from the observable entity without re-fetching.

    Returns Promise<SubscriptionEntitlementSnapshot>

    const snap = await sogni.account.getSubscriptionStatus();
    if (snap.active) {
    console.log('Plan:', snap.tier, 'until', snap.currentPeriodEnd);
    }
  • Fetch the current user's usage for the active billing cycle.

    Returns the render/job counters for the subscriber's current billing cycle (not a calendar month). While the entitlement is 'trialing', the response also carries trialEndsAt, trialCreditsLimit, and trialCreditsUsed so you can render "X of N trial credits used" messaging; those fields are omitted for non-trial subscriptions.

    Note: these trial usage fields come from this endpoint, NOT from getSubscriptionStatus — the entitlement snapshot never carries trial usage.

    Returns Promise<SubscriptionUsage>

    const usage = await sogni.account.getSubscriptionUsage();
    if (usage.trialCreditsLimit !== undefined) {
    console.log(`${usage.trialCreditsUsed} of ${usage.trialCreditsLimit} trial credits used`);
    }
  • Check whether the current account is eligible to start a free trial.

    Returns { eligible, reasonCode }. Use eligible as the decision and treat reasonCode as an opaque display hint.

    Returns Promise<TrialEligibility>

    const { eligible, reasonCode } = await sogni.account.getTrialEligibility();
    if (eligible) {
    const { url } = await sogni.account.createSubscriptionCheckout('unlimited', 'monthly', {
    startTrial: true
    });
    }
  • Create Ethers.js Wallet instance from username and password. This method is used internally to create a wallet for the user. You can use this method to create a wallet if you need to sign transactions.

    Parameters

    • username: string

      Sogni account username

    • password: string

      Sogni account password

    Returns Wallet

    const wallet = sogni.account.getWallet('username', 'password');
    console.log(wallet.address);
  • Login with username and password. WebSocket connection is established after successful login.

    Parameters

    • username: string
    • password: string
    • rememberMe: boolean = false

      Whether to establish a long-lived session. Default is false. Only applicable for cookie-based authentication.

    • OptionalappSource: string

      Optional client app/source label for login attribution. Defaults to the SogniClient connection appSource when configured.

    Returns Promise<LoginData>

    await sogni.account.login('username', 'password');
    console.log('Logged in');
  • Logout the user and close the WebSocket connection.

    Returns Promise<void>

    await sogni.account.logout();
    console.log('Logged out');
  • Remove an event listener

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • listener: (data: {}[T]) => void

    Returns void

  • Add an event listener, returns a function that can be called to remove the listener

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • listener: (data: {}[T]) => void

    Returns () => void

  • Add an event listener that will be called only once

    Type Parameters

    • T extends never

    Parameters

    • event: T
    • listener: (data: {}[T]) => void

    Returns () => void

  • Refresh the balance of the current account.

    Usually, you don't need to call this method manually. Balance is updated automatically through WebSocket events. But you can call this method to force a balance refresh. Note that will also trigger updated event on the current account.

    Returns Promise<Balances>

    const balance = await sogni.account.refreshBalance();
    console.log(balance);
  • Associate an opaque host-application identifier with the current account. Requires an authenticated session.

    Parameters

    • deviceId: string

      Opaque host-application identifier.

    Returns Promise<void>

    await sogni.account.setDeviceId(myPersistentDeviceId);
    
  • Switch between fast and relaxed networks. This will change default network used to process projects. After switching, client will receive list of AI models available for on selected network.

    Parameters

    Returns Promise<SupernetType>

    await sogni.account.switchNetwork('fast');
    console.log('Switched to the fast network, now lets wait until we get list of models');
    await sogni.projects.waitForModels();
  • Get the transaction history of the current account.

    Parameters

    Returns Promise<{ entries: TxHistoryEntry[]; next: TxHistoryParams }>

    Transaction history entries and next query parameters

    const { entries, next } = await sogni.account.transactionHistory({
    status: 'completed',
    limit: 10,
    address: sogni.account.currentAccount.walletAddress
    });
  • Get the balance of the wallet address.

    This method is used to get the balance of the wallet address. It returns $SOGNI and ETH balance.

    Parameters

    • walletAddress: string
    • provider: "base" | "etherlink" = 'base'

      blockchain provider, 'base' or 'etherlink' defaults to 'base'

    Returns Promise<{ ether: string; sogni: string; spark: string }>

    const address = sogni.account.currentAccount.walletAddress;
    const balance = await sogni.account.walletBalance(address);
    console.log(balance);
    // { token: '100.000000', ether: '0.000000' }
  • Withdraw funds from the current account to wallet.

    Parameters

    • password: string

      account password

    • amount: string | number

      amount of tokens to withdraw from account to wallet

    • provider: string = 'base'

      blockchain provider, 'base' or 'etherlink' defaults to 'base'

    Returns Promise<void>

    await sogni.account.withdraw('your-account-password', 100, 'etherlink');