iamge genration credits fixing - not fixed
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Billing Module
|
||||
|
||||
**Last Verified:** January 8, 2026
|
||||
**Status:** ✅ Active (Payment System Refactored January 2026)
|
||||
**Last Verified:** January 10, 2026
|
||||
**Status:** ✅ Active (Image Generation Credit System Complete January 2026)
|
||||
**Backend Path:** `backend/igny8_core/modules/billing/` + `backend/igny8_core/business/billing/`
|
||||
**Frontend Path:** `frontend/src/pages/Billing/` + `frontend/src/pages/Account/`
|
||||
|
||||
@@ -208,6 +208,36 @@ credits = CreditService.calculate_credits_for_image(
|
||||
# Returns: 15 (3 images × 5 credits)
|
||||
```
|
||||
|
||||
### Check Credits for Image Generation (NEW v1.7.1)
|
||||
|
||||
```python
|
||||
# Pre-check credits before image generation starts
|
||||
# Raises InsufficientCreditsError if not enough credits
|
||||
required = CreditService.check_credits_for_image(
|
||||
account=account,
|
||||
model_name='dall-e-3', # Model with credits_per_image = 5
|
||||
num_images=3
|
||||
)
|
||||
# Returns: 15 (required credits) if sufficient, raises exception if not
|
||||
```
|
||||
|
||||
### Deduct Credits for Image Generation (v1.7.1 Verified)
|
||||
|
||||
```python
|
||||
# Called after each successful image generation
|
||||
credits_deducted = CreditService.deduct_credits_for_image(
|
||||
account=account,
|
||||
model_name='dall-e-3',
|
||||
num_images=1,
|
||||
description='Image generation: Article Title',
|
||||
metadata={'image_id': 123, 'content_id': 456},
|
||||
cost_usd=0.04,
|
||||
related_object_type='image',
|
||||
related_object_id=123
|
||||
)
|
||||
# Logs to CreditTransaction and CreditUsageLog
|
||||
```
|
||||
|
||||
### Calculate Credits from Tokens by Model (NEW v1.4.0)
|
||||
|
||||
```python
|
||||
@@ -327,5 +357,7 @@ Displays:
|
||||
| Feature | Status | Description |
|
||||
|---------|--------|-------------|
|
||||
| ~~AI Model Config database~~ | ✅ v1.4.0 | Model pricing moved to AIModelConfig |
|
||||
| Image model quality tiers | ✅ v1.4.0 | credits_per_image per quality tier |
|
||||
| Credit service enhancements | 🔄 v1.5.0 | Model-specific calculation methods |
|
||||
| ~~Image model quality tiers~~ | ✅ v1.4.0 | credits_per_image per quality tier |
|
||||
| ~~Credit service enhancements~~ | ✅ v1.7.1 | Model-specific calculation methods |
|
||||
| ~~Image generation credit check~~ | ✅ v1.7.1 | Pre-generation credit verification |
|
||||
| ~~Image generation logging~~ | ✅ v1.7.1 | AITaskLog + notifications for images |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Credit System
|
||||
|
||||
**Last Verified:** January 5, 2026
|
||||
**Status:** ✅ Simplified (v1.5.0)
|
||||
**Last Verified:** January 10, 2026
|
||||
**Status:** ✅ Complete (v1.7.1 - Image Generation Credits)
|
||||
|
||||
---
|
||||
|
||||
@@ -93,7 +93,7 @@ Credits calculated from actual token usage:
|
||||
| Content Generation | gpt-4o | 1,000 |
|
||||
| Content Optimization | gpt-4o-mini | 10,000 |
|
||||
|
||||
### Fixed-Cost Operations (Image AI)
|
||||
### Fixed-Cost Operations (Image AI) - v1.7.1 Complete
|
||||
|
||||
Credits per image based on quality tier:
|
||||
|
||||
@@ -103,6 +103,13 @@ Credits per image based on quality tier:
|
||||
| Quality | dall-e-3 | 5 |
|
||||
| Premium | google:4@2 | 15 |
|
||||
|
||||
**Image Generation Credit Flow (v1.7.1):**
|
||||
1. Pre-check: `CreditService.check_credits_for_image()` verifies sufficient credits
|
||||
2. Generation: Images generated via `process_image_generation_queue` Celery task
|
||||
3. Post-deduct: `CreditService.deduct_credits_for_image()` called per successful image
|
||||
4. Logging: `CreditUsageLog` + `CreditTransaction` + `AITaskLog` entries created
|
||||
5. Notifications: `NotificationService.notify_images_complete/failed()` called
|
||||
|
||||
### Free Operations
|
||||
|
||||
| Operation | Cost |
|
||||
@@ -452,3 +459,58 @@ All AI operations logged in `CreditUsageLog` with:
|
||||
- Model used
|
||||
- Token counts
|
||||
- Related object metadata
|
||||
|
||||
---
|
||||
|
||||
## Image Generation Credit System (v1.7.1)
|
||||
|
||||
### Implementation Details
|
||||
|
||||
**Files:**
|
||||
- `CreditService.check_credits_for_image()` - [credit_service.py:307-335](../backend/igny8_core/business/billing/services/credit_service.py#L307-L335)
|
||||
- `process_image_generation_queue` credit check - [tasks.py:290-319](../backend/igny8_core/ai/tasks.py#L290-L319)
|
||||
- `deduct_credits_for_image()` - [tasks.py:745-770](../backend/igny8_core/ai/tasks.py#L745-L770)
|
||||
- AITaskLog logging - [tasks.py:838-875](../backend/igny8_core/ai/tasks.py#L838-L875)
|
||||
- Notifications - [tasks.py:877-895](../backend/igny8_core/ai/tasks.py#L877-L895)
|
||||
|
||||
### Credit Flow for Image Generation
|
||||
|
||||
```
|
||||
1. User triggers image generation
|
||||
↓
|
||||
2. CreditService.check_credits_for_image(account, model, num_images)
|
||||
- Calculates: credits_per_image × num_images
|
||||
- Raises InsufficientCreditsError if balance < required
|
||||
↓
|
||||
3. process_image_generation_queue() processes each image
|
||||
↓
|
||||
4. For each successful image:
|
||||
CreditService.deduct_credits_for_image()
|
||||
- Creates CreditUsageLog entry
|
||||
- Creates CreditTransaction entry
|
||||
- Updates account.credits balance
|
||||
↓
|
||||
5. After all images processed:
|
||||
- AITaskLog entry created
|
||||
- Notification created (success or failure)
|
||||
```
|
||||
|
||||
### Logging Locations
|
||||
|
||||
| Table | What's Logged | When |
|
||||
|-------|---------------|------|
|
||||
| CreditTransaction | Credit deduction (financial ledger) | Per image |
|
||||
| CreditUsageLog | Usage details (model, cost, credits) | Per image |
|
||||
| AITaskLog | Task execution summary | After batch |
|
||||
| Notification | User notification | After batch |
|
||||
|
||||
### Automation Compatibility
|
||||
|
||||
Image generation credits work identically for:
|
||||
- Manual image generation (from UI)
|
||||
- Automation Stage 6 (scheduled/manual automation runs)
|
||||
|
||||
Both call `process_image_generation_queue` which handles:
|
||||
- Credit checking before generation
|
||||
- Credit deduction after each successful image
|
||||
- Proper logging to all tables
|
||||
|
||||
Reference in New Issue
Block a user