Skip to main content

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.
Token Settings
If billing mode is not configured, API calls will fail. You must complete this configuration first!

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.

🌟 Core Features

  • 📐 Concrete Sizing: Flux 2 supports size and width / height
  • 🎨 High-Quality Output: Supports common sizes such as 1024×1024, 1792×1024, and 1024×1792
  • 🧩 Multi-Image Editing: Native Flux 2 uses input_image through input_image_8 for 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

💡 Pricing note: Flux usage is billed by the model’s current price. Check the console for real-time pricing and call logs.

📐 Size Parameters

Flux 2 and Flux Kontext use different parameter structures:
Do not use multipart -F "image=@..." for Flux 2 image editing. Use a JSON request and place reference images in input_image, input_image_2, input_image_3, and so on.

Flux 2 Common Sizes

Legacy Flux Kontext Ratios

Legacy flux-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

Editing endpoint: Single-image and multi-image editing also use /v1/images/generations; input_image triggers edit mode. See Flux Image Editing.

💡 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
Flux 2 Flex:
  • ✅ More controllable editing workflows
  • ✅ Complex design iteration
  • ✅ Balanced quality and cost
Flux 2 Max:
  • ✅ Highest quality requirements
  • ✅ Final commercial assets
  • ✅ Complex compositions and strong consistency needs
Flux Kontext Pro / Max:
  • ✅ 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

  1. URL Validity:
    • Generated image URLs are only valid for 10 minutes
    • Must download before expiration
    • Recommended to download immediately after generation
  2. Parameter Passing:
    • Flux 2 text-to-image: pass size or width / height as top-level JSON fields
    • Flux 2 image editing: pass input_image and size parameters in JSON
    • Legacy Flux Kontext: use extra_body.aspect_ratio
  3. Size Range:
    • Flux 2 common sizes: 1024x1024, 1792x1024, 1024x1792
    • For Flux 2 editing, use either size or width + height
    • Legacy Flux Kontext supports continuous aspect ratios from 3:7 to 7:3
  4. Content Safety:
    • safety_tolerance parameter controls moderation strictness (0-6)
    • 0 = strictest, 6 = most lenient
    • Default value 2 suitable for most scenarios
  5. Output Format:
    • Default JPEG format, smaller files
    • PNG format higher quality but larger files
    • Choose appropriate format based on use case
  6. Prompt Processing:
    • prompt_upsampling auto-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 existing aspect_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 as 1024x1024, 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 same seed 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:
  1. Download immediately after generation
  2. Use concurrency control to avoid excessive processing time
  3. 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

  1. Multi-image fields: Use input_image, input_image_2, and input_image_3
  2. Prompt references: Use image 1, image 2, and image 3 in the prompt
  3. Size control: Use width and height
  4. Result handling: Download the returned URL immediately
  • 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

Size requirement: For Flux 2 editing, use width / height, for example 1792 × 1024 for landscape or 1024 × 1792 for portrait.
🎨 Pro Tip: Start with flux-2-pro for most tests, then move to flux-2-max for final high-quality assets when needed.