Token Authentication & Credits
AI Token Authentication
Before recording can begin, the app must obtain a valid AI token for server authentication.
Token Endpoint
| Field | Value |
|---|---|
| URL | https://kagtryxgjwavupzlmlzv.supabase.co/functions/v1/generate_ai_token |
| Method | POST |
| Authorization | User Supabase JWT (Bearer token) |
Token Request
{
"request_type": "ai_voice_chat_token"
}
Token Response
{
"ai_token": "eyJhbGciOiJIUzI1NiIs...",
"expires_in": 600
}
The token expires in 600 seconds (10 minutes).
Token Validation Rules
- Valid: Token exists AND expires in more than 3 minutes
- Invalid: No token OR token expires within 3 minutes
- Token is stored in memory only (not persisted to storage)
- New token requested automatically when invalid
Code Location
_isAITokenValid()at line ~1750 inai_voice_tab.dart_requestAIToken()at line ~1772 inai_voice_tab.dart
Credit System
Users have a credit-based system that limits AI voice chat usage.
Credit Types
| Type | Description | Expiry |
|---|---|---|
| Weekly Credits | Reset periodically (tracked by weekly_reset_date) |
Resets on schedule |
| Extra/Bank Credits | Purchased credits | Never expire |
Credit Check Logic
A user can record if:
- Weekly credits not exhausted (
weekly_used_credits < weekly_limit_credits), OR - Bank credits available (
bank_used_credits < bank_limit_credits)
Credit Update Flow
- Server returns
ai_usage_in_secondsin response - App rounds up to nearest integer for credits used
- If weekly limit is 0: credits added directly to bank usage
- If weekly credits available: deduct from weekly first
- If weekly exhausted: deduct from bank credits
- Updated credits saved to
user_profile.json
Source Data
user_profile.json->ai_usageobject_hasAvailableCredits()at line ~1669_updateAIUsageCredits()at line ~1581