AIGC Text-to-Image API Complete Guide
Master API calls for FLUX, Stable Diffusion, DALL-E and more to create stunning AI artwork.
Supported image generation models
FLUX 1.1 Pro
flux-1.1-pro~10秒
最新的 FLUX 旗舰Model, 极致的图像质量
最高 2048x2048
超高质量精准Tip词Understand复杂场景艺术创作
FLUX Dev
flux-dev~5秒
DevelopVersion, 平衡质量与速度
最高 1024x1024
高质量LoRA support快速迭代风格化
FLUX Schnell
flux-schnell~2秒
超快速Generate, 适合实时apply
最高 1024x1024
极速Generate实时预览低成本批量处理
Stable Diffusion XL
stable-diffusion-xl~5秒
经典开源Model, 社区生态丰富
最高 1024x1024
开源ModelControlNet大量 LoRA自定义训练
DALL-E 3
dall-e-3~15秒
OpenAI 的文生图Model, Understand能力强
1024x1024, 1792x1024
自然语言Understand文字渲染创意Generate安全过滤
Midjourney
midjourney-v6~30秒
艺术化程度最高的Model
多种比例
艺术风格美学OptimizeParameter丰富社区驱动
Code Examples
Basic Text-to-Image
Generate high-quality images using FLUX
import requests
import json
# API configuration
API_KEY = "YOUR_API_KEY"
API_URL = "https://api.example.com/v1/images/generations"
# Request parameters
data = {
"model": "flux-1.1-pro", # Options: flux-dev, flux-schnell
"prompt": "A cute cartoon cat sitting on a rainbow, fantasy style, 8K quality, detailed painting",
"negative_prompt": "low quality, blurry, deformed",
"width": 1024,
"height": 1024,
"num_inference_steps": 50, # Inference steps, higher means better quality
"guidance_scale": 7.5, # Prompt guidance scale
"seed": 42 # Random seed; same seed generates the same image
}
# Send request
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(API_URL, headers=headers, json=data)
result = response.json()
# Get image URL
image_url = result["data"][0]["url"]
print(f"Generated image: {image_url}")
# Download image
import urllib.request
urllib.request.urlretrieve(image_url, "generated_image.png")Parameter Reference
| Parameter | Type | Description | Example |
|---|---|---|---|
prompt | string | 图像描述Tip词, 越详细效果越好 | a beautiful sunset over mountains, oil painting style |
negative_prompt | string | 负面Tip词, 描述不想出现的内容 | low quality, blurry, distorted |
width / height | integer | 图像尺寸, need是 8 的倍数 | 1024 |
num_inference_steps | integer | 推理步数, 越高质量越好但速度越慢 | 50 |
guidance_scale | float | Tip词引导强度, 控制与Tip词的匹配程度 | 7.5 |
seed | integer | 随机种子, 相同种子Generate相同图像 | 42 |
Usage Tips
Prompt tips
- Use specific descriptors: materials, lighting, style, color
- Add quality keywords: masterpiece, best quality, ultra-detailed
- Specify artistic styles: oil painting, anime style, photorealistic
- Use weighting syntax: (important:1.2), [less important:0.8]
Common style keywords
- Photorealistic: photorealistic, hyperrealistic, professional photography
- Art styles: oil painting, watercolor, digital art, concept art
- Anime styles: anime, manga, cel shading, studio ghibli style
- Special effects: volumetric lighting, ray tracing, depth of field
Performance optimization
- Handle batch requests asynchronously
- Choose appropriate models and parameters for your use case
- Use fewer steps for quick previews
- Cache frequently generated results
Troubleshooting
- Image distortion: check aspect ratio and use standard sizes
- Poor quality: increase steps and refine prompts
- Generation failed: ensure prompts avoid sensitive content
- Timeouts: reduce batch size and use async processing
Prompt examples
Photorealistic portrait:
portrait of a young woman, natural lighting, shallow depth of field, 85mm lens, professional photography, soft skin, detailed eyes, warm color gradingConcept art:
futuristic cityscape, cyberpunk aesthetic, neon lights, flying vehicles, rain, reflections, volumetric fog, cinematic composition, concept art by simon stalenhagAnime style:
anime girl, cherry blossoms, school uniform, flowing hair, cel shading, studio ghibli style, soft pastel colors, dreamy atmosphere, detailed background