FLUX 3 Klein Text to Image
接口
POST /jobs/createTask
完整 URL: https://modelfold.ai/v1/jobs/createTask
鉴权:所有请求都需要
Authorization: Bearer <API_KEY>请求头。
Query Task Status
After submitting the task, you can check the progress of the task and obtain the generated results through the unified query endpoint:
- Get Task Details — Learn how to check the task status and obtain the generated results
TIP
In the production environment, it is recommended to use the "callBackUrl" parameter to receive the automatic notification upon completion of the generation, rather than polling the status endpoint.
Related resources
- Market Overview — View all available models
请求参数
请求体 (application/json)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | The model name used for generation. This endpoint must use flux-3/klein-text-to-image. 默认值:"flux-3/klein-text-to-image"。 可选值:flux-3/klein-text-to-image。 示例:flux-3/klein-text-to-image。 |
callBackUrl | string | 否 | The URL to receive generation task completion updates. Optional but recommended for production use. The system POSTs the task status and results to this URL when generation completes. To ensure callback security, see Webhook Verification Guide. 示例: https://your-domain.com/api/callback。 |
input | object | 是 | Input parameters for the generation task |
input.prompt | string | 是 | A text description of the image you want to generate (Max length: 5000 characters) minLength: 1. maxLength: 5000. |
input.aspect_ratio | string | 否 | Aspect ratio of the generated image Options: 1:1; 4:3; 3:4; 3:2; 2:3; 16:9; 9:16; 21:9; 9:21 默认值: "1:1"。 可选值:1:1 / 4:3 / 3:4 / 3:2 / 2:3 / 16:9 / 9:16 / 21:9 / 9:21。 示例:1:1。 |
input.resolution | string | 否 | Resolution of the generated image Options: 1K; 2K; 4K 默认值: "1K"。 可选值:1K / 2K / 4K。 示例:1K。 |
input.width | integer | 否 | Image width. Both width and height must be passed at the same time. Aspect ratio must be between 1:2.5 and 2.5:1. Once passed, aspect_ratio and resolution are ignored. minimum: 256. maximum: 4096. |
input.height | integer | 否 | Image height. Both width and height must be passed at the same time. Aspect ratio must be between 1:2.5 and 2.5:1. Once passed, aspect_ratio and resolution are ignored. minimum: 256. maximum: 4096. |
input.output_format | string | 否 | Format of the output image Options: png; jpeg; webp 默认值: "png"。 可选值:png / jpeg / webp。 示例:png。 |
input.num_images | integer | 否 | Number of images to generate 默认值:1。 minimum: 1. maximum: 4. 示例:1。 |
input.seed | integer | 否 | Random seed minimum: 0. maximum: 2147483647. |
input.enhance_prompt | boolean | 否 | Rewrites the prompt into a fuller description before generating, which noticeably improves quality. Enabled by default (also when the parameter is omitted); pass false to turn it off. Applies to both text-to-image and image editing; in editing, the rewrite preserves the intent of the original instruction. 默认值:true。 可选值:true / false。 示例:true。 |
input.nsfw_checker | boolean | 否 | Defaults to false. When false, no additional content filtering is applied and results are returned directly by the model. |
请求示例
bash
curl -X POST "https://modelfold.ai/v1/jobs/createTask" \
-H "Authorization: Bearer $MODELFOLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "flux-3/klein-text-to-image",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field",
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png",
"num_images": 1,
"enhance_prompt": true
}
}'python
import os
import requests
resp = requests.post(
"https://modelfold.ai/v1/jobs/createTask",
headers={
"Authorization": "Bearer " + os.environ["MODELFOLD_API_KEY"],
"Content-Type": "application/json",
},
json={
"model": "flux-3/klein-text-to-image",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field",
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png",
"num_images": 1,
"enhance_prompt": True,
},
},
)
print(resp.json())javascript
const resp = await fetch("https://modelfold.ai/v1/jobs/createTask", {
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.MODELFOLD_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "flux-3/klein-text-to-image",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field",
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png",
"num_images": 1,
"enhance_prompt": true
}
}),
});
console.log(await resp.json());go
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{"model":"flux-3/klein-text-to-image","callBackUrl":"https://your-domain.com/api/callback","input":{"prompt":"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field","aspect_ratio":"16:9","resolution":"1K","output_format":"png","num_images":1,"enhance_prompt":true}}`)
req, _ := http.NewRequest("POST", "https://modelfold.ai/v1/jobs/createTask", body)
req.Header.Set("Authorization", "Bearer " + os.Getenv("MODELFOLD_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
out, _ := io.ReadAll(resp.Body)
fmt.Println(string(out))
}java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String body = "{\"model\":\"flux-3/klein-text-to-image\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"input\":{\"prompt\":\"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field\",\"aspect_ratio\":\"16:9\",\"resolution\":\"1K\",\"output_format\":\"png\",\"num_images\":1,\"enhance_prompt\":true}}";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://modelfold.ai/v1/jobs/createTask"))
.header("Authorization", "Bearer " + System.getenv("MODELFOLD_API_KEY"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
}
}php
<?php
$ch = curl_init('https://modelfold.ai/v1/jobs/createTask');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv("MODELFOLD_API_KEY"),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => '{"model":"flux-3/klein-text-to-image","callBackUrl":"https://your-domain.com/api/callback","input":{"prompt":"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field","aspect_ratio":"16:9","resolution":"1K","output_format":"png","num_images":1,"enhance_prompt":true}}',
]);
echo curl_exec($ch);
curl_close($ch);csharp
using System;
using System.Net.Http;
using System.Text;
var client = new HttpClient();
var req = new HttpRequestMessage(new HttpMethod("POST"), "https://modelfold.ai/v1/jobs/createTask");
req.Headers.TryAddWithoutValidation("Authorization", "Bearer " + Environment.GetEnvironmentVariable("MODELFOLD_API_KEY"));
req.Content = new StringContent("{\"model\":\"flux-3/klein-text-to-image\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"input\":{\"prompt\":\"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field\",\"aspect_ratio\":\"16:9\",\"resolution\":\"1K\",\"output_format\":\"png\",\"num_images\":1,\"enhance_prompt\":true}}", Encoding.UTF8, "application/json");
var resp = await client.SendAsync(req);
Console.WriteLine(await resp.Content.ReadAsStringAsync());json
{
"model": "flux-3/klein-text-to-image",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field",
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png",
"num_images": 1,
"enhance_prompt": true
}
}响应
200 — Request Successful
json
{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_flux-3_klein-text-to-image_1765175072483"
}
}回调
onImageGenerated
回调地址:{$request.body#/callBackUrl}(即请求体里的 callBackUrl)。
Sent when the task succeeds or fails.
回调体参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | integer | 否 | 200: success. 501: failure; see data.failCode and data.failMsg. 可选值:200 / 501。 示例:200。 |
msg | string | 否 | Status message 示例:Playground task completed successfully.。 |
data | object | 否 | — |
data.completeTime | integer | 否 | Task completion time, represented as a Unix timestamp in milliseconds 示例:1786430358000。 |
data.costTime | integer | 否 | Processing time in seconds. Present on both success and failure callbacks. 示例:8。 |
data.createTime | integer | 否 | Task creation time, represented as a Unix timestamp in milliseconds 示例:1786430330000。 |
data.model | string | 否 | Image generation model used for the task 示例:flux-3/klein-text-to-image。 |
data.param | string | 否 | Parameters submitted when creating the task, in JSON string format 示例:{"model": "flux-3/klein-text-to-image", "callBackUrl": "https://your-domain.com/api/callback", "input": "{\"prompt\": \"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field\", \"aspect_ratio\": \"16:9\", \"resolution\": \"1K\", \"output_format\": \"png\", \"num_images\": 1, \"enhance_prompt\": true}"}。 |
data.resultJson | string | 否 | Image generation result in JSON string format. resultUrls contains the list of generated image URLs. Present only when state is success. 示例:{"resultUrls": ["https://tempfile.aiquickdraw.com/js/p6/3f2a9c1d0b7e.png"]}。 |
data.state | string | 否 | Task status 可选值:success / fail。 示例:success。 |
data.taskId | string | 否 | Task ID 示例:e0af60383dfdb1d6bfb6bd40d9e6f891。 |
data.updateTime | integer | 否 | Use completeTime as the completion time; updateTime may equal createTime. 示例:1786430358000。 |
data.failCode | string | 否 | Failure code, a numeric string such as "400" or "500". Present only when state is fail. 示例:500。 |
data.failMsg | string | 否 | Failure reason. Present only when state is fail. 示例:<error detail>。 |
Success
json
{
"code": 200,
"msg": "Playground task completed successfully.",
"data": {
"taskId": "e0af60383dfdb1d6bfb6bd40d9e6f891",
"model": "flux-3/klein-text-to-image",
"state": "success",
"param": "{\"model\": \"flux-3/klein-text-to-image\", \"callBackUrl\": \"https://your-domain.com/api/callback\", \"input\": \"{\\\"prompt\\\": \\\"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field\\\", \\\"aspect_ratio\\\": \\\"16:9\\\", \\\"resolution\\\": \\\"1K\\\", \\\"output_format\\\": \\\"png\\\", \\\"num_images\\\": 1, \\\"enhance_prompt\\\": true}\"}",
"resultJson": "{\"resultUrls\": [\"https://tempfile.aiquickdraw.com/js/p6/3f2a9c1d0b7e.png\"]}",
"completeTime": 1786430358000,
"createTime": 1786430330000,
"costTime": 8,
"updateTime": 1786430358000
}
}Failure
json
{
"code": 501,
"msg": "Playground task failed.",
"data": {
"taskId": "e0af60383dfdb1d6bfb6bd40d9e6f891",
"model": "flux-3/klein-text-to-image",
"state": "fail",
"param": "{\"model\": \"flux-3/klein-text-to-image\", \"callBackUrl\": \"https://your-domain.com/api/callback\", \"input\": \"{\\\"prompt\\\": \\\"A corgi wearing a yellow rain hat sitting on wet stone steps after the rain, shallow depth of field\\\", \\\"aspect_ratio\\\": \\\"16:9\\\", \\\"resolution\\\": \\\"1K\\\", \\\"output_format\\\": \\\"png\\\", \\\"num_images\\\": 1, \\\"enhance_prompt\\\": true}\"}",
"failCode": "500",
"failMsg": "<error detail>",
"completeTime": 1786430358000,
"createTime": 1786430330000,
"costTime": 8,
"updateTime": 1786430358000
}
}