curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-pro",
"prompt": "A blue cat sitting on the grass",
"resolution": "2MP",
"size": "16:9",
"output_format": "jpeg"
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "A blue cat sitting on the grass",
"resolution": "2MP",
"size": "16:9",
"output_format": "jpeg"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "flux-2-pro",
prompt: "A blue cat sitting on the grass",
resolution: "2MP",
size: "16:9",
output_format: "jpeg"
};
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(await response.json());
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "Insufficient balance, please top up",
"type": "payment_required"
}
}
Flux 2.0
FLUX.2 Image Generation
Submit asynchronous FLUX.2 text-to-image or reference-image generation tasks. The API returns a task ID; poll the task endpoint for the generated image.
POST
/
v1
/
images
/
generations
curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-pro",
"prompt": "A blue cat sitting on the grass",
"resolution": "2MP",
"size": "16:9",
"output_format": "jpeg"
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "A blue cat sitting on the grass",
"resolution": "2MP",
"size": "16:9",
"output_format": "jpeg"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "flux-2-pro",
prompt: "A blue cat sitting on the grass",
resolution: "2MP",
size: "16:9",
output_format: "jpeg"
};
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(await response.json());
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "Insufficient balance, please top up",
"type": "payment_required"
}
}
curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-2-pro",
"prompt": "A blue cat sitting on the grass",
"resolution": "2MP",
"size": "16:9",
"output_format": "jpeg"
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "flux-2-pro",
"prompt": "A blue cat sitting on the grass",
"resolution": "2MP",
"size": "16:9",
"output_format": "jpeg"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "flux-2-pro",
prompt: "A blue cat sitting on the grass",
resolution: "2MP",
size: "16:9",
output_format: "jpeg"
};
const response = await fetch(url, {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(await response.json());
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "Insufficient balance, please top up",
"type": "payment_required"
}
}
Supported Models
| Model | Description |
|---|---|
flux-2-flex | Fine-grained generation with adjustable sampling steps and guidance. |
flux-2-pro | Balanced quality and speed for general-purpose production workflows. |
flux-2-max | Highest-quality FLUX.2 model for maximum detail. |
Authorizations
string
required
All endpoints require Bearer Token authentication.Get an API key from API Key Management, then add it to the request header:
Authorization: Bearer YOUR_API_KEY
Body
string
required
Model name:
flux-2-flexflux-2-proflux-2-max
boolean
default:"false"
Whether to run content moderation before submitting the image task.
true: useomni-moderation-latestto review prompts and input imagesfalseor omitted: do not send a moderation request, adding no moderation cost or latency (default)
string
required
Text description of the image to generate or the edit to apply to the reference images.
string
default:"2MP"
Output resolution preset. Supported values:
1MP2MP(default)3MP4MP
1MP equals 1,048,576 pixels.Legacy aliases remain accepted: 512 / 512P / 1M map to 1MP, 1K / 1024 map to 2MP, 2K / 2048 map to 3MP, and 4K maps to 4MP. Any other value causes the task to fail.The preset determines the output dimensions when size is an aspect ratio.string
default:"1:1"
Output aspect ratio or pixel dimensions.
size also supports auto: when image_urls is provided, the output follows the reference image aspect ratio while keeping the current resolution tier; without a reference image, it uses the default 1:1.Supported size options:1:1(default)4:33:416:99:163:22:321:99:21auto- Follow the reference image aspect ratio
1024x1536. Exact pixel dimensions are subject to the same pixel limits as width and height and take priority over resolution and an aspect ratio.integer
Exact output width in pixels. It must be provided together with
height, and each dimension must be at least 64 pixels. Supplying only one dimension causes the task to fail.A complete width and height pair has the highest priority and overrides resolution and size.integer
Exact output height in pixels. It must be provided together with
width, and each dimension must be at least 64 pixels. Supplying only one dimension causes the task to fail.The output must not exceed 4 MP (width × height ≤ 4,194,304), and the output plus all reference images must not exceed 9 MP in total.array
Reference images for image-to-image generation. Publicly accessible image URLs and Base64 input are supported.
- Maximum: 8 images
- The output plus all reference images must not exceed 9 MP in total
string
default:"jpeg"
Output image encoding. Supported values:
jpeg, png, and webp.integer
default:"1"
Number of images generated per task. The only supported value is
1; submit multiple tasks concurrently if you need multiple images.integer
Random seed. Reuse the same seed and parameters for reproducible output; omit it to use a random seed.
boolean
default:"false"
Whether to enhance and rewrite the prompt before generation. The default is
false. Pass false explicitly to disable prompt rewriting.integer
default:"2"
Safety tolerance from
0 to 5. Higher values are more permissive.integer
default:"50"
Sampling steps from
1 to 50. Higher values can improve detail but take longer.This parameter is supported only by flux-2-flex. Do not send it with flux-2-pro or flux-2-max.number
default:"5.0"
Prompt guidance from
1.5 to 10. Higher values follow the prompt more closely.This parameter is supported only by flux-2-flex. Do not send it with flux-2-pro or flux-2-max.Resolution Reference Table
| Aspect ratio | 1MP | 2MP (default) | 3MP | 4MP |
|---|---|---|---|---|
1:1 | 1024×1024 | 1440×1440 | 1536×1536 | 2048×2048 |
4:3 | 1152×864 | 1664×1248 | 1824×1360 | 2336×1760 |
3:4 | 864×1152 | 1248×1664 | 1360×1824 | 1760×2336 |
16:9 | 1344×752 | 1920×1072 | 2048×1152 | 2720×1536 |
9:16 | 752×1344 | 1072×1920 | 1152×2048 | 1536×2720 |
3:2 | 1248×832 | 1728×1152 | 1872×1248 | 2496×1664 |
2:3 | 832×1248 | 1152×1728 | 1248×1872 | 1664×2496 |
21:9 | 1504×640 | 2176×928 | 2304×992 | 3072×1312 |
9:21 | 640×1504 | 928×2176 | 992×2304 | 1312×3072 |
width + height → a pixel-string size → resolution + aspect-ratio size → the default 2MP + 1:1.
Usage Examples
Text-to-image
{
"model": "flux-2-pro",
"prompt": "A cinematic city at night with neon reflections on wet streets",
"resolution": "1MP",
"size": "16:9"
}
Reference-image generation
{
"model": "flux-2-pro",
"prompt": "Place the person from the first image in the scene from the second image and match the lighting",
"image_urls": [
"https://example.com/person.jpg",
"https://example.com/scene.jpg"
],
"resolution": "2MP",
"output_format": "webp"
}
Exact output dimensions
{
"model": "flux-2-max",
"prompt": "A highly detailed botanical illustration",
"width": 1024,
"height": 1536
}
FLUX.2 Flex controls
{
"model": "flux-2-flex",
"prompt": "A minimalist poster with the headline SUMMER SALE and the subheading 50% OFF",
"resolution": "3MP",
"size": "3:4",
"steps": 50,
"guidance": 6.5
}
Response
integer
Response status code.
array
Retrieve the Result
PollGET /v1/tasks/{task_id} until the task reaches completed or failed. See the Task Status API for the complete response schema.
Task statuses:
| Status | Meaning |
|---|---|
submitted / pending | Accepted or queued; continue polling. |
processing | Image generation is in progress; continue polling. |
completed | Generation succeeded; the image is available in result.images. |
failed | Generation failed; read data.error.message. The task is fully refunded. |
{
"code": 200,
"data": {
"id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2",
"status": "completed",
"progress": 100,
"result": {
"images": [
{
"url": ["https://upload.apimart.ai/f/image/xxxxxxxx-flux-2.jpeg"],
"expires_at": 1785220083
}
]
}
}
}
data.result.images[0].url[0]. Its expiration is defined by the Unix timestamp in data.result.images[0].expires_at; download the image before that time.
Invalid parameters and failed tasks
Invalid model parameters do not produce a synchronous 4xx response. The submission still returns HTTP 200 with atask_id; keep polling until the task becomes failed, then read the specific reason from data.error.message. Failed tasks are fully refunded.
{
"code": 200,
"data": {
"status": "failed",
"error": {
"type": "task_failed",
"code": "task_failed",
"message": "`steps` must be between 1 and 50 (got 0)"
}
}
}
error.code is always task_failed; the specific reason is in error.message.
Notes
- Tasks are processed asynchronously. The submission response returns a
task_idfor polling. ndefaults to1, which is the only supported value.- Reference images may use publicly accessible image URLs or Base64 input.
- Up to 8 reference images are supported, subject to the 9 MP combined input-and-output limit.
- Exact output dimensions can be set with a pixel-string
size, or with pairedwidthandheight. When used, both dimensions must be at least 64 pixels; output is limited to 4 MP. - Result URL expiration is determined by the
expires_atvalue returned in the task response. - Invalid model parameters are returned asynchronously: poll until
failedand readdata.error.message.