AI Features Overview
How chat, image, and video generation work, and which provider powers which route.
Two AI surfaces
This project exposes AI in two different ways that ship independently:
1. Cursor-generator (main product)
The cursor-generator pipeline uses Kie.ai (GPT Image 2 at 1K) for
text-to-image and image-to-image generation. The route is
/api/cursor-generator/generate-all (and /generate-preview). See
lib/cursor-generator/generator.ts and lib/ai-providers/kie.ts.
Background removal is performed client-side with
@imgly/background-removal (no server token needed).
2. Demo routes (optional)
The /api/chat, /api/image/generate, and /api/video/* routes power
the /demo marketing pages. They use Volcano Engine (Doubao) and
are independent from the cursor-generator pipeline. Skip them in
production if you are not shipping the demo pages.
| Surface | Provider | Model | Endpoint |
|---|---|---|---|
| Cursor-generator (image) | Kie.ai | GPT Image 2 (1K) | /api/cursor-generator/generate-all |
| Demo chat | Volcano Engine | doubao-1-5-thinking-pro-250415 | /api/chat/stream |
| Demo image | Volcano Engine | doubao-seededit-3-0-i2i-250628 | /api/image/generate |
| Demo video | Volcano Engine | doubao-seedance-1-0-pro-250528 | /api/video/generate |
Configuration
# Cursor-generator (required for the main product)
KIE_API_KEY="your-kie-api-key"
KIE_API_BASE_URL="https://api.kie.ai"
KIE_IMAGE_MODEL="gpt-image-2-5-flare-image-to-image"
KIE_TEXT_MODEL="gpt-image-2-5-flare-text-to-image"
KIE_IMAGE_RESOLUTION="1K"
# Demo routes only — skip if not shipping /demo
# VOLCANO_ENGINE_API_KEY="your-volcano-engine-api-key"
# VOLCANO_ENGINE_API_URL="https://ark.cn-beijing.volces.com/api/v3"Architecture
lib/
├── ai-providers/
│ └── kie.ts # cursor-generator image gen
├── cursor-generator/
│ ├── generator.ts # main pipeline
│ └── image-processor.ts # client-side bg removal
└── volcano-engine/ # demo routes only
├── config.ts
├── chat.ts
├── image.ts
└── video.tsCredit Integration
Every AI operation follows the deduct-first, refund-on-failure pattern:
- Check if user has enough credits
- Deduct credits from balance
- Call AI API
- If API fails, refund credits automatically
Replacing the cursor-generator provider
To swap Kie.ai for another image provider:
- Replace the call site in
lib/cursor-generator/generator.ts - Update
lib/ai-providers/(keep the samegenerateImage(prompt, imageUrl)signature) - Update environment variables in
lib/env.tsand.env.example - Keep the same credit deduction pattern