API Overview
Laozhang API provides comprehensive image processing capabilities, covering image generation, editing, understanding, and more. Supports top-tier models including OpenAI DALL-E, Flux, Sora Image, and GPT-Image-1, offering the most cost-effective image processing solutions.
🎯 Image Processing Capabilities Overview
Text-to-Image Generate high-quality images from text descriptions, supporting multiple styles and sizes
Image Editing Intelligent editing of existing images, supporting partial modifications and style transformations
Image Understanding Analyze and understand image content, supporting object recognition, OCR, and scene description
Multi-Image Fusion Intelligently merge multiple images to create new visual effects
💰 Pricing Overview
Best Value : GPT-4o Image and Sora Image at only $0.01/image , the most cost-effective options on the market!
Model Text-to-Image Price Image Editing Price Features GPT-4o Image $0.01/image $0.01/image 💥 Price killer, excellent quality Sora Image $0.01/image $0.01/image 🚀 Ultra-fast generation, Chinese-friendly DALL-E 3 $0.04/image - 🎨 Official OpenAI, rich details DALL-E 2 $0.02/image $0.02/image 📸 Classic model, stable and reliable Flux Pro $0.035/image - 🌟 Professional-grade quality Flux Max $0.07/image $0.07/image 👑 Highest quality, supports editing GPT-Image-1 Token-based billing Token-based billing 🔧 Flexible control, comprehensive features
🚀 Text-to-Image API
All text-to-image models use the unified OpenAI Images API format:
API Endpoint : POST https://api.laozhang.ai/v1/images/generations
curl https://api.laozhang.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o-image",
"prompt": "A serene Japanese garden with cherry blossoms",
"n": 1,
"size": "1024x1024"
}'
Detailed Model Introduction
🔥 GPT-4o Image (Recommended)
Price Killer : Only $0.01/image, the lowest price for comparable quality!
Advantages : Extreme cost-performance, excellent quality, fast generation speed
Supported Sizes : 1024x1024, 1024x1792, 1792x1024
Use Cases : Batch generation, daily use, commercial projects
🚀 Sora Image
High cost-performance solution implemented through reverse engineering:
# Sora Image uses Chat Completions API
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : "Draw a beautiful sunset seascape【3:2】" # Specify ratio at the end
}]
)
# Extract image URL from returned markdown
import re
content = response.choices[ 0 ].message.content
image_url = re.search( r '! \[ . *? \]\( ( . *? ) \) ' , content).group( 1 )
Price : $0.01/image (fixed price)
Supported Ratios : 【2:3】, 【3:2】, 【1:1】
Features : Native Chinese support, second-level generation
🎨 DALL-E Series
Official OpenAI models, suitable for scenarios requiring detail and creativity:
# DALL-E 3 - Latest version, strong understanding
response = client.images.generate(
model = "dall-e-3" ,
prompt = "A detailed oil painting of a robot playing chess" ,
size = "1024x1024" ,
quality = "hd" ,
style = "vivid"
)
# DALL-E 2 - Classic version, high cost-performance
response = client.images.generate(
model = "dall-e-2" ,
prompt = "A minimalist logo design for a tech company" ,
size = "512x512"
)
🌟 Flux Series
Professional-grade image generation supporting flexible aspect ratios:
# Flux Pro - Professional quality
response = client.images.generate(
model = "black-forest-labs/flux-pro-v1.1" ,
prompt = "Professional product photography of a luxury watch" ,
extra_body = {
"aspect_ratio" : "16:9" , # Flexible aspect ratio
"seed" : 42 , # Reproducible results
"prompt_upsampling" : True # Automatic prompt enhancement
}
)
# Flux Max - Highest quality, supports editing
response = client.images.generate(
model = "black-forest-labs/flux-kontext-max" ,
prompt = "Ultra detailed fantasy landscape with dragons" ,
extra_body = {
"aspect_ratio" : "21:9" , # Ultra-wide
"safety_tolerance" : 2
}
)
Flux-generated image URLs are only valid for 10 minutes, please download and save promptly!
🎨 Image Editing API
OpenAI Standard Editing Interface
Applicable to DALL-E 2 and GPT-Image-1:
# Local editing using mask
response = client.images.edit(
image = open ( "original.png" , "rb" ),
mask = open ( "mask.png" , "rb" ), # White = editing area
prompt = "A sunflower in the vase" ,
model = "dall-e-2" ,
n = 1 ,
size = "1024x1024"
)
Flux Image Editing
Supports more flexible editing control:
# Flux Max editing - Supports online images
response = client.images.edit(
image = "https://example.com/original.jpg" , # Supports URL
mask = "https://example.com/mask.png" , # Optional
prompt = "Transform the car into a futuristic hovering vehicle" ,
model = "black-forest-labs/flux-kontext-max" ,
extra_body = {
"aspect_ratio" : "16:9"
}
)
Sora Image Editing
Implement image editing and multi-image fusion through Chat API:
# Single image editing
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "Turn this image into watercolor style" },
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/photo.jpg" }}
]
}]
)
# Multi-image fusion
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "Merge the style and content of these two images" },
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/style.jpg" }},
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/content.jpg" }}
]
}]
)
👁️ Image Understanding API
Use Chat Completions API to analyze and understand image content:
# Basic image analysis
response = client.chat.completions.create(
model = "gpt-4o" , # or gemini-2.5-pro, claude-3-5-sonnet
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "Please describe this image in detail" },
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/image.jpg" }}
]
}]
)
# OCR text recognition
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "Please extract all text from the image" },
{ "type" : "image_url" , "image_url" : { "url" : "data:image/jpeg;base64,..." }}
]
}]
)
# Multi-image comparison analysis
response = client.chat.completions.create(
model = "gemini-2.5-pro" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "Compare the differences between these two images" },
{ "type" : "image_url" , "image_url" : { "url" : "image1.jpg" }},
{ "type" : "image_url" , "image_url" : { "url" : "image2.jpg" }}
]
}]
)
Recommended Model Comparison
Model Advantages Use Cases GPT-4o Strong overall capabilities, fast speed General analysis, OCR Gemini 2.5 Pro 2M context, detail recognition Complex documents, multi-image analysis Claude 3.5 Sonnet Strong logical reasoning Chart analysis, technical drawings
🎯 Selection Guide
By Budget
Ultra-Low Budget Recommended : Sora Image, GPT-4o ImageFixed $0.01/image, suitable for bulk usage
Balanced Choice Recommended : DALL-E 2, Flux Pro$0.02-0.035/image, quality and price balanced
Quality Focused Recommended : DALL-E 3, Flux Max$0.04-0.07/image, professional-grade output
By Use Case
Use Case Recommended Models Reason E-commerce Product Images GPT-4o Image High cost-performance, stable quality Artistic Creation DALL-E 3, Flux Max Strong creative understanding, rich details Batch Generation Sora Image Lowest price, fast speed Social Media Flux Pro Diverse styles, flexible ratios Image Editing Flux Max, Sora Edit Strong editing capabilities, multi-image support Content Analysis GPT-4o, Gemini 2.5 Accurate understanding, Chinese-friendly
💡 Best Practices
1. Prompt Optimization
[Subject Description] + [Art Style] + [Environment Setting] + [Lighting Effect] + [Quality Modifiers]
Example: A majestic eagle (subject) in photorealistic style (style)
soaring above mountain peaks (environment) during golden hour (lighting)
highly detailed, 8K resolution (quality)
English Prompts : Supported by all models, more precise expression
Chinese Prompts : Natively supported by Sora Image, understood by other models but potentially less effective
Recommendation : Use English for professional scenarios, Chinese for daily use
2. Batch Processing Examples
Standard Images API
Reverse Generation API
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
api_key = "YOUR_API_KEY" ,
base_url = "https://api.laozhang.ai/v1"
)
async def generate_batch_images ( prompts ):
tasks = []
for prompt in prompts:
task = client.images.generate(
model = "dall-e-3" ,
prompt = prompt,
n = 1
)
tasks.append(task)
results = await asyncio.gather( * tasks)
return [r.data[ 0 ].url for r in results]
# Usage example
prompts = [
"A cute cat playing with yarn" ,
"A dog running in the park" ,
"A bird sitting on a branch"
]
urls = await generate_batch_images(prompts)
3. Image Download and Save
Some models (like Flux) generate URLs with expiration times, recommend immediate download and save!
import requests
from datetime import datetime
def download_and_save ( image_url , prefix = "image" ):
response = requests.get(image_url)
timestamp = datetime.now().strftime( "%Y%m %d _%H%M%S" )
filename = f " { prefix } _ { timestamp } .png"
with open (filename, 'wb' ) as f:
f.write(response.content)
return filename
# Generate and save (Standard API)
response = client.images.generate(
model = "flux-pro-v1.1" ,
prompt = "Beautiful sunset"
)
saved_file = download_and_save(response.data[ 0 ].url, "sunset" )
print ( f "Image saved as: { saved_file } " )
# Generate and save (Reverse API - GPT-4o Image/Sora Image)
import re
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{ "role" : "user" , "content" : "Generate a beautiful sunset image" }]
)
content = response.choices[ 0 ].message.content
image_url = re.search( r '! \[ . *? \]\( ( . *? ) \) ' , content).group( 1 )
saved_file = download_and_save(image_url, "sunset" )
print ( f "Image saved as: { saved_file } " )
🔧 Error Handling
Common Error Codes
Error Code Description Solution 400 Parameter error or content violation Check parameter format and prompt content 401 Invalid API Key Verify if API Key is correct 429 Request rate too high Reduce request frequency, use queue 500 Server error Retry later or contact support
Content Policy
Please avoid generating the following content:
❌ Violent, gory content
❌ Adult, pornographic content
❌ Politically sensitive content
❌ Copyright-infringing content
❌ Inappropriate content involving real people
📊 Usage Statistics
Through Laozhang API console, you can view:
Usage statistics by model
Daily/monthly generation counts
Detailed billing and trends
API call logs