# OpenAI

## 1. 概述

业界第一大语言模型。根据文字提示修改图片。

**模型列表：**

* `gpt-image-2`

## 2. 请求说明

* **请求方法**:`POST`
* **请求地址**:

  > `https://gateway.theturbo.ai/v1/images/edits`

***

## 3. 请求参数

### 3.1 Header 参数

| 参数名称            | 类型     | 必填 | 说明                                         | 示例值                                                                            |
| --------------- | ------ | -- | ------------------------------------------ | ------------------------------------------------------------------------------ |
| `Content-Type`  | string | 是  | 设置请求头类型，必须为 `multipart/form-data`          | `multipart/form-data; boundary=------------------------y0QNRDhXQUE3yHQi7DEbLz` |
| `Accept`        | string | 是  | 设置响应类型，建议统一为 `application/json`            | `application/json`                                                             |
| `Authorization` | string | 是  | 身份验证所需的 API\_KEY，格式 `Bearer $YOUR_API_KEY` | `Bearer $YOUR_API_KEY`                                                         |

***

### 3.2 Body 参数 (application/json)

| 参数名称       | 类型              | 必填 | 说明                                                                                                                        | 示例                      |
| ---------- | --------------- | -- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| **model**  | string          | 是  | 要使用的模型 ID。详见[概述](#1-概述)列出的可用版本，如 `gpt-image-2`。                                                                           | `gpt-image-2`           |
| **prompt** | string          | 是  | 一段描述所需图像的文字`gpt-image-2`描述最大长度为 32000 字符。                                                                                 | `A cute baby sea otter` |
| **image**  | file/file array | 是  | 提交用于编辑的图像。对于`gpt-image-2`，每张图像应为小于 25MB 的 PNG、WEBP 或 JPG 文件。您最多可以通过数组提交 16 张图像。                                           |                         |
| mask       | file            | 否  | 一个附加图像，其完全透明的区域（例如 alpha 为零的地方）表示图像应被编辑的位置。如果提供了多张图像，遮罩将应用于第一张图像。必须是有效的 PNG 文件，小于 4MB，且尺寸必须与图像相同。                         |                         |
| n          | number          | 否  | 生成图像的数量，必须在 1 到 10 之间。`gpt-image-2`仅支持 n=1。                                                                               | `1`                     |
| size       | string          | 否  | 生成图像的尺寸。`gpt-image-2`支持任意分辨率，以`WIDTHxHEIGHT`字符串形式指定，`WIDTH`和`HEIGHT`都必须能被 16 整除，且请求的宽高比必须介于`1:3`和`3:1`之间，最大支持`3840x2160`。 | `1024x1024`             |
| quality    | string          | 否  | 生成图像的质量选项。`gpt-image-2`支持`high`、`medium`、`low`。                                                                           | `high`                  |

***

## 4. 请求示例

{% tabs %}
{% tab title="单图片" %}

```sh
curl -X POST https://gateway.theturbo.ai/v1/images/edits \
	-H "Authorization: Bearer $YOUR_API_KEY" \
	-F "model=gpt-image-2" \
	-F "image=@input.png" \
	-F 'prompt=A cute baby sea otter wearing a beret' \
	-F ... 其它参数
```

{% endtab %}

{% tab title="多图片" %}

```sh
curl -X POST https://gateway.theturbo.ai/v1/images/edits \
	-H "Authorization: Bearer $YOUR_API_KEY" \
	-F "model=gpt-image-2" \
	-F "image[]=@input1.png" \
	-F "image[]=@input2.png" \
	-F 'prompt=A cute baby sea otter wearing a beret' \
	-F ... 其它参数
```

{% endtab %}
{% endtabs %}

## 5. 响应示例

{% tabs %}
{% tab title="b64\_json" %}

```json
{
	"created": 1589478378,
	"data": [{
			"b64_json": "..."
		},
		{
			"b64_json": "..."
		}
	],
	"usage": {
		"input_tokens": 0,
		"input_tokens_details": {
			"image_tokens": 0,
			"text_tokens": 0
		},
		"output_tokens": 0,
		"total_tokens": 0,
		"output_tokens_details": {
			"image_tokens": 0,
			"text_tokens": 0
		}
	}
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api/cn/compute/aig/image-edit/openai-image-edit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
