docs/sd/stable_diffusion.md

3.6 KiB
Raw Blame History

目录

1. 文生图接口


1. 文生图接口

接口功能

根据prompt生成图片

URL

http://sl.vrgon.com:6060/v1/workflows/run

Authorization

Bearer Token (密钥请联系算法团队)

支持格式

JSON

HTTP请求方式

POST

请求参数

Request Body
  • inputs (object) Required 允许传入 App 定义的各变量值。 inputs 参数包含了多组键值对Key/Value pairs每组的键对应一个特定变量每组的值则是该变量的具体值。
  • response_mode (string) Required 返回响应模式,支持:
    • streaming 流式模式(推荐)。基于 SSEServer-Sent Events实现类似打字机输出方式的流式返回。
    • blocking 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。 由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。
  • user (string) Required 用户标识,用于定义终端用户的身份,方便检索、统计。 由开发者定义规则,需保证用户标识在应用内唯一。
参数 必选 类型 说明
inputs ture json 请求数据
response_mode true string 返回方式。1streaming2blocking 。
user true string 用户名例如zk-123。
inputs (object)
参数 必选 类型 说明
prompt ture string 提示词
model_name fasle string 模型名称可选,[chilloutmix_NiPrunedFp32Fix],[dosmix_],[ghostmix_v20Bakedvae],[rundiffusionFX_v10],[v1-5-pruned-emaonly]默认为[v1-5-pruned-emaonly] 。

接口示例

curl -X POST 'http://sl.vrgon.com:6060/v1/workflows/run' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {
        "prompt": "一个胸有成竹的男人",
        "model_name": "chilloutmix_NiPrunedFp32Fix"
    },
    "response_mode": "blocking",
    "user": "alg123"
}'

Response

{
    "task_id": "40a1cce0-f8d1-4fa9-8d03-857ed804fe2a",
    "workflow_run_id": "00c81e90-5f5c-4606-8c10-de9195f5d159",
    "data": {
        "id": "00c81e90-5f5c-4606-8c10-de9195f5d159",
        "workflow_id": "aa4896ce-61eb-4873-8e8d-b18789bbd41b",
        "status": "succeeded",
        "outputs": {
            "files": [
                {
                    "__variant": "FileVar",
                    "tenant_id": "a28e2d2e-0eb5-49a6-8742-16369a5c22bd",
                    "type": "image",
                    "transfer_method": "tool_file",
                    "url": "/files/tools/8faea5f8-b5c9-498a-b557-a39c474f0e59.png?timestamp=1713938972&nonce=ab195cba5d0c37924bbbdfe1fd2c62e9&sign=F_kZ8pAmMi2xgtg47yGhgYXv_lAUHnZTD9_NuFQLkj0=",
                    "related_id": "8faea5f8-b5c9-498a-b557-a39c474f0e59",
                    "filename": "image",
                    "extension": ".png",
                    "mime_type": "image/png"
                }
            ]
        },
        "error": null,
        "elapsed_time": 18.601953488003346,
        "total_tokens": 536,
        "total_steps": 5,
        "created_at": 1713938954,
        "finished_at": 1713938972
    }
}

请求结果中的 url 即为生成好的图片,通过拼接http://sl.vrgon.com:6060 即可获得该图片

http://sl.vrgon.com:6060/files/tools/8faea5f8-b5c9-498a-b557-a39c474f0e59.png?timestamp=1713938972&nonce=ab195cba5d0c37924bbbdfe1fd2c62e9&sign=F_kZ8pAmMi2xgtg47yGhgYXv_lAUHnZTD9_NuFQLkj0=