Prerequisites
1
Get API Key
Log in to laozhang.ai console to obtain your API key
2
Configure Billing Mode
Edit token settings and choose one of the following billing modes (same price for both):
- Volume Priority (Recommended): Uses balance billing first, automatically switches when balance is insufficient. Suitable for most users
- Pay-per-call: Direct deduction for each call. Suitable for strict budget control scenarios
Both modes have exactly the same price. Current Flux models include
flux-2-pro, flux-2-max, flux-2-flex, flux-kontext-pro, and flux-kontext-max; check the console for real-time pricing.
Flux Image Generation API
Flux is an industry-leading image generation and editing model. Through LaoZhang API’s/v1/images/generations endpoint, you can call Flux 2 for text-to-image generation. When input_image is present, the same endpoint becomes image editing; with input_image_2 through input_image_8, it becomes multi-image fusion editing.
🎯 High-Quality Generation
Flux 2 is recommended for new image generation and multi-reference editing workflows. Flux Kontext remains available for legacy integrations.
Flux 2 is recommended for new image generation and multi-reference editing workflows. Flux Kontext remains available for legacy integrations.
🌟 Core Features
- 📐 Concrete Sizing: Flux 2 supports
sizeandwidth/height - 🎨 High-Quality Output: Supports common sizes such as 1024×1024, 1792×1024, and 1024×1792
- 🧩 Multi-Image Editing: Native Flux 2 uses
input_imagethroughinput_image_8for multiple reference images - 💰 Pricing Details: Pricing is shown in the console for procurement review
- 🔧 JSON API: Text-to-image, single-image editing, and multi-image editing all use
/v1/images/generations - ⏱️ URL Validity: Generated result URLs valid for 10 minutes, download promptly
- 🔄 Reproducibility: Supports seed parameter for consistent results
📋 Model Comparison
📐 Size Parameters
Flux 2 and Flux Kontext use different parameter structures:Flux 2 Common Sizes
Legacy Flux Kontext Ratios
Legacyflux-kontext-pro / flux-kontext-max support continuous aspect ratios from 3:7 to 7:3, maintaining approximately 1 megapixel total:
📏 Custom Ratios: Besides the examples above, you can use any ratio within the 3:7 to 7:3 range, such as
5:4, 4:5, 16:10, etc. The system automatically adjusts size to maintain approximately 1 megapixel total area.🚀 Quick Start
Flux 2 Text-to-Image cURL
Flux 2 Python Example
📝 Parameter Details
Flux 2 Text-to-Image Parameters
💡 Best Practices
1. URL Management and Download Strategy
Since Flux generated image URLs are only valid for 10 minutes, proper download strategy is crucial:2. Model Selection Guide
Flux 2 Pro:- ✅ Recommended default model
- ✅ Text-to-image and multi-image editing
- ✅ Cost-sensitive projects
- ✅ Product images, posters, and general design assets
- ✅ More controllable editing workflows
- ✅ Complex design iteration
- ✅ Balanced quality and cost
- ✅ Highest quality requirements
- ✅ Final commercial assets
- ✅ Complex compositions and strong consistency needs
- ✅ Legacy integrations
- ✅ Daily design needs
- ✅ Batch content generation
3. Prompt Optimization
Based on official documentation recommendations, detailed and descriptive prompts yield better results:⚠️ Important Notes
-
URL Validity:
- Generated image URLs are only valid for 10 minutes
- Must download before expiration
- Recommended to download immediately after generation
-
Parameter Passing:
- Flux 2 text-to-image: pass
sizeorwidth/heightas top-level JSON fields - Flux 2 image editing: pass
input_imageand size parameters in JSON - Legacy Flux Kontext: use
extra_body.aspect_ratio
- Flux 2 text-to-image: pass
-
Size Range:
- Flux 2 common sizes:
1024x1024,1792x1024,1024x1792 - For Flux 2 editing, use either
sizeorwidth+height - Legacy Flux Kontext supports continuous aspect ratios from 3:7 to 7:3
- Flux 2 common sizes:
-
Content Safety:
safety_toleranceparameter controls moderation strictness (0-6)- 0 = strictest, 6 = most lenient
- Default value 2 suitable for most scenarios
-
Output Format:
- Default JPEG format, smaller files
- PNG format higher quality but larger files
- Choose appropriate format based on use case
-
Prompt Processing:
prompt_upsamplingauto-optimizes prompts- May change original intent, recommended to test first
- Significant effect on simple prompts
🔍 FAQ
Q: Why do image URLs expire?
A: This is Flux official’s security design. All generated image URLs automatically expire after 10 minutes. Please download and save promptly.Q: How is Flux different from other models?
A: Flux focuses on high-quality image generation and editing. Flux 2 supports text-to-image, multi-image editing, and concrete size control; legacy Flux Kontext is best for existingaspect_ratio integrations.
Q: How to choose between Pro, Flex, and Max?
A:- flux-2-pro: $0.0300/call, recommended default for most generation and editing
- flux-2-flex: $0.0600/call, suitable for more controlled and complex edits
- flux-2-max: $0.0700/call, suitable for highest-quality final commercial assets
- flux-kontext-pro/max: legacy Kontext-compatible models
Q: Can I use any aspect ratio?
A: For Flux 2, use concrete sizes such as1024x1024, 1792x1024, and 1024x1792. Legacy Flux Kontext supports continuous aspect ratios from 3:7 to 7:3.
Q: How to set safety_tolerance?
A:- 0-1: Corporate/commercial environment, strictest
- 2-3: General creation, balanced mode (recommended)
- 4-6: Artistic creation, more lenient
Q: What does prompt_upsampling do?
A: When enabled, AI automatically expands and optimizes your prompt, especially suitable for brief prompts. But may change original meaning, recommended to test first.Q: How to ensure reproducible results?
A: Use the sameseed value and identical other parameters to generate consistent results. This is helpful for iterative design.
Q: How to avoid URL expiration in batch generation?
A:- Download immediately after generation
- Use concurrency control to avoid excessive processing time
- Consider using async processing for efficiency
🎯 Multi-Image Processing Solution
Flux 2 supports multi-image editing. Use/v1/images/generations with JSON fields input_image, input_image_2, and input_image_3, up to input_image_8; repeated multipart image fields are not the multi-image structure.
Use Cases
- Pattern Transfer: Transfer design patterns onto clothing models
- Style Fusion: Combine characteristic elements from multiple images
- Product Composition: Fuse product, background, and design references into one scene
Technical Approach
Flux 2 Multi-Image Strategy
Flux 2 Multi-Image Strategy
- Multi-image fields: Use
input_image,input_image_2, andinput_image_3 - Prompt references: Use image 1, image 2, and image 3 in the prompt
- Size control: Use
widthandheight - Result handling: Download the returned URL immediately
Batch Processing Capability
Batch Processing Capability
- Supports automated processing of multiple image pairs
- Unified prompt control for processing effects
- Automatic result download and file management
- Complete error handling and logging
Quick Start
🔗 Related Resources
- Complete Example Code
- Flux Image Edit API - Edit existing images
- Pricing Calculator - Real-time price query
- Online Demo - Test Flux effects
🎨 Pro Tip: Start with
flux-2-pro for most tests, then move to flux-2-max for final high-quality assets when needed.