Image Generation API
Generate, edit, dan variasi gambar menggunakan AI. Use case: thumbnail generator, avatar builder, product mockup, illustration.
DALL-E (OpenAI)
const response = await openai.images.generate({
model: "dall-e-3",
prompt: "A minimalist illustration of a web developer coding, flat design, blue tones",
n: 1,
size: "1024x1024",
quality: "standard", // or "hd"
});
const imageUrl = response.data[0].url;
Image Analysis (Vision)
// GPT-4o bisa "melihat" gambar
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{
role: "user",
content: [
{ type: "text", text: "Apa yang ada di gambar ini?" },
{ type: "image_url", image_url: { url: imageUrl } },
],
}],
});
Alternatives
- Stability AI — Stable Diffusion API, lebih murah
- Replicate — Run any open-source model via API
- Midjourney — Kualitas tertinggi, tapi Discord-based (tidak ada direct API)
Best Practices
- Cache generated images — jangan generate ulang untuk prompt yang sama
- Simpan di object storage (S3/R2), bukan serve dari API URL (expired)
- Content moderation — filter prompt yang inappropriate
- Cost control — image generation mahal ($0.04-0.12 per gambar)