Chuyển đến nội dung chính
POST

Tổng quan

POST /flux/v1/\{model\} tạo một hình ảnh bằng yêu cầu định dạng BFL gốc. Theo mặc định, các yêu cầu là bất đồng bộ. Lưu id trong phản hồi cấp cao nhất, sau đó thăm dò GET /flux/v1/get_result bằng ID tác vụ đó. Để chờ hình ảnh trong cùng yêu cầu, hãy gửi "async": false trong phần thân JSON. Phản hồi đồng bộ thành công chứa status: "Ready" và URL hình ảnh trong result.sample. API playground bao gồm các ví dụ yêu cầu chuyển văn bản thành hình ảnh cho FLUX.2 Pro, Flex và Max. Xem trang Models hoặc /v1/models để biết ID mô hình và khả năng sử dụng của tài khoản.

Các trường yêu cầu

Bắt đầu với prompt, width, height và output_format. Bạn cũng có thể gửi seed; kết quả hoàn tất có thể báo cáo seed đã dùng, nhưng riêng trường đó không đảm bảo đầu ra có thể lặp lại. Trường async tùy chọn kiểm soát cách yêu cầu trả về. Dùng giá trị boolean JSON false để tạo đồng bộ. Dùng true hoặc bỏ qua trường này để tạo bất đồng bộ. Không gửi chuỗi như "false". Để chỉnh sửa hình ảnh tham chiếu, hãy gửi URL hình ảnh HTTPS công khai trong input_image. Trường này được hỗ trợ cho ba mô hình FLUX.2 ở trên. FLUX.2 Pro cũng chấp nhận URL HTTPS công khai thứ hai trong input_image_2; hãy bao gồm input_image bất cứ khi nào bạn gửi input_image_2.

Tạo đồng bộ

Chọn Chuyển văn bản thành hình ảnh đồng bộ (FLUX.2 Pro) trong các ví dụ yêu cầu để gửi "async": false. Giữ kết nối mở trong khi hình ảnh được tạo. Ví dụ sử dụng thời gian chờ phía máy khách 300 giây; đây là cài đặt máy khách, không phải thời hạn hoàn tất. Khi phản hồi có status: "Ready", hãy đọc trực tiếp result.sample. Không cần thăm dò kết quả. Nếu yêu cầu thất bại, hãy xử lý lỗi HTTP trước khi đọc kết quả. Không kết hợp async: false với webhook_url hoặc webhook_secret. Các yêu cầu đồng bộ trả về kết quả trực tiếp và từ chối các trường webhook này.

Gửi bất đồng bộ và thăm dò

Khi async là true hoặc bị bỏ qua, phản hồi tạo sẽ trả về ID tác vụ trong khi quá trình tạo tiếp tục. Dùng id cấp cao nhất của nó với endpoint kết quả CometAPI; máy khách không nên phụ thuộc vào polling_url được cung cấp trong phản hồi. Thăm dò cho đến khi endpoint kết quả trả về status: "Ready". Coi Error, Failed, Failure, Task not found, Request Moderated và Content Moderated là lỗi. Với các trạng thái khác, tiếp tục thăm dò trong giới hạn thử lại và thời gian chờ của ứng dụng.
Khi một tác vụ sẵn sàng, result.sample là URL hình ảnh tạm thời. Hãy tải xuống hoặc chuyển nó ngay; không dựa vào thời hạn cố định.

Ủy quyền

Authorization
string
header
bắt buộc

Bearer token authentication. Use your CometAPI key.

Tham số đường dẫn

model
string
bắt buộc

FLUX.2 model ID in the URL path. Check /v1/models or the Models page for account availability.

Nội dung

application/json
prompt
string
bắt buộc

Text prompt describing the image or reference-image edit.

Ví dụ:

"A clean editorial photograph of a red ceramic teapot on a pale blue table, soft window light, no text."

async
boolean
mặc định:true

Controls whether generation returns asynchronously. Set false to wait for the finished image and read result.sample from the successful response. Set true or omit this field to receive a task ID for polling. Use a JSON boolean, not a string. Do not combine false with webhook_url or webhook_secret.

input_image
string
bắt buộc if input_image_2 is set

Public HTTPS URL of the first reference image. Replace the example URL with a publicly accessible image. This editing field is available for the FLUX.2 models covered by this reference.

Ví dụ:

"https://your-image-host/reference-one.jpg"

input_image_2
string

Public HTTPS URL of a second reference image for flux-2-pro. Replace the example URL and also send input_image.

Ví dụ:

"https://your-image-host/reference-two.jpg"

seed
integer

Optional seed value. A completed result can report the used seed; that field alone does not establish repeatable output.

width
integer

Requested output width in pixels. Use a dimension supported by the selected model.

Ví dụ:

1280

height
integer

Requested output height in pixels. Use a dimension supported by the selected model.

Ví dụ:

768

output_format
string

Requested output image format supported by the selected model. The examples use png.

Ví dụ:

"png"

Phản hồi

200 - application/json

With async: false, successful generation returns status: "Ready" and the image URL in result.sample. With async: true or no async field, save the top-level id and poll the CometAPI result endpoint.

id
string
bắt buộc

Task ID to pass to GET /flux/v1/get_result?id=....

status
string
bắt buộc

Task state. A successful synchronous response returns Ready. An asynchronous submission can return Pending while generation continues.

result
object | null

Generation result. A successful synchronous response contains the finished image. An asynchronous submission can return an empty or null result.

polling_url
string | null

Response-supplied convenience URL when returned. Clients should poll the documented CometAPI result route by the top-level id.

cost
number | null

Numeric billing coefficient when returned. This field is not documented as a currency or credit amount.

input_mp
number | null

Input image megapixels when returned.

output_mp
number | null

Output image megapixels when returned.

progress
number | null

Task progress when returned.

details
any

Additional task details when returned.

preview
any

Task preview data when returned.

Lần sửa đổi cuối 21 tháng 9, 2026