DocHub
Consumable AI credit purchases — same flow as course IAP, credits added to user bank

AI Credits Purchase

Key Points

  • AI credits are consumable products (can be purchased multiple times)
  • Same IAP flow as course purchases
  • Uses purchaseAICredits(productId) method
  • Server adds credits to user’s AI usage bank
  • Validated via /functions/v1/validate_purchase_ai_credits

Purchase Payload

{
  "product_id": "ai_credits_100",
  "purchase_id": "GPA.1234-5678-9012",
  "transaction_date": "1703347200000",
  "status": "PurchaseStatus.purchased",
  "platform": "android",
  "purchase_token": "token-from-google-play"
}

Server Response

After successful validation, the server updates the user’s AI usage bank:

{
  "ai_usage": {
    "weekly_limit_credits": 10,
    "weekly_used_credits": 0,
    "weekly_reset_date": "2025-12-30T00:00:00Z",
    "bank_limit_credits": 200,
    "bank_used_credits": 0
  }
}

bank_limit_credits increases by the number of credits purchased. The weekly allocation is separate and resets automatically.

AI Usage Model

Field Description
weekly_limit_credits Max credits available per week (free tier)
weekly_used_credits Credits consumed this week
weekly_reset_date When the weekly counter resets (ISO 8601)
bank_limit_credits Total purchased credits in the bank
bank_used_credits Purchased credits consumed so far

The app receives AI usage data both from the handshake response and after AI credit purchases.