Image Generation
Two-photo engagement portrait generation with Kie.ai GPT Image 2.
Overview
The production flow uses Kie.ai GPT Image 2 to combine two distinct, account-owned reference photos into one engagement portrait.
Endpoint
POST /api/image/generateRequest
{
"imageUrl": "https://media.example.com/uploads/user/person-a.jpg",
"partnerImageUrl": "https://media.example.com/uploads/user/person-b.jpg",
"styleKey": "editorial",
"customPrompt": "Optional scene details"
}Both URLs must belong to the signed-in account. The server validates the style and builds the provider prompt.
Response Flow
- Validate user session and credits
- Reserve one credit and create a processing history record in one transaction
- Send both source images to Kie.ai GPT Image 2
- Apply a server-side watermark for trial previews and upload the result to R2
- Save to
generationHistorytable - Return the image URL and remaining balance; refund the credit on provider or storage failure
Storage
R2 is required for the engagement flow. Provider URLs are mirrored immediately so generation history never depends on an expiring third-party result URL.
History
All generations are tracked in the generationHistory table:
type—imageprompt— User's promptresultUrl— URL of generated imagestatus—completedorfailedcreditsUsed— Credits charged