> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Sample Flows

## Article: Sample Flows

## Article Link: https://dev.wix.com/docs/api-reference/account-level/ai-credits/sample-flows.md

## Article Content:

# AI Credits: Sample Flows

This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.

## Display an account's AI credit balance

Apps that offer AI features often show account owners how many credits they have left. The AI Credits API returns the full balance in a single call, so you can render it in a dashboard or settings page.

To display an account's AI credit balance:

1. Call [Get Balance](https://dev.wix.com/docs/api-reference/account-level/ai-credits/get-balance.md) to retrieve the account's current balance. The request takes no parameters.
1. Read `periodicCredits.balance` for remaining recurring credits and `topUpCredits.balance` for remaining top-up credits, then show the total available as `periodicCredits.balance + (topUpCredits.balance ?? 0)`.
1. Optionally, use `creditBalanceBreakdown` to display credits from each source separately.
1. Refresh the balance after AI actions so the displayed total stays accurate.

## Gate an AI feature on available credits

Before running an AI action that consumes credits, check whether the account has enough credits and prompt the account to top up if it doesn't.

To gate an AI feature on available credits:

1. Call [Get Balance](https://dev.wix.com/docs/api-reference/account-level/ai-credits/get-balance.md) to retrieve the account's current balance.
1. Calculate the total available credits as `periodicCredits.balance + (topUpCredits.balance ?? 0)`.
1. Compare the available credits with the estimated cost of the action, and run the AI action when there are enough credits.
1. When there aren't enough credits, prompt the account to upgrade their plan or purchase top-up credits, and don't run the action.