

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Stable Image Ultra 請求和回應
<a name="model-parameters-diffusion-stable-ultra-text-image-request-response"></a>

請求內文會在請求的 `body` 欄位傳遞至 [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html) 操作。

**模型調用請求內文欄位**

當您使用 Stable Image Ultra 模型進行 InvokeModel 呼叫時，請在內文欄位中填入如下所示的 JSON 物件。
+ **prompt** – (字串) 您想要在輸出影像中看到的內容。一個強烈的描述性提示會清楚定義元素、顏色和主題，將帶來更好的結果。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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\$1reasons** – 指出請求是否已經過篩選的列舉。`null` 將指出請求成功。目前可能的值：`"Filter reason: prompt", "Filter reason: output image", "Filter reason: input image", "Inference error", null`。
+ **images** – 產生的影像清單，採用 base64 字串格式。

如需詳細資訊，請參閱 https：//[https://platform.us.stability.ai/docs/api-reference\$1tag/v1generation](https://platform.us.stability.ai/docs/api-reference#tag/v1generation)。

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

Stability.ai Stable Image Ultra 模型具有下列推論參數，可用於文字轉影像推論呼叫。
+ **prompt** – (字串) 您想要在輸出影像中看到的內容。一個強烈的描述性提示會清楚定義元素、顏色和主題，將帶來更好的結果。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/model-parameters-diffusion-stable-ultra-text-image-request-response.html)

**選用欄位**
+ **aspect\$1ratio** – (字串) 控制所產生影像的長寬比。此參數僅適用於文字轉影像請求。預設值為 1:1。列舉：16:9、1:1、21:9、2:3、3:2、4:5、5:4、9:16、9:21。
+ **mode** – 設定為文字轉影像。預設值：text-to-image。列舉：`text-to-image`。
+ **output\$1format** – 指定輸出影像的格式。支援的格式：JPEG、PNG。支援的維度：高度 640 到 1,536 像素，寬度 640 到 1,536 像素。
+ **seed** – (數字) 用來引導產生「隨機性」的特定值。(省略此參數或傳遞 0 以使用隨機種子。) 範圍：0 到 4294967295。
+ **negative\$1prompt** – 您不希望在輸出影像中看到的關鍵字。上限：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 模型具有下列推論參數，可用於影像轉影像推論呼叫。
+ **prompt** – (字串) 您想要在輸出影像中看到的內容。一個強烈的描述性提示會清楚定義元素、顏色和主題，將帶來更好的結果。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/model-parameters-diffusion-stable-ultra-text-image-request-response.html)

**選用欄位**
+ **image** – (字串) 要用作產生起點的 Base64 影像。支援的格式：JPEG、PNG、WebP。
+ **strength** – (數字) 影像參數對所產生影像的影響程度。強度值較低的影像看起來會更像原始影像。範圍：0.0 到 1.0。預設值：0.35。
+ **aspect\$1ratio** – (字串) 控制所產生影像的長寬比。此參數僅適用於文字轉影像請求。預設值為 1:1。列舉：16:9、1:1、21:9、2:3、3:2、4:5、5:4、9:16、9:21。
+ **output\$1format** – 指定輸出影像的格式。支援的格式：JPEG、PNG。支援的維度：高度 640 到 1,536 像素，寬度 640 到 1,536 像素。
+ **seed** – (數字) 用來引導產生「隨機性」的特定值。(省略此參數或傳遞 0 以使用隨機種子。) 範圍：0 到 4294967295。
+ **negative\$1prompt** – 您不希望在輸出影像中看到的關鍵字。上限：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")
```

------