Skip to content

Flux-2 文生图 ​

本页由 ModelFold 文档站根据上游官方 OpenAPI 文档同步生成。接口路径、参数、示例与官方保持一致;品牌与 API 域名已替换为 ModelFold。

接口 ​

POST /jobs/createTask

完整 URL: https://ai.modelfold.online/v1/jobs/createTask

鉴权:所有请求都需要 Authorization: Bearer <API_KEY> 请求头。

基于 Flux-2 先进 AI 模型的高质量写实风格图像生成

输出格式不固定,结果可能是 PNG 或 JPEG。

查询任务状态 ​

提交任务后,可通过统一的查询端点查看任务进度并获取生成结果:

TIP

生产环境中,建议使用 callBackUrl 参数接收生成完成的自动通知,而非轮询状态端点。

相关资源 ​

请求参数 ​

请求体 (application/json) ​

参数类型必填说明
modelstring是用于生成的模型名称。必填字段。
- 此端点必须使用 flux-2/flex-text-to-image 默认值:"flux-2/flex-text-to-image"。 可选值:flux-2/flex-text-to-image。 示例:flux-2/flex-text-to-image。
callBackUrlstring否接收生成任务完成更新的 URL。可选但建议在生产环境中使用。
- 当生成完成时,系统将向此 URL POST 任务状态和结果
- 回调包含生成的内容 URL 和任务信息
- 您的回调端点应接受包含结果的 JSON 负载的 POST 请求
- 或者,使用获取任务详情端点轮询任务状态
- 为确保回调安全性,请参阅 Webhook 校验指南 了解签名验证实现方法 示例:https://your-domain.com/api/callback。
inputobject否生成任务的输入参数
  input.promptstring是长度必须在 3-5000 字符之间。(最大长度:5000 字符) 示例:A humanoid figure with a vintage television set for a head, featuring a green-tinted screen displaying a Hello FLUX.2 writing in ASCII font. The figure is wearing a yellow raincoat, and there are various wires and components attached to the television. The background is cloudy and indistinct, suggesting an outdoor setting。
  input.aspect_ratiostring是必填。生成图像的宽高比。 可选值:1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3。 示例:1:1。
  input.resolutionstring是必填。输出图像分辨率。 可选值:1K / 2K。 示例:1K。
  input.nsfw_checkerboolean否默认 false。为 false 时不额外进行内容过滤,结果由模型直接返回。

请求示例 ​

bash
curl -X POST "https://ai.modelfold.online/v1/jobs/createTask" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "flux-2/flex-text-to-image",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "A humanoid figure with a vintage television set for a head, featuring a green-tinted screen displaying a `Hello FLUX.2` writing in ASCII font. The figure is wearing a yellow raincoat, and there are various wires and components attached to the television. The background is cloudy and indistinct, suggesting an outdoor setting",
    "aspect_ratio": "1:1",
    "resolution": "1K",
    "nsfw_checker": false
  }
}'
json
{
  "model": "flux-2/flex-text-to-image",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "A humanoid figure with a vintage television set for a head, featuring a green-tinted screen displaying a `Hello FLUX.2` writing in ASCII font. The figure is wearing a yellow raincoat, and there are various wires and components attached to the television. The background is cloudy and indistinct, suggesting an outdoor setting",
    "aspect_ratio": "1:1",
    "resolution": "1K",
    "nsfw_checker": false
  }
}

响应 ​

200 — 请求成功 ​

参数类型必填说明
codeinteger是请求状态码。请求失败时 HTTP 状态仍为 200,请始终以本字段判断:200 表示成功,其他值均表示失败,原因见 msg。常见值:401 API key 无效或缺失;402 积分不足;429 超出频率限制;422 或 500 请求未能处理(请先查看 msg、检查参数,再决定是否重试)。 可选值:200 / 401 / 402 / 404 / 422 / 429 / 433 / 455 / 500 / 501 / 505。 示例:200。
msgstring是响应消息,失败时的错误描述
dataobject是—
  data.taskIdstring是可以使用任务 ID 与“获取任务详细信息”端点一起查询任务状态。
json
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_flux-2_1765175490366"
  }
}

回调 ​

onImageGenerated ​

