Prerequisites
Get API Key
Log in to laozhang.ai console to obtain your API key
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, Flux Kontext Pro $0.035/image, Flux Kontext Max $0.07/image, only the billing method differs.

Flux Image Generation API
Flux is an industry-leading image generation model. Through LaoZhang API’s OpenAI-compatible interface, you can easily call Flux Kontext Pro and Max models to generate high-quality images. We offer better pricing than official rates, combined with exchange rate advantages and recharge bonuses to save you more costs.🎯 High-Quality Generation
Flux models are renowned for exceptional image quality and detail, supporting flexible aspect ratios from 3:7 to 7:3.
Flux models are renowned for exceptional image quality and detail, supporting flexible aspect ratios from 3:7 to 7:3.
🌟 Core Features
- 📐 Flexible Ratios: Supports continuous aspect ratio range from 3:7 to 7:3
- 🎨 High-Quality Output: 1 megapixel images with rich details and artistic expression
- 💰 Price Advantage: Better rates than official pricing, cost savings
- 🔧 OpenAI Compatible: Uses standard Images API format, easy integration
- ⏱️ URL Validity: Generated result URLs valid for 10 minutes, download promptly
- 🔄 Reproducibility: Supports seed parameter for consistent results
📋 Model Comparison
| Model | Model ID | LaoZhang API Price | Official Price | Savings | Features |
|---|---|---|---|---|---|
| Flux Kontext Pro | flux-kontext-pro | $0.035/image | $0.040/image | 12.5% | Cost-effective, suitable for batch use |
| Flux Kontext Max | flux-kontext-max | $0.07/image | $0.08/image | 12.5% | Highest quality, professional use |
📐 Supported Aspect Ratios
Flux models support continuous aspect ratio range from 3:7 to 7:3, maintaining approximately 1 megapixel total. Here are some common ratio examples:| Ratio | Type | Approximate Size | Use Case |
|---|---|---|---|
1:1 | Square | 1024×1024 | General use, social media avatars |
2:3 | Vertical | ~832×1248 | Phone wallpapers, portrait photos |
3:2 | Horizontal | ~1248×832 | Desktop wallpapers, landscape photos |
4:3 | Standard Horizontal | ~1182×886 | Traditional displays, presentations |
16:9 | Widescreen | ~1408×792 | Modern displays, video thumbnails |
9:16 | Vertical Screen | ~792×1408 | Mobile videos, vertical posters |
21:9 | Ultra-wide | ~1680×720 | Movie posters, ultra-wide displays |
3:7 | Narrowest Vertical | ~662×1544 | Bookmarks, vertical long images |
7:3 | Widest Horizontal | ~1544×662 | Website banners, panoramic images |
📏 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
Basic Example
📝 Parameter Details
Parameters Passed via extra_body
| Parameter | Type | Range/Options | Description | Default |
|---|---|---|---|---|
aspect_ratio | string | 3:7 to 7:3 | Output image aspect ratio | ”1:1” |
seed | integer | Any integer | Random seed for reproducibility | Random |
safety_tolerance | integer | 0-6 | Content safety control, 0=strictest, 6=most lenient | 2 |
output_format | string | ”jpeg”, “png” | Output image format | ”jpeg” |
prompt_upsampling | boolean | true/false | Auto-enhance prompt | false |
💡 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 Kontext Pro:- ✅ Daily design needs
- ✅ Batch content generation
- ✅ Cost-sensitive projects
- ✅ Rapid prototyping
- ✅ Professional design works
- ✅ Commercial use images
- ✅ High-quality requirements
- ✅ Print output needs
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:
- All Flux-specific parameters must be passed via
extra_body - Cannot use Flux proprietary parameters directly in top-level parameters
- All Flux-specific parameters must be passed via
-
Aspect Ratio Range:
- Supports continuous range from 3:7 to 7:3
- Not limited to fixed ratios, can use any ratio within range
- System auto-adjusts size to maintain ~1 megapixel
-
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 models focus on high-quality image generation, supporting flexible aspect ratios (3:7 to 7:3), particularly suitable for professional designs requiring specific dimensions.Q: How to choose between Pro and Max versions?
A:- Pro: Cost-effective, $0.035/image, suitable for daily use and batch generation
- Max: Highest quality, $0.07/image, suitable for commercial works and professional needs
Q: Can I use any aspect ratio?
A: You can use any ratio within the 3:7 to 7:3 range, such as5:4, 16:10, 21:9, etc. The system auto-adjusts to maintain ~1 megapixel.
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 API natively only supports single image input, but through our batch processing scripts, you can achieve dual-image composition processing.Use Cases
- Pattern Transfer: Transfer design patterns onto clothing models
- Style Fusion: Combine characteristic elements from two images
- Comparison Display: Show original and target effect simultaneously
Technical Approach
Image Merging Strategy
Image Merging Strategy
- Auto Download: Fetch two input images from URLs
- Smart Merge: Use Python PIL to stitch images side by side
- API Call: Use merged image as single input
- Result Processing: AI performs intelligent processing based on merged image
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
- Multi-Image Processing Script
- Flux Image Edit API - Edit existing images
- Pricing Calculator - Real-time price query
- Online Demo - Test Flux effects
🎨 Pro Tip: Combining different aspect ratios and model versions can meet various needs from social media to professional design!