Get started with the Flux Kontext API in minutes. Learn how to generate images from text and edit existing images using AI.
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 notificationsGenerated 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#
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:{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_flux_abc123"
}
}
2. Edit an Existing Image#
Modify an existing image using text prompts:3. Check Generation Status#
Use the returned taskId to monitor progress:0: GENERATING - Task is currently being processed
1: SUCCESS - Task completed successfully
2: CREATE_TASK_FAILED - Failed to create the task
3: 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)
Safety Tolerance Out of Range (Code 500)
Rate Limiting (Code 429)
Best Practices#
1.
Use Callbacks: Set up webhook callbacks instead of polling for better performance
2.
Model Selection: Use flux-kontext-pro for standard tasks, flux-kontext-max for complex scenes
3.
Prompt Engineering: Use detailed, specific prompts for better results
4.
Image Preprocessing: Ensure input images are accessible and optimized
5.
Download Management: Download images promptly as they expire after 14 days
6.
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 optionsTrack Progress
Monitor task status and retrieve detailed generation informationWebhook Callbacks
Set up automatic notifications for task completionSupport#
Need help? Here are your options:API Status: Monitor service health and announcements
Documentation: Explore detailed API references
Community: Join our developer community for tips and examples
Ready to create amazing AI images? Start with the examples above and explore the full API capabilities!