回调地址:{$request.body#/callBackUrl}(即请求体里的 callBackUrl)。

任务成功或失败时发送回调。

回调体参数

参数类型必填说明
codeinteger否200:成功;501:失败,原因见 data.failCode 与 data.failMsg。 可选值:200 / 501。 示例:200。
msgstring否状态消息 示例:Playground task completed successfully.。
dataobject否—
  data.completeTimeinteger否任务完成时间,Unix 毫秒时间戳 示例:1786430877000。
  data.costTimeinteger否处理耗时(秒),成功和失败回调都会返回。 示例:38。
  data.createTimeinteger否任务创建时间,Unix 毫秒时间戳 示例:1786430837000。
  data.creditsConsumednumber否本任务消耗的积分;失败任务为 0。 示例:14。
  data.modelstring否图片生成使用的模型 示例:flux-2/flex-text-to-image。
  data.paramstring否创建任务时提交的参数,JSON 字符串格式 示例:{"input":"{\"aspect_ratio\":\"1:1\",\"prompt\":\"一个手持复古电视机的人形机器人,电视屏幕上显示着绿色调的ASCII字体“Hello FLUX.2”。该人形身穿黄色雨衣,电视上连接着各种电线和部件。背景为阴云密布、模糊不清,暗示其处于户外环境。\",\"resolution\":\"1K\",\"nsfw_checker\":false}","callBackUrl":"https://your-domain.com/api/callback","model":"flux-2/flex-text-to-image"}。
  data.resultJsonstring否图片生成结果,JSON 字符串格式。resultUrls 为生成图片的 URL 列表。仅在 state 为 success 时出现。 示例:{"resultUrls":["https://tempfile.aiquickdraw.com/h/97d494e87bb500bbfd9ae018b9df5e50_1786430874.png"]}。
  data.statestring否任务状态 可选值:success / fail。 示例:success。
  data.taskIdstring否任务 ID 示例:97d494e87bb500bbfd9ae018b9df5e50。
  data.updateTimeinteger否完成时间请以 completeTime 为准;updateTime 可能与 createTime 相同。 示例:1786430877000。
  data.failCodestring否失败码,数字字符串,如 "400"、"500"。仅在 state 为 fail 时出现。 示例:500。
  data.failMsgstring否失败原因,仅在 state 为 fail 时出现。 示例:&lt;error detail&gt;。

成功

json
{
  "code": 200,
  "msg": "Playground task completed successfully.",
  "data": {
    "taskId": "97d494e87bb500bbfd9ae018b9df5e50",
    "model": "flux-2/flex-text-to-image",
    "state": "success",
    "param": "{\"input\":\"{\\\"aspect_ratio\\\":\\\"1:1\\\",\\\"prompt\\\":\\\"一个手持复古电视机的人形机器人,电视屏幕上显示着绿色调的ASCII字体“Hello FLUX.2”。该人形身穿黄色雨衣,电视上连接着各种电线和部件。背景为阴云密布、模糊不清,暗示其处于户外环境。\\\",\\\"resolution\\\":\\\"1K\\\",\\\"nsfw_checker\\\":false}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"flux-2/flex-text-to-image\"}",
    "resultJson": "{\"resultUrls\":[\"https://tempfile.aiquickdraw.com/h/97d494e87bb500bbfd9ae018b9df5e50_1786430874.png\"]}",
    "completeTime": 1786430877000,
    "createTime": 1786430837000,
    "costTime": 38,
    "creditsConsumed": 14,
    "updateTime": 1786430877000
  }
}

失败

json
{
  "code": 501,
  "msg": "Playground task failed.",
  "data": {
    "taskId": "97d494e87bb500bbfd9ae018b9df5e50",
    "model": "flux-2/flex-text-to-image",
    "state": "fail",
    "param": "{\"input\":\"{\\\"aspect_ratio\\\":\\\"1:1\\\",\\\"prompt\\\":\\\"一个手持复古电视机的人形机器人,电视屏幕上显示着绿色调的ASCII字体“Hello FLUX.2”。该人形身穿黄色雨衣,电视上连接着各种电线和部件。背景为阴云密布、模糊不清,暗示其处于户外环境。\\\",\\\"resolution\\\":\\\"1K\\\",\\\"nsfw_checker\\\":false}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"flux-2/flex-text-to-image\"}",
    "failCode": "500",
    "failMsg": "<error detail>",
    "completeTime": 1786430877000,
    "createTime": 1786430837000,
    "costTime": 38,
    "creditsConsumed": 0,
    "updateTime": 1786430877000
  }
}

ModelFold — 一个 API,接入所有主流 AI 模型。