Flux-2 API Reference
Overview
| Property | Value |
|---|---|
| Model ID | flux-2 |
| Type | Text-to-Image, Image-to-Image |
| Pricing | $0.05-0.13/image |
| Average Time | 20-30 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-2
2. Query Task Status
GET https://api.apixo.ai/api/v1/statusTask/flux-2?taskId={taskId}
Request Parameters
Request Body Structure
{
"request_type": "callback",
"callback_url": "https://your-server.com/callback",
"input": {
"mode": "pro-text-to-image",
"prompt": "Your image description",
"aspect_ratio": "1:1",
...
}
}
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 | pro-text-to-image | Generation mode: pro-text-to-image or pro-image-to-image or flex-text-to-image or flex-image-to-image |
prompt | string | Yes | - | Image description (Must be between 3 and 5,000 characters) |
image_urls | string[] | No | - | Up to 8 reference image URLs for image-to-image editing |
aspect_ratio | string | Yes | 1:1 | Output ratio: 1:1, 9:16, 16:9, 4:3, 3:4, 3:2, 2:3, auto |
resolution | string | Yes | 1K | Output image resolution: 1K or 2K |
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": 1698765412000,
"createTime": 1698765400000,
"costTime": 12000
}
}
Failure Callback
{
"code": 400,
"message": "failed",
"data": {
"taskId": "task_12345678",
"state": "failed",
"failCode": "CONTENT_VIOLATION",
"failMsg": "Content does not meet safety guidelines",
"completeTime": 1698765412000,
"createTime": 1698765400000,
"costTime": 12000
}
}
Quick Start
1. Text-to-Image Generation
curl -X POST https://api.apixo.ai/api/v1/generateTask/flux-2 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_type": "async",
"input": {
"mode": "pro-text-to-image",
"prompt": "A beautiful sunset over the mountains",
"aspect_ratio": "1:1",
"resolution": "1K"
}
}'
Response:
{
"code": 200,
"message": "success",
"data": {
"taskId": "task_12345678"
}
}
2. Check Task Status
curl -X GET "https://api.apixo.ai/api/v1/statusTask/flux-2?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-2 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_type": "async",
"input": {
"mode": "pro-image-to-image",
"prompt": "Transform into a watercolor painting style",
"image_urls": ["https://example.com/input.jpg"],
"aspect_ratio": "16:9",
"resolution": "1K"
}
}'
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 15 seconds before first poll, then poll every 5 seconds
- Timeout: Set maximum wait time to 3 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