Skip to main content

Prerequisites

1 Get API Key Log in to YeLIn 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, Flux Kontext Pro 0.035/image,FluxKontextMax0.035/image, Flux Kontext Max 0.07/image, only the billing method differs.
请在 Console 查看对应界面截图。
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 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.

🌟 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

💡 Price Advantage: Call Flux models through LaoZhang API platform, combined with exchange rate advantage (1:7) and recharge bonus policy (top up $100, get +10% bonus), save over 25% compared to official pricing!

📐 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: 📏 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

💡 Prompt Enhancement: Enabling prompt_upsampling allows AI to automatically optimize and expand your prompt, but may change original intent. Recommended to test first.

💡 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
Flux Kontext Max:
  • ✅ 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

  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:
    • All Flux-specific parameters must be passed via extra_body
    • Cannot use Flux proprietary parameters directly in top-level parameters
  3. 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
  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 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 as 5: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 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 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
  1. Auto Download: Fetch two input images from URLs
  2. Smart Merge: Use Python PIL to stitch images side by side
  3. API Call: Use merged image as single input
  4. Result Processing: AI performs intelligent processing based on merged image
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

Shell Script Python Implementation
Dependency Requirements: Script requires jq, Python3 + PIL, and optionally ImageMagick. See script help for detailed installation instructions. 🎨 Pro Tip: Combining different aspect ratios and model versions can meet various needs from social media to professional design!