> For the complete documentation index, see [llms.txt](https://nsclouds.gitbook.io/aillm.nscloud.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nsclouds.gitbook.io/aillm.nscloud.ai/api-reference-cn/tu-xiang-bian-ji/openai.md).

# OpenAI

### 1. 概述

OpenAI 在当前环境中提供的图像编辑能力。

{% hint style="success" %}
本接口提供 OpenAI Images API 的 gpt-image-2 图像能力。
{% endhint %}

**模型列表：**

* `gpt-image-2`

### 2. gpt-image-2 参数说明

{% hint style="info" %}
`gpt-image-2` 支持基于一张或多张输入图像进行编辑。`mask` 为可选参数，透明区域代表需要编辑的区域。
{% endhint %}

| 参数              | 支持情况                                                          |
| --------------- | ------------------------------------------------------------- |
| `image`         | 必填，支持单图或多图；可传 URL、base64、data URI 或文件上传。                      |
| `prompt`        | 必填，最长参考为 32000 个字符。                                           |
| `mask`          | 可选，透明区域代表编辑区域。                                                |
| `n`             | 可选，范围参考为 1-10；实际返回图片数量可能少于请求数量。                               |
| `size`          | 可选，支持 `auto` 和下方列出的固定尺寸。                                      |
| `quality`       | 可选，支持 `low`、`medium`、`high`；省略、`auto`、`standard` 按 `high` 计费。 |
| `background`    | 可选，支持 `opaque`、`auto`。                                        |
| `output_format` | 可选，支持 `png`、`jpeg`。                                           |

支持尺寸：`auto`, `1024x1024`, `1024x1536`, `1536x1024`, `2048x2048`, `2048x1152`, `3840x2160`, `2160x3840`, `2048x1360`, `1360x2048`, `1152x2048`, `2048x1536`, `1536x2048`, `2048x880`, `880x2048`, `688x2048`, `2048x688`, `2048x1024`, `1024x2048`

### 3. 接口详情

## 编辑图像

> 根据原始图像和文本提示创建编辑后的图像。与 OpenAI 的 Images API 兼容。

```json
{"openapi":"3.1.0","info":{"title":"NSCloud AI API 文档","version":"1.11.0"},"tags":[{"name":"image_edits_openai","description":"OpenAI 的图像编辑 API"}],"servers":[{"url":"https://aillm.nscloud.ai","description":"国际服务器"}],"security":[{"APIKeyHeader":[]}],"components":{"securitySchemes":{"APIKeyHeader":{"type":"http","scheme":"bearer","description":"使用 Bearer 令牌进行认证，格式：'Bearer YOUR_SECRET_TOKEN'"}},"schemas":{"ImageUsage":{"type":"object","description":"图像生成的资源使用统计。","properties":{"total_tokens":{"type":"integer","description":"总 token 数。"},"input_tokens":{"type":"integer","description":"输入 token 数。"},"output_tokens":{"type":"integer","description":"输出 token 数。"},"input_tokens_details":{"type":"object","description":"输入 token 使用明细。","properties":{"text_tokens":{"type":"integer","description":"文本提示消耗的 token 数。"},"image_tokens":{"type":"integer","description":"图片输入消耗的 token 数。"}},"additionalProperties":true}}},"ErrorResponse":{"type":"object","description":"错误响应。","properties":{"error":{"$ref":"#/components/schemas/ErrorDetail"}}},"ErrorDetail":{"type":"object","description":"错误详情对象。","properties":{"message":{"type":"string","description":"错误说明。"},"type":{"type":"string","description":"错误类型。"},"param":{"description":"与错误相关的参数名。","type":["string","null"]},"code":{"description":"错误码。","type":["string","null"]}}}},"responses":{"ErrorResponse":{"description":"错误响应","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/v1/images/edits":{"post":{"tags":["image_edits_openai"],"summary":"编辑图像","description":"根据原始图像和文本提示创建编辑后的图像。与 OpenAI 的 Images API 兼容。","operationId":"createImageEdit_openai","requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","description":"gpt-image-2 图像编辑请求体。","properties":{"model":{"type":"string","description":"要调用的模型 ID。"},"image":{"description":"输入的一张或多张图片，支持文件上传、URL、base64 字符串和 data URI。","anyOf":[{"type":"string","format":"binary"},{"type":"array","items":{"type":"string","format":"binary"}},{"type":"string"},{"type":"array","items":{"type":"string"}}]},"prompt":{"type":"string","maxLength":32000,"description":"图像编辑提示词。"},"mask":{"description":"可选蒙版，透明区域代表编辑区域。","anyOf":[{"type":"string","format":"binary"},{"type":"string"}]},"n":{"type":"integer","minimum":1,"maximum":10,"default":1,"description":"请求生成的图片数量，实际返回数量可能少于请求数量。"},"size":{"type":"string","description":"请求的输出图片尺寸。","enum":["auto","1024x1024","1024x1536","1536x1024","2048x2048","2048x1152","3840x2160","2160x3840","2048x1360","1360x2048","1152x2048","2048x1536","1536x2048","2048x880","880x2048","688x2048","2048x688","2048x1024","1024x2048"],"default":"1024x1024"},"quality":{"type":"string","description":"请求的图像质量等级。","enum":["low","medium","high"],"default":"high"},"background":{"type":"string","description":"背景处理模式。","enum":["opaque","auto"]},"output_format":{"type":"string","description":"输出图片格式。","enum":["png","jpeg"],"default":"png"}},"required":["model","image","prompt"]},"encoding":{"image":{"style":"form","explode":true}}}}},"responses":{"200":{"description":"成功响应","content":{"application/json":{"schema":{"type":"object","description":"gpt-image-2 图像编辑响应。","properties":{"created":{"type":"integer","description":"响应创建时间戳（Unix 秒）。"},"background":{"type":"string","description":"编辑图像的背景类型。"},"output_format":{"type":"string","description":"输出图片格式。"},"quality":{"type":"string","description":"实际使用的图像质量等级。"},"size":{"type":"string","description":"实际返回的图像尺寸。"},"data":{"type":"array","description":"编辑图像结果列表。","items":{"type":"object","properties":{"url":{"type":"string","description":"编辑图片 URL。"},"revised_prompt":{"type":"string","description":"模型实际使用或修正后的提示词。"}}}},"usage":{"$ref":"#/components/schemas/ImageUsage"}}}}}},"400":{"$ref":"#/components/responses/ErrorResponse"},"401":{"$ref":"#/components/responses/ErrorResponse"},"429":{"$ref":"#/components/responses/ErrorResponse"}}}}}}
```
