Payments and Balance
This guide explains how subscribers purchase payment plans and check their credit balances. These operations are typically performed by users who want to access AI agents.Overview
The payment flow consists of:- Discovering Plans: Browse available payment plans for agents
- Ordering Plans: Purchase a plan to receive credits
- Checking Balance: Monitor available credits and subscription status
Get Plan Balance
Subscribers can check their available credits for a specific plan:Balance Response Structure
The balance response contains:Working with Balance
Order a Plan
Subscribers purchase plans to receive credits:Crypto Payment
For plans priced in cryptocurrency:Fiat Payment (Stripe)
For plans priced in fiat currency, use Stripe checkout:Complete Purchase Flow
Waiting for Balance Updates
After ordering a plan, credits are allocated on-chain, which may take a few seconds:Check Multiple Plan Balances
If a subscriber has multiple plans:Stripe Checkout Integration
Complete Stripe Flow
Plan Information
Before ordering, subscribers might want to view plan details:Complete Example: Purchase Flow with UI
Best Practices
- Check Balance First: Always check existing balance before ordering
- Wait for Settlement: Allow time for on-chain credit allocation after purchase
- Handle Errors: Wrap order operations in try-catch blocks
- User Feedback: Provide clear feedback during the purchase process
- Balance Monitoring: Check balance before each agent request
- Stripe Redirects: Use absolute URLs for Stripe success/cancel URLs
Related Documentation
- Payment Plans - Understanding plan types and pricing
- Querying an Agent - Using credits to access agents
Source References:
src/api/plans-api.ts(orderPlan, getPlanBalance, getStripeCheckout methods)tests/e2e/test_payments_e2e.test.ts(ordering and balance verification)