الانتقال إلى المحتوى الرئيسي
POST

نظرة عامة

POST /flux/v1/\{model\} يُنشئ صورةً باستخدام طلب أصلي بتنسيق BFL. تكون الطلبات غير متزامنة افتراضيًا. خزّن id من الاستجابة ذات المستوى الأعلى، ثم استعلم بشكل دوري عن GET /flux/v1/get_result باستخدام معرّف المهمة هذا. للانتظار حتى اكتمال الصورة ضمن الطلب نفسه، أرسل "async": false في جسم JSON. تحتوي الاستجابة المتزامنة الناجحة على status: "Ready" ورابط الصورة في result.sample. تتضمن ساحة اختبار API أمثلة لطلبات تحويل النص إلى صورة لـ FLUX.2 Pro وFlex وMax. راجع صفحة النماذج أو /v1/models للحصول على معرّفات النماذج ومدى توفر الحساب.

حقول الطلب

ابدأ باستخدام prompt وwidth وheight وoutput_format. يمكنك أيضًا إرسال seed؛ ويمكن للنتيجة المكتملة الإبلاغ عن البذرة المستخدمة، لكن هذا الحقل وحده لا يضمن مخرجات قابلة للتكرار. يتحكم الحقل الاختياري async في كيفية إرجاع الطلب. استخدم القيمة المنطقية في JSON false للإنشاء المتزامن. استخدم true أو احذف الحقل للإنشاء غير المتزامن. لا ترسل سلسلة نصية مثل "false". لتحرير الصور المرجعية، أرسل رابط صورة HTTPS عامًا في input_image. هذا الحقل مدعوم للنماذج الثلاثة FLUX.2 المذكورة أعلاه. يقبل FLUX.2 Pro أيضًا رابط HTTPS عامًا ثانيًا في input_image_2؛ أدرج input_image كلما أرسلت input_image_2.

الإنشاء المتزامن

حدّد تحويل النص إلى صورة المتزامن (FLUX.2 Pro) في أمثلة الطلبات لإرسال "async": false. أبقِ الاتصال مفتوحًا أثناء إنشاء الصورة. يستخدم المثال مهلة للعميل تبلغ 300 ثانية؛ وهذا إعداد للعميل وليس موعدًا نهائيًا للإكمال. عندما تحتوي الاستجابة على status: "Ready"، اقرأ result.sample مباشرةً. لا حاجة إلى الاستعلام الدوري عن النتيجة. إذا فشل الطلب، عالج خطأ HTTP قبل قراءة النتيجة. لا تجمع async: false مع webhook_url أو webhook_secret. تُرجع الطلبات المتزامنة النتيجة مباشرةً وترفض حقول webhook هذه.

الإرسال غير المتزامن والاستعلام الدوري

عندما يكون async مساويًا لـ true أو محذوفًا، تُرجع استجابة الإنشاء معرّف مهمة بينما يستمر الإنشاء. استخدم id ذي المستوى الأعلى مع نقطة نهاية النتائج في CometAPI؛ لا ينبغي للعملاء الاعتماد على polling_url المُقدَّم في الاستجابة. استعلم بشكل دوري حتى تُرجع نقطة نهاية النتائج status: "Ready". اعتبر Error وFailed وFailure وTask not found وRequest Moderated وContent Moderated حالات فشل. بالنسبة إلى الحالات الأخرى، واصل الاستعلام الدوري ضمن حدود إعادة المحاولة والمهلة في تطبيقك.
عندما تكون المهمة جاهزة، يكون result.sample رابط صورة مؤقتًا. نزّله أو انقله فورًا؛ ولا تعتمد على مدة صلاحية ثابتة.

التفويضات

Authorization
string
header
مطلوب

Bearer token authentication. Use your CometAPI key.

معلمات المسار

model
string
مطلوب

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

الجسم

application/json
prompt
string
مطلوب

Text prompt describing the image or reference-image edit.

مثال:

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

async
boolean
افتراضي: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
مطلوب 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.

مثال:

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

مثال:

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

مثال:

1280

height
integer

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

مثال:

768

output_format
string

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

مثال:

"png"

الاستجابة

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
مطلوب

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

status
string
مطلوب

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.

آخر تعديل في ٢١ سبتمبر ٢٠٢٦