

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Stable Image Ultra 请求和响应
<a name="model-parameters-diffusion-stable-ultra-text-image-request-response"></a>

请求正文在[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)操作请求`body`字段中传递。

**模型调用请求正文字段**

当你使用 Stable Image Ultra 模型 InvokeModel 拨打电话时，在正文字段中填充一个如下所示的 JSON 对象。
+ **prompt** –（字符串）您希望在输出图像中看到的内容。清晰定义元素、颜色和主题的有效描述性提示可带来更好的结果。    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/bedrock/latest/userguide/model-parameters-diffusion-stable-ultra-text-image-request-response.html)

**模型调用响应正文字段**

使用 Stable Image Ultra 模型调用 `InvokeModel` 时，响应类似于以下内容 

```
{
         'seeds': [2130420379], 
         "finish_reasons":[null], 
         "images":["..."]
     }
```

完成原因非 `null` 的响应将类似于以下内容：

```
{
         "finish_reasons":["Filter reason: prompt"]
     }
```
+ **seeds** –（字符串）用于为模型生成图像的种子列表。
+ **finish\_reasons** – 表示请求是否被过滤的枚举。`null` 表示请求成功。当前可能的值：`"Filter reason: prompt", "Filter reason: output image", "Filter reason: input image", "Inference error", null`。
+ **images** – 以 base64 字符串格式生成的图像列表。

欲了解更多信息，请参阅 [https://platform.us.stability。 ai/docs/api-reference\#tag/v第 1 代](https://platform.us.stability.ai/docs/api-reference#tag/v1generation)。

------
#### [ Text to image ]

Stability.ai Stable Image Ultra 模型具有以下用于推理调用的 text-to-image推理参数。
+ **prompt** –（字符串）您希望在输出图像中看到的内容。清晰定义元素、颜色和主题的有效描述性提示可带来更好的结果。    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/bedrock/latest/userguide/model-parameters-diffusion-stable-ultra-text-image-request-response.html)

**可选字段**
+ **aspect\_ratio** –（字符串）控制生成的图像的宽高比。此参数仅对 text-to-image请求有效。默认为 1:1。枚举：16:9、1:1、21:9、2:3、3:2、4:5、5:4、9:16、9:21。
+ **模式**-设置为 text-to-image。默认： text-to-image。枚举：`text-to-image`。
+ **output\_format** – 指定输出图像的格式。支持的格式：JPEG、PNG。支持的尺寸：高 640 到 1,536 像素，宽 640 到 1,536 像素。
+ **seed** –（数字）用于说明生成的随机性的特定值。（省略此参数或输入 0 以使用随机种子。） 范围：0 至 4294967295。
+ **negative\_prompt** – 您不想在输出图像中看到的关键字。最多：10,000 个字符。

```
import boto3
       import json
       import base64
       import io
       from PIL import Image
       
       bedrock = boto3.client('bedrock-runtime', region_name='us-west-2')
       response = bedrock.invoke_model(
           modelId='stability.sd3-ultra-v1:1',
           body=json.dumps({
               'prompt': 'A car made out of vegetables.'
           })
       )
       output_body = json.loads(response["body"].read().decode("utf-8"))
       base64_output_image = output_body["images"][0]
       image_data = base64.b64decode(base64_output_image)
       image = Image.open(io.BytesIO(image_data))
       image.save("image.png")
```

------
#### [ Image to image ]

Stability.ai Stable Image Ultra 模型具有以下用于推理调用的 image-to-image推理参数。
+ **prompt** –（字符串）您希望在输出图像中看到的内容。清晰定义元素、颜色和主题的有效描述性提示可带来更好的结果。    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/bedrock/latest/userguide/model-parameters-diffusion-stable-ultra-text-image-request-response.html)

**可选字段**
+ **image** –（字符串）用作生成起点的 Base64 图像。支持的格式：JPEG、PNG、WebP。
+ **strength** –（数字）image 参数对生成的图像的影响程度。strength 值越低的图像与原始图像的相似度越高。范围：0.0 至 1.0。默认值：0.35。
+ **aspect\_ratio** –（字符串）控制生成的图像的宽高比。此参数仅对 text-to-image请求有效。默认为 1:1。枚举：16:9、1:1、21:9、2:3、3:2、4:5、5:4、9:16、9:21。
+ **output\_format** – 指定输出图像的格式。支持的格式：JPEG、PNG。支持的尺寸：高 640 到 1,536 像素，宽 640 到 1,536 像素。
+ **seed** –（数字）用于说明生成的随机性的特定值。（省略此参数或输入 0 以使用随机种子。） 范围：0 至 4294967295。
+ **negative\_prompt** – 您不想在输出图像中看到的关键字。最多：10,000 个字符。

```
import boto3
       import json
       import base64
       import io
       from PIL import Image
       
       bedrock = boto3.client('bedrock-runtime', region_name='us-west-2')
       response = bedrock.invoke_model(
           modelId='stability.sd3-ultra-v1:1',
           body=json.dumps({
               'prompt': 'A car made out of vegetables.'
           })
       )
       output_body = json.loads(response["body"].read().decode("utf-8"))
       base64_output_image = output_body["images"][0]
       image_data = base64.b64decode(base64_output_image)
       image = Image.open(io.BytesIO(image_data))
       image.save("image.png")
```

------