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. 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
| Model | Model ID | Billing Type | Current Price | Notes |
|---|---|---|---|---|
| Flux 2 Pro | flux-2-pro | Pay-per-call - Chat | $0.0300/call | Recommended default for generation and editing |
| Flux 2 Flex | flux-2-flex | Pay-per-call - Chat | $0.0600/call | More controllable editing and design workflows |
| Flux 2 Max | flux-2-max | Pay-per-call - Chat | $0.0700/call | Highest-quality final assets |
| Flux Kontext Pro | flux-kontext-pro | Pay-per-call - Chat | $0.0350/call | Legacy Kontext-compatible model |
| Flux Kontext Max | flux-kontext-max | Pay-per-call - Chat | $0.0700/call | Legacy high-quality Kontext model |
📐 Size Parameters
Flux 2 and Flux Kontext use different parameter structures:| Scenario | Endpoint | Size Parameter | Notes |
|---|---|---|---|
| Flux 2 text-to-image | /v1/images/generations | size or width + height | No input_image field |
| Flux 2 single-image editing | /v1/images/generations | input_image + size or width + height | input_image is a public URL or data URL |
| Flux 2 multi-image editing | /v1/images/generations | input_image through input_image_8 + size parameters | Reference images are numbered by field order |
| Legacy Flux Kontext | /v1/images/generations | extra_body.aspect_ratio | Legacy aspect-ratio format |
Flux 2 Common Sizes
| Parameter | Output Size | Use Case |
|---|---|---|
"size": "1024x1024" | 1024×1024 | Square images, avatars, product shots |
"size": "1792x1024" | 1792×1024 | Landscape covers, banners, hero images |
"size": "1024x1792" | 1024×1792 | Portrait posters, mobile covers, story images |
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:
| 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
Flux 2 Text-to-Image cURL
Flux 2 Python Example
📝 Parameter Details
Flux 2 Text-to-Image Parameters
| Parameter | Type | Range/Options | Description | Default |
|---|---|---|---|---|
model | string | flux-2-pro / flux-2-flex / flux-2-max | Model ID | - |
prompt | string | - | Image prompt | - |
n | integer | 1 | Number of images | 1 |
size | string | e.g. 1024x1024 / 1792x1024 | OpenAI-style output size; use this or width / height | 1024x1024 |
width | integer | 64-2048, preferably divisible by 16 | BFL-style output width; use this or size | 1024 |
height | integer | 64-2048, preferably divisible by 16 | BFL-style output height; use this or size | 1024 |
output_format | string | jpeg / png | Output image format | jpeg |
seed | integer | - | Fixed seed for reproducibility | Random |
💡 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.