FLUX Kontext API Reference
Overview
| Property | Value |
|---|---|
| Model ID | flux-kontext |
| Type | Text-to-Image, Image-to-Image |
| Pricing | Pro: $0.03/image ยท Max: $0.06/image |
| Average Time | 10-15 seconds |
Authentication
All API requests require authentication using a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEY
Endpoints
1. Submit Generation Task
POST https://api.apixo.ai/api/v1/generateTask/flux-kontext
2. Query Task Status
GET https://api.apixo.ai/api/v1/statusTask/flux-kontext?taskId={taskId}
Request Parameters
Request Body Structure
{
"request_type": "async",
"callback_url": "https://your-server.com/callback",
"input": {
"mode": "pro",
"prompt": "Your image description",
"aspect_ratio": "16:9",
...
}
}
Top-Level Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request_type | string | Yes | Request mode: async (poll results) or callback (webhook notification) |
callback_url | string | No | Webhook URL for callback mode. Must be publicly accessible |
input | object | Yes | Generation parameters (see below) |
Input Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
mode | string | Yes | - | Quality mode: pro ($0.03) or max ($0.06) |
prompt | string | Yes | - | Image description (max 10,000 characters) |
image_url | string | No | - | Input image URL for image-to-image editing |
aspect_ratio | string | Yes | 16:9 | Output ratio: 21:9, 16:9, 4:3, 1:1, 3:4, 9:16 |
output_format | string | No | jpeg | Output format: jpeg or png |
promptUpsampling | boolean | No | false | Enable AI prompt enhancement |
enableTranslation | boolean | No | true | Auto-translate non-English prompts |
safetyTolerance | integer | No | 2 | Content moderation: 0 (strict), 1 (moderate), 2 (balanced) |
watermark | string | No | - | Custom watermark text |
uploadCn | boolean | No | false | Use China servers (true) or international (false) |
Response Format
Task Submission Response
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678"
}
}
Status Query Response
Processing:
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678",
"state": "processing",
"createTime": 1698765400000
}
}
Success:
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678",
"state": "success",
"resultJson": "{\"resultUrls\":[\"https://example.com/image.jpg\"]}",
"costTime": 12000,
"createTime": 1698765400000,
"completeTime": 1698765412000
}
}
Failed:
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678",
"state": "failed",
"failCode": "CONTENT_VIOLATION",
"failMsg": "Content does not meet safety guidelines",
"createTime": 1698765400000,
"completeTime": 1698765412000
}
}
Response Fields:
| Field | Type | Description |
|---|---|---|
code | integer | HTTP status code (200 = success) |
data.taskId | string | Unique task identifier |
data.state | string | Task state: pending, processing, success, failed |
data.resultJson | string | JSON string with resultUrls array (on success) |
data.costTime | integer | Generation time in milliseconds |
data.failCode | string | Error code (on failure) |
data.failMsg | string | Error message (on failure) |
Callback Response
When the task is completed, the system will send a POST request to your callBackUrl in the following format:
Success Callback
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678",
"state": "success",
"resultJson": "{\"resultUrls\":[\"https://example.com/result.jpg\"]}",
"completeTime": 1698765432000,
"createTime": 1698765400000,
"costTime": 32000
}
}
Failure Callback
{
"code": 400,
"message": "failed",
"data": {
"taskId": "task_12345678",
"state": "failed",
"failCode": "CONTENT_VIOLATION",
"failMsg": "Content does not meet safety guidelines",
"completeTime": 1698765432000,
"createTime": 1698765400000,
"costTime": 32000
}
}
Quick Start
1. Text-to-Image Generation
curl -X POST https://api.apixo.ai/api/v1/generateTask/flux-kontext \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_type": "async",
"input": {
"mode": "pro",
"prompt": "A serene mountain landscape at sunset with vibrant colors",
"aspect_ratio": "16:9"
}
}'
Response:
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678"
}
}
2. Check Task Status
curl -X GET "https://api.apixo.ai/api/v1/statusTask/flux-kontext?taskId=task_12345678" \
-H "Authorization: Bearer YOUR_API_KEY"
Response (Success):
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678",
"state": "success",
"resultJson": "{\"resultUrls\":[\"https://example.com/image.jpg\"]}"
}
}
3. Image-to-Image Editing
curl -X POST https://api.apixo.ai/api/v1/generateTask/flux-kontext \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_type": "async",
"input": {
"mode": "pro",
"prompt": "Transform into a watercolor painting style",
"image_url": "https://example.com/input.jpg",
"aspect_ratio": "16:9"
}
}'
Best Practices
Request Mode Selection
| Mode | Use When |
|---|---|
| Callback | Production environments with public server endpoints |
| Async | Client-side apps or when webhook setup is not feasible |
Performance Tips
- Async Mode: Wait 8-10 seconds before first poll, then poll every 2-3 seconds
- Timeout: Set maximum wait time to 2 minutes
- Rate Limiting: Avoid excessive concurrent requests
- Error Handling: Always check
statefield and handle failures gracefully
Resource Management
- Image URLs may be temporary - download and store important results
- Clean up failed tasks appropriately
- Log
taskIdfor debugging and support