

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

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

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

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

当你使用 Stability AI 稳定扩散稳定图像核心模型 InvokeModel 拨打电话时，请使用如下所示的 JSON 对象填充正文字段。

```
{
        'prompt': 'Create an image of a panda'
    }
```

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

当你使用 Stability AI 稳定扩散稳定图像核心模型 InvokeModel 拨打电话时，响应如下所示 

```
{
        'seeds': [2130420379], 
        'finish_reasons': [null], 
        'images': ['...']
    }
```
+ **seeds** –（字符串）用于为模型生成图像的种子列表。
+ **finish\$1reasons** – 表示请求是否被过滤的枚举。`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\$1tag/v第 1 代](https://platform.us.stability.ai/docs/api-reference#tag/v1generation)。

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

Stable Image Core 模型具有以下推理参数，用于进行文本到图像的推理调用。

 **pro** mpt（必填）—（字符串）您希望在输出图像中看到的内容。清晰定义元素、颜色和主题的有效描述性提示可带来更好的结果。


| 最小值 | 最大值 | 
| --- | --- | 
| 0 | 10,000 个字符 | 

**可选字段**
+ **aspect\$1ratio** –（字符串）控制生成的图像的宽高比。此参数仅对 text-to-image请求有效。默认为 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.stable-image-core-v1:0',
         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")
```

------