Image Generation
Generate images with AI using multiple providers
Image Generation
Create AI-generated images from text descriptions using OpenAI DALL-E, Replicate Flux, or Kling AI.
Supported Providers
OpenAI DALL-E 3
Model: dall-e-3
Features:
- Highest quality images
- Best prompt understanding
- 1024×1024 or 1792×1024 resolution
- Natural language prompts
Cost: 5 credits per image
Best For: Professional images, realistic photos, detailed artwork
OpenAI DALL-E 2
Model: dall-e-2
Features:
- Good quality
- Faster generation
- 512×512, 1024×1024 resolution
- Lower cost alternative
Cost: 5 credits per image
Best For: Quick iterations, concept art
Replicate Flux Schnell
Model: black-forest-labs/flux-schnell
Features:
- Fast generation (10-20 seconds)
- Good quality
- Open source model
- Cost-effective
Cost: 3 credits per image
Best For: Rapid prototyping, bulk generation
Kling AI
Model: kling-v1
Features:
- Asian art style support
- Good quality
- Moderate speed
Cost: 4 credits per image
Best For: Asian aesthetics, anime style
Quick Start
Using AI Generator
- Visit
/ai-generator - Select Image Generation
- Choose provider (default: OpenAI)
- Select model (default: dall-e-3)
- Enter prompt
- Click Generate
- Wait 10-30 seconds
- View and download
Using API
const generateImage = async () => {
const response = await fetch("/api/generator/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
ai_type: "image",
provider: "openai",
model: "dall-e-3",
prompt: "A serene Japanese garden with koi pond",
}),
});
const { data } = await response.json();
// Poll for result
setTimeout(async () => {
const result = await fetch("/api/generator/query", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ gen_id: data.gen_id }),
});
const { data: { result_urls } } = await result.json();
console.log("Image URL:", result_urls[0]);
}, 15000); // Wait 15 seconds
};
Prompt Engineering
Structure of a Good Prompt
[Subject] + [Action/Pose] + [Environment] + [Style] + [Details]
Example:
Subject: A red sports car
Action: drifting around a corner
Environment: in a neon-lit cyberpunk city
Style: cinematic, dramatic lighting
Details: motion blur, rain reflections, 4K quality
Full Prompt:
A red sports car drifting around a corner in a neon-lit cyberpunk city,
cinematic dramatic lighting, motion blur, rain reflections, 4K quality
Prompt Examples
Portrait:
Professional headshot of a business woman, confident expression,
office background, natural lighting, sharp focus, corporate style
Landscape:
Majestic mountain landscape at sunrise, misty valleys,
golden hour lighting, wide angle, nature photography
Product:
Modern smartphone on a clean white surface, minimalist composition,
soft shadows, product photography, high-end commercial style
Artistic:
Abstract art, flowing liquid colors, purple and gold gradient,
smooth curves, digital art, 8K resolution
Fantasy:
Dragon flying over ancient castle, magical atmosphere,
fantasy art style, detailed scales, dramatic clouds
Tips for Better Results
-
Be Specific:
- Instead of "a dog", say "a golden retriever puppy"
- Instead of "nice lighting", say "soft morning sunlight"
-
Include Style:
- Photography: "professional photo", "DSLR", "bokeh"
- Art: "oil painting", "watercolor", "digital art"
- 3D: "3D render", "octane render", "unreal engine"
-
Mention Quality:
- "4K", "8K", "high resolution"
- "professional", "award-winning"
- "detailed", "intricate"
-
Avoid Negatives:
- DALL-E doesn't support negative prompts well
- Focus on what you WANT, not what you don't want
Configuration
API Keys
Method 1: Admin UI (Recommended)
- Visit
/admin/ai-config - Add providers: openai, replicate, kling
- Enter API keys
- Enable and save
Method 2: Environment Variables
OPENAI_API_KEY="sk-proj-xxx"
REPLICATE_API_TOKEN="r8_xxx"
KLING_ACCESS_KEY="xxx"
Get API Keys
OpenAI:
- Visit platform.openai.com
- Sign up / Sign in
- Go to API keys
- Create new secret key
- Copy and save (shown only once)
Replicate:
- Visit replicate.com
- Sign up / Sign in
- Go to Account > API tokens
- Copy default token or create new
Kling:
- Visit Kling AI platform
- Sign up and verify account
- Get API access key from dashboard
Advanced Usage
Batch Generation
Generate multiple images:
const prompts = [
"A red apple on white background",
"A green apple on white background",
"A yellow apple on white background",
];
for (const prompt of prompts) {
await fetch("/api/generator/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
ai_type: "image",
provider: "replicate", // Cheaper for batch
model: "black-forest-labs/flux-schnell",
prompt,
}),
});
// Add delay to avoid rate limiting
await new Promise(r => setTimeout(r, 1000));
}
Style Transfer
Create variations of a concept in different styles:
const basePrompt = "A coffee cup on a wooden table";
const styles = [
"photorealistic, DSLR, shallow depth of field",
"oil painting, impressionist style, visible brush strokes",
"minimalist vector art, flat design, pastel colors",
"anime style, vibrant colors, cel shading",
];
styles.forEach(style => {
generateImage(`${basePrompt}, ${style}`);
});
Credit Costs Comparison
| Provider | Model | Cost | Speed | Quality |
|---|---|---|---|---|
| OpenAI | DALL-E 3 | 5 | Medium | Highest |
| OpenAI | DALL-E 2 | 5 | Fast | Good |
| Replicate | Flux | 3 | Fast | Good |
| Kling | kling-v1 | 4 | Medium | Good |
Recommendation:
- Best Quality: OpenAI DALL-E 3
- Best Value: Replicate Flux Schnell
- Balanced: Kling v1
Troubleshooting
Image not generating
Check:
- Credit balance (need 3-5 credits)
- API key configured
- Provider service status
- Prompt doesn't violate policies
Poor quality results
Try:
- Switch to DALL-E 3
- Add quality keywords: "high resolution", "professional"
- Be more specific in prompt
- Regenerate with refined prompt
Content policy violation
Error: "Your request was rejected as a result of our safety system"
Solutions:
- Avoid violence, gore, explicit content
- Rephrase prompt to be more general
- Use different provider
- Check provider's content policy
Rate limit exceeded
Error: "Rate limit exceeded"
Solutions:
- Wait a few minutes before retrying
- Use different API key
- Upgrade API quota with provider
- Use alternative provider
Best Practices
-
Test prompts iteratively:
- Start simple
- Refine based on results
- Build a prompt library
-
Choose right provider:
- Quality needed? → DALL-E 3
- Cost conscious? → Replicate Flux
- Specific style? → Try different providers
-
Download immediately:
- URLs expire
- Save important results
-
Monitor credits:
- Check balance regularly
- Plan generations accordingly
Next Steps
- Video Generation - Generate videos
- AI Generator - Use the UI
- AI APIs - API reference
- Credit System - Manage credits