跳到主要内容

图片编辑

更新时间:2025-12-08 17:20:20
图片编辑API能基于用户输入的文字描述和图片,生成符合语义描述的新图片。
POST
https://cloud.baicaiinfer.com/v1/images/generations
Authorizations
AuthorizationsStringHeaderRequired

用户需使用已获取的API Key进行身份验证,以访问服务。

Body
application/json
selected_modelStringRequired

模型名称,选择Qwen-Image-Edit。更多模型,可参考支持的模型

task_typeEnumerateRequired

指定生成式模型需执行的任务类型,目前仅支持“image-edit”。更多模型,可参考支持的模型

response_formatEnumerateRequired

允许强制模型产生特定的输出格式。

inputStructRequired

生成式模型(如图像生成)的核心参数集合,包含prompt(正向提示词)、width/height(尺寸)等具体配置,用于定义生成内容的细节和规则。

input.promptStringRequired

是生成图像时用于描述期望内容(如场景、风格、细节等)的正向提示词,指导模型生成符合需求的图像。

input.negative_promptStringRequired

用于指定生成图像时需避免的元素(如低质量、失真等)的反向提示词,以优化生成结果的质量,示例:blurry, low quality, low resolution, cartoon, anime, painting, illustration, distorted face, bad proportions, extra limbs, unrealistic, overexposed, underexposed, noisy

input.widthIntRequired

指定生成图像的宽度,单位通常为像素,用于定义输出图像在水平方向上的尺寸,示例:640。

input.heightIntRequired

指定生成图像的高度,单位通常为像素,用于定义输出图像在垂直方向上的尺寸,示例:480。若直接提供了 width(宽度)和 height(高度)的具体像素值,系统将直接采用此设定。若未直接指定宽高,但同时提供了 resolution 和 aspect_ratio,系统将根据这两者自动计算出对应的宽高值。例如 16:9 + 720p,计算结果为 1280*720;如9:16 + 720p,计算结果为 720*1280。

input.guidance_scaleFloatRequired

控制生成内容与input.prompt(正向提示词)的契合度,值越高生成内容越贴近提示词,但可能降低图像自然度;值越低则模型创造力越强,但可能偏离需求,示例:1。

input.strengthFloatRequired

控制生成图片与原始输入图片相似程度的参数,示例:0.75。

input.number_of_imagesIntRequired

指定生成图像的数量,用于控制一次请求返回的图片总数,示例:1。

input.num_inference_stepsIntRequired

指定生成模型迭代优化的次数,次数越多生成图像细节越精细、质量越高,但同时会增加生成耗时,示例:35。

input.seedIntRequired

生成式模型中控制结果随机性的种子,固定它可复现相同结果,改变则生成不同内容,示例:-1。

input.true_cfg_scaleIntRequired

一种优化后的提示词引导,相比普通guidance_scale能更精准控制生成内容与提示词的契合度,减少过度引导导致的图像失真问题。当true_cfg_scale 大于1且提供了negative_prompt时,真正的无分类器引导(引导尺度)将被启用,示例:3.5。

input.imageStringRequired

单张图片。

Response
状态码:application/json
statusIntRequired

表示请求处理状态的状态码。

0是成功标识,表示接口正常返回预期结果。
messageStringRequired

返回请求的处理结果,通常配合状态码使用,直观告知用户当前请求的具体情况。

success是成功标识,表示请求完全正常处理,无任何问题。
dataStruct Required

返回生图请求成功后生成的具体内容,或请求失败时的补充信息。

data.urlList

是生成图像的网络访问链接,通过该URL可直接下载或在线查看图像文件(如PNG、JPG格式),适合需要快速预览或通过链接分享的场景。

data.b64_jsonList

是图像文件经Base64编码后的字符串,需解码后才能还原为图像数据,适合无法直接访问外部链接(如内网环境)或需要本地直接处理图像的场景。

curl --location --request POST 'https://cloud.baicaiinfer.com/v1/images/generations' \
--header 'Authorization: Bearer sk-5p1zwaivq2bRCfF08Vm*****' \
--header 'Content-Type: application/json' \
--data-raw '{
     "selected_model": "Qwen-Image-Edit",
    "task_type": "image-edit",
    "response_format":"url",
    "input": {
        "prompt": "a beautiful young woman, realistic face, detailed eyes, soft natural lighting, high-resolution portrait, 8K, ultra-detailed skin texture, cinematic lighting, professional photography, sharp focus",
        "negative_prompt": "blurry, low quality, low resolution, cartoon, anime, painting, illustration, distorted face, bad proportions, extra limbs, unrealistic, overexposed, underexposed, noisy",
        "width": 1024,
        "height": 1024,
        "guidance_scale": 1,
        "strength": 0.75,
        "number_of_images": 1,
        "num_inference_steps": 35,
        "seed": null,
        "true_cfg_scale": 3.5,
        "image": "https://s1.llamafactory.online/baicai-infer/users/acb6f5bdf6a04e53820a62b9ea53152c/307b7736f009461c9e0a0e3710d82dbe.png"
    }
}'

{
    "status": 0,
    "message": "success",
    "created": 1761015469,
    "data": {
        "url": [
            "https://llamafactory-online-assets.oss-cn-beijing.aliyuncs.com/baicai-infer/users/123456/output/356d8358150a42f09a47322baf66e97d.png"
        ]
    }
}