FLUX API
Model Introduction
Exchange Token provides FLUX image generation through these API paths:
POST /v1/flux-2-proPOST /v1/flux-2-maxPOST /v1/flux-3-image
Submit a generation request first, then poll the returned polling_url or GET /v1/get_result?id=....
Calling Method
API Endpoint
https://api.exchangetoken.aiAuthentication
FLUX endpoints use the following authentication header:
x-key: YOUR_API_KEYYou can also use Authorization: Bearer YOUR_API_KEY. Use the same API key to create the task and query its result.
Content Type
Content-Type: application/jsonTask Submission
FLUX 2 pro/max Request
Use POST /v1/flux-2-pro or POST /v1/flux-2-max.
Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Text prompt for image generation or editing |
input_image | string | No | First reference image as an accessible image URL or Base64; omit for text-to-image generation |
input_image_2 to input_image_8 | string | No | Reference images 2–8; one image per field |
seed | integer | No | Random seed for reproducibility, such as 42 |
width | integer | No | Output width in pixels; must be at least 64 when specified |
height | integer | No | Output height in pixels; must be at least 64 when specified |
safety_tolerance | integer | No | The current API accepts 0–5, with 0 the strictest |
output_format | string | No | Output image format; use jpeg or png |
FLUX 3 Image Request
Use POST /v1/flux-3-image.
Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Text prompt for image generation or editing; must not be empty or contain only whitespace |
images | string or string[] | No | 1–10 reference images as HTTP(S) URLs or Base64; omit this field when there are no references, rather than sending null or an empty array |
resolution | string | No | Resolution tier: 768sq, 1k, 1.5k, 2k, or 4k; defaults to 1k |
aspect_ratio | string | No | Output aspect ratio; defaults to auto. See the values below |
grounding | boolean | No | Whether to enable web and image search; false disables both |
safety_tolerance | integer | No | The current API accepts 0–4, with 0 the strictest |
Supported aspect_ratio values: 21:9, 2:1, 16:9, 3:2, 7:5, 4:3, 5:4, 1:1, 4:5, 3:4, 5:7, 2:3, 9:16, 1:2, 9:21, and auto.
Response
| Field | Type | Description |
|---|---|---|
id | string | Gateway task ID for subsequent queries |
polling_url | string | Full result URL; send a GET request with the same API key |
Query Task Result
Request Fields
GET /v1/get_result?id=TASK_ID| Field | Location | Type | Required | Description |
|---|---|---|---|---|
id | Query | string | Yes | Task ID from the submit response |
Response Fields
| Field | Type | Description |
|---|---|---|
id | string | Gateway task ID |
status | string | Currently Pending, Ready, or Error |
result | object or null | Contains sample on success; null while pending or on failure |
result.sample | string | Complete generated image URL |
progress | number | Optional progress value; omitted when unavailable |
details | object[] | Optional failure details; each entry contains only msg |
details[].msg | string | Failure reason |
Platform Error Responses
When a request fails validation by the Exchange Token platform or Exchange Token cannot complete request processing, the response uses an HTTP 4xx or 5xx status code with the following structure:
| Field | Type | Description |
|---|---|---|
error | object | Platform error information |
error.type | string | Error type, such as invalid_request or rate_limited |
error.message | string | Detailed description of the error |
Common HTTP status codes:
| Status Code | Description |
|---|---|
400 | Invalid parameters or missing required parameters |
401 | Missing or invalid API key |
402 | Insufficient available quota |
403 | Access denied, for example because the API key is disabled, expired, or the client IP is not allowed |
404 | The task does not exist or does not belong to the current API key |
429 | Request rate or concurrency limit exceeded |
500 | Internal platform processing failure |
502 | Upstream communication failure or an invalid upstream response |
503 | Service temporarily unavailable, for example because no channel is available |
Examples
Submit a Generation Task
FLUX 2 pro Text-to-Image
curl -X POST "https://api.exchangetoken.ai/v1/flux-2-pro" \
-H "x-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A cinematic portrait of a silver robot walking in neon rain",
"width": 1024,
"height": 1024,
"seed": 42,
"safety_tolerance": 2,
"output_format": "png"
}'FLUX 2 max with Reference Images
Replace the example URLs with accessible image URLs.
curl -X POST "https://api.exchangetoken.ai/v1/flux-2-max" \
-H "x-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Keep the teapot shape from the first image, apply the colors from the second image, and place it on a wooden table",
"input_image": "https://example.com/teapot.png",
"input_image_2": "https://example.com/color-reference.png",
"width": 1024,
"height": 1024,
"output_format": "png"
}'FLUX 3 Image Text-to-Image
curl -X POST "https://api.exchangetoken.ai/v1/flux-3-image" \
-H "x-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A cinematic portrait of a silver robot walking in neon rain",
"resolution": "2k",
"aspect_ratio": "1:1",
"grounding": false,
"safety_tolerance": 2
}'FLUX 3 Image with Reference Images
Replace the example URLs with accessible image URLs.
curl -X POST "https://api.exchangetoken.ai/v1/flux-3-image" \
-H "x-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Keep the teapot shape from the first image, apply the colors from the second image, and place it on a wooden table",
"images": [
"https://example.com/teapot.png",
"https://example.com/color-reference.png"
],
"resolution": "1k",
"aspect_ratio": "4:3"
}'Response
{
"id": "sg_img_123456",
"polling_url": "https://api.exchangetoken.ai/v1/get_result?id=sg_img_123456"
}Query Task Result
Replace id with the task ID from the submit response.
curl "https://api.exchangetoken.ai/v1/get_result?id=sg_img_123456" \
-H "x-key: YOUR_API_KEY"Poll the same task ID until status changes to Ready or Error.
Pending Response Example
{
"id": "sg_img_123456",
"status": "Pending",
"result": null,
"progress": 0.45
}Ready Response Example
{
"id": "sg_img_123456",
"status": "Ready",
"result": {
"sample": "https://cdn.example.com/generated-image.png?signature=example"
}
}Read result.sample to retrieve the image. Preserve the complete URL, including its query parameters, when downloading it.
Error Responses
Platform Parameter Error
A FLUX 3 request with an unsupported resolution returns HTTP 400:
{
"error": {
"type": "invalid_request",
"message": "FLUX 3 resolution must be one of 768sq, 1k, 1.5k, 2k, 4k"
}
}Upstream Task Error
Querying a failed task returns HTTP 200, with the upstream error message in details[0].msg:
{
"id": "sg_img_123456",
"status": "Error",
"result": null,
"details": [
{
"msg": "image generation failed"
}
]
}