> 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-sheng-cheng/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` 支持文本生成图像。`n` 可请求 1-10 张图像，实际返回数量可能少于请求数量。
{% endhint %}

| 参数                   | 支持情况                                                          |
| -------------------- | ------------------------------------------------------------- |
| `prompt`             | 必填，最长参考为 32000 个字符。                                           |
| `n`                  | 可选，范围参考为 1-10；实际返回图片数量可能少于请求数量。                               |
| `size`               | 可选，支持 `auto` 和下方列出的固定尺寸。                                      |
| `quality`            | 可选，支持 `low`、`medium`、`high`；省略、`auto`、`standard` 按 `high` 计费。 |
| `background`         | 可选，支持 `opaque`、`auto`。                                        |
| `moderation`         | 可选，仅图像生成接口支持，支持 `low`、`auto`。                                 |
| `output_format`      | 可选，支持 `png`、`jpeg`。                                           |
| `output_compression` | 可选，范围 0-100，仅 `jpeg` 使用；`png` 应省略或设为 100。                     |

支持尺寸：`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_generations_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/generations":{"post":{"tags":["image_generations_openai"],"summary":"创建图像","description":"根据文本提示生成图像。与 OpenAI 的 Images API 兼容。","operationId":"createImageGeneration_openai","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","description":"gpt-image-2 图像生成请求体。","properties":{"model":{"type":"string","description":"要调用的模型 ID。"},"prompt":{"type":"string","maxLength":32000,"description":"图像生成提示词。"},"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"]},"moderation":{"type":"string","description":"图像生成的内容审核强度。","enum":["low","auto"]},"output_format":{"type":"string","description":"输出图片格式。","enum":["png","jpeg"],"default":"png"},"output_compression":{"type":"integer","minimum":0,"maximum":100,"description":"0-100 的压缩级别，仅适用于 jpeg；png 应省略或设为 100。"}},"required":["model","prompt"]}}}},"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"}}}}}}
```
