1.Stable Diffusion 3 API开放了!
Stability AI在2024年4月18日开放了其最新的SD3 API。它的开放性使得更多的开发者可以接触到Stability AI的AI模型,可以预见到AI技术将会得到更广泛的应用。
API支持Text-to-Image、Image-to-Image两种模式。
AIGC文生图或图生图方向又多了一个选择。体验了下API能力,出图质量相对还是不错的。出图质量比Fooocus高,出图速度比Midjounery快。接口是实时响应,10s左右出结果。
2.Stability AI Document地址
API文档地址:https://platform.stability.ai/
3.获取API Key
点击右上角账户信息,可以查看API Keys获取key,查看Billing订购积分。
4.API方式调用SD3出图
接口地址
SD3接口地址:https://api.stability.ai/v2beta/stable-image/generate/sd3
当前Stability AI发布的API版本是 v2beta 版本。(几周前还是alpha版本)
接口请求规范
接口请求规范参考文档说明即可。
- Authorization 认证
认证类型为 Bearer Token。Token值即为API Key。
示例值:sk-hmTXXXXXXXXXXXXXXXXz - Headers 请求头
(1)authorization
示例值:Bearer sk-hmTXXXXXXXXXXXXXXXXz
(2)content-type
固定值:multipart/form-data
(3)accept
示例值:application/json、image/*。
image/* 接收图片字节数据。application/json 接收JSON格式结果,其中包含图片base64编码。
- Body 请求体
(1)prompt 提示词【必传】
(2)aspect_ratio 宽高比【非必传,默认1:1】
示例值: 16:9 1:1 21:9 2:3 3:2 4:5 5:4 9:16 9:21
(3)mode 模式【非必传,默认text-to-image】
示例值:text-to-image、image-to-image
(4)model 模型【非必传,默认sd3】
示例值:sd3、sd3-turbo
(5)negative_prompt 反向提示词【非必传,默认空】
提示词是表明,生成的图片要符合提示词。
反向提示词是表明,生成的图片不要包含反向提示词提到的信息。
模型指定为sd3-turbo时,负面提示词不生效。
(6)seed 种子【非必传,默认0】
取值范围:[ 0 … 4294967294 ]
指定种子,允许出图时,参考种子对应的出图结果,进行微调,重新生成新的出图结果。
不指定种子,允许出图时,自由发散的去创作出图结果。
(7)output_format 输出格式【非必传,默认png】
示例值:jpeg、png
当mode 模式为image-to-image时,去除aspect_ratio 参数,增加参数image、strength
- Body 请求体
(1)image 原图片【必传】
支持的图片格式为jpeg、png、webp
(2)strength 降噪【必传】
取值范围[ 0 … 1 ]
图像降噪是个图像领域的专业词汇,指减少数字图像中噪点的过程。
噪点,可以简单理解为,如果连续时间内,某个点相对同一位置产生的不同点来说误差较大,显得突兀,可以标记为噪点,降噪就是去除噪点的过程。使得图片看起来更加真实,符合人类视觉感受,符合客观规律。
值为0将产生与输入相同的图像。如果值为1,则表示您根本没有传递任何图像。
接口请求响应结果
此处使用Postman调用SD3 API,text-to-image。
提示词:Lighthouse on a cliff overlooking the ocean
模型:sd3-turbo
Postman请求明细:可以将以下代码,另存为Stability.postman_collection.json文件,导入到Postman工具。注意替换request.auth.bearer.value为可用的Stability API Key
{
"info": {
"_postman_id": "92b9d0d1-fc78-4eed-a01c-de7fa58594d4",
"name": "Stability",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "7588473"
},
"item": [
{
"name": "Stable Diffusion 3.0",
"protocolProfileBehavior": {
"disabledSystemHeaders": {
"accept": true
}
},
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "sk-xxxxxxxxxxxxxx",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "content-type",
"value": "multipart/form-data"
},
{
"key": "accept",
"value": "application/json"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "prompt",
"value": "Batman stood under the eaves, the moonlight shining on his black cape",
"type": "text"
},
{
"key": "model",
"value": "sd3-turbo",
"description": "sd3 sd3-turbo",
"type": "text"
},
{
"key": "aspect_ratio",
"value": "9:16",
"description": "16:9 1:1 21:9 2:3 3:2 4:5 5:4 9:16 9:21",
"type": "text"
},
{
"key": "mode",
"value": "text-to-image",
"description": "text-to-image image-to-image",
"type": "text"
},
{
"key": "seed",
"value": "0",
"type": "text"
},
{
"key": "output_format",
"value": "png",
"description": "jpeg png",
"type": "text"
}
]
},
"url": {
"raw": "https://api.stability.ai/v2beta/stable-image/generate/sd3",
"protocol": "https",
"host": [
"api",
"stability",
"ai"
],
"path": [
"v2beta",
"stable-image",
"generate",
"sd3"
]
}
},
"response": []
}
]
}
调用情况如下所示:
5.Stable Diffusion 3.0、Stable Image Core、Fooocus 2.3.1、MidJounery效果查看
指定相同的提示词:Lighthouse on a cliff overlooking the ocean
其中Stable Image Core和Fooocus明确指定了绘图风格 anime
-
Stable Diffusion 3.0
-
Stable Image Core
-
Fooocus 2.3.1
-
MidJounery
Fooocus官网:fooocus.cc
Stable Diffusion官网:stability.ai/stable-image
MidJounery官网:midjourney.com
Powered By niaonao