Skip to content

FLUX API ​

Model Introduction ​

Exchange Token provides FLUX image generation through these API paths:

  • POST /v1/flux-2-pro
  • POST /v1/flux-2-max
  • POST /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 ​

text
https://api.exchangetoken.ai

Authentication ​

FLUX endpoints use the following authentication header:

text
x-key: YOUR_API_KEY

You can also use Authorization: Bearer YOUR_API_KEY. Use the same API key to create the task and query its result.

Content Type ​

text
Content-Type: application/json

Task Submission ​

FLUX 2 pro/max Request ​

Use POST /v1/flux-2-pro or POST /v1/flux-2-max.

Request Fields ​
FieldTypeRequiredDescription
promptstringYesText prompt for image generation or editing
input_imagestringNoFirst reference image as an accessible image URL or Base64; omit for text-to-image generation
input_image_2 to input_image_8stringNoReference images 2–8; one image per field
seedintegerNoRandom seed for reproducibility, such as 42
widthintegerNoOutput width in pixels; must be at least 64 when specified
heightintegerNoOutput height in pixels; must be at least 64 when specified
safety_toleranceintegerNoThe current API accepts 0–5, with 0 the strictest
output_formatstringNoOutput image format; use jpeg or png

FLUX 3 Image Request ​

Use POST /v1/flux-3-image.

Request Fields ​
FieldTypeRequiredDescription
promptstringYesText prompt for image generation or editing; must not be empty or contain only whitespace
imagesstring or string[]No1–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
resolutionstringNoResolution tier: 768sq, 1k, 1.5k, 2k, or 4k; defaults to 1k
aspect_ratiostringNoOutput aspect ratio; defaults to auto. See the values below
groundingbooleanNoWhether to enable web and image search; false disables both
safety_toleranceintegerNoThe 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 ​

FieldTypeDescription
idstringGateway task ID for subsequent queries
polling_urlstringFull result URL; send a GET request with the same API key

Query Task Result ​

Request Fields ​

text
GET /v1/get_result?id=TASK_ID
FieldLocationTypeRequiredDescription
idQuerystringYesTask ID from the submit response

Response Fields ​

FieldTypeDescription
idstringGateway task ID
statusstringCurrently Pending, Ready, or Error
resultobject or nullContains sample on success; null while pending or on failure
result.samplestringComplete generated image URL
progressnumberOptional progress value; omitted when unavailable
detailsobject[]Optional failure details; each entry contains only msg
details[].msgstringFailure 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:

FieldTypeDescription
errorobjectPlatform error information
error.typestringError type, such as invalid_request or rate_limited
error.messagestringDetailed description of the error

Common HTTP status codes:

Status CodeDescription
400Invalid parameters or missing required parameters
401Missing or invalid API key
402Insufficient available quota
403Access denied, for example because the API key is disabled, expired, or the client IP is not allowed
404The task does not exist or does not belong to the current API key
429Request rate or concurrency limit exceeded
500Internal platform processing failure
502Upstream communication failure or an invalid upstream response
503Service temporarily unavailable, for example because no channel is available

Examples ​

Submit a Generation Task ​

FLUX 2 pro Text-to-Image ​

bash
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.

bash
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 ​

bash
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.

bash
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 ​

json
{
  "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.

bash
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 ​

json
{
  "id": "sg_img_123456",
  "status": "Pending",
  "result": null,
  "progress": 0.45
}

Ready Response Example ​

json
{
  "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:

json
{
  "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:

json
{
  "id": "sg_img_123456",
  "status": "Error",
  "result": null,
  "details": [
    {
      "msg": "image generation failed"
    }
  ]
}