Welcome to the Flux Kontext API!
This quickstart guide will walk you through the essential steps to start generating and editing images using state-of-the-art AI models.Overview
Text-to-Image Generation
Create stunning AI images from detailed text descriptions or images
Task Details
Real-time status tracking and webhook callback notifications
Generated images are stored for 14 days and automatically expire after that period.
Authentication
All API requests require authentication via Bearer Token.1
Get Your API Key
Visit the API Key Management Page to obtain your API key.
2
Add to Request Headers
Include your API key in all requests:
Keep your API key secure and never share it publicly. If compromised, reset it immediately in the management page.
Basic Usage
1. Generate an Image from Text
Start by creating your first text-to-image generation task:2. Edit an Existing Image
Modify an existing image using text prompts:3. Check Generation Status
Use the returnedtaskId
to monitor progress:
0
: GENERATING - Task is currently being processed1
: SUCCESS - Task completed successfully2
: CREATE_TASK_FAILED - Failed to create the task3
: GENERATE_FAILED - Task creation succeeded but generation failed
Complete Workflow Example
Here’s a complete example that generates an image and waits for completion:Advanced Features
Model Selection
Choose the appropriate model based on your needs:Aspect Ratio Options
Support for various image formats:Prompt Enhancement
Let the AI optimize your prompts:Safety Tolerance Control
Adjust content moderation levels:Using Callbacks
Set up webhook callbacks for automatic notifications:Learn More About Callbacks
Set up webhook callbacks to receive automatic notifications when your images are ready.
Error Handling
Common error scenarios and how to handle them:Content Policy Violations (Code 400)
Content Policy Violations (Code 400)
Safety Tolerance Out of Range (Code 500)
Safety Tolerance Out of Range (Code 500)
Rate Limiting (Code 429)
Rate Limiting (Code 429)
Best Practices
Performance Optimization
- Use Callbacks: Set up webhook callbacks instead of polling for better performance
- Model Selection: Use
flux-kontext-pro
for standard tasks,flux-kontext-max
for complex scenes - Prompt Engineering: Use detailed, specific prompts for better results
- Image Preprocessing: Ensure input images are accessible and optimized
- Download Management: Download images promptly as they expire after 14 days
- Translation Settings: Set
enableTranslation: false
if your prompts are already in English
Important Limitations
- Language Support: Prompts only support English (use
enableTranslation: true
for auto-translation) - Image Storage: Generated images expire after 14 days
- Original Image URLs: Valid for only 10 minutes after generation
- Safety Tolerance: Generation mode (0-6), Editing mode (0-2)
- Input Images: Must be publicly accessible URLs
Supported Parameters
Core Parameters
Parameter | Type | Description | Default |
---|---|---|---|
prompt | string | Required. Text description for generation/editing | - |
aspectRatio | string | Output image aspect ratio | 16:9 |
model | string | flux-kontext-pro or flux-kontext-max | flux-kontext-pro |
outputFormat | string | jpeg or png | jpeg |
Optional Parameters
Parameter | Type | Description | Default |
---|---|---|---|
inputImage | string | URL for image editing mode | - |
enableTranslation | boolean | Auto-translate non-English prompts | true |
promptUpsampling | boolean | AI prompt enhancement | false |
safetyTolerance | integer | Content moderation level | 2 |
callBackUrl | string | Webhook notification URL | - |
uploadCn | boolean | Use China servers for upload | false |
watermark | string | Watermark identifier | - |
Next Steps
Generate or Edit Images
Learn about all generation and editing parameters and advanced options
Track Progress
Monitor task status and retrieve detailed generation information
Webhook Callbacks
Set up automatic notifications for task completion
Support
Need help? Here are your options:- Technical Support: support@fluxapi.ai
- API Status: Monitor service health and announcements
- Documentation: Explore detailed API references
- Community: Join our developer community for tips and examples