> ## Documentation Index
> Fetch the complete documentation index at: https://docs-vip.apigo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI 图片生成示例

> OpenAI 图片生成与编辑接入示例。

## 推荐 endpoint

* [OpenAI /v1/images/generations](/api-reference/endpoints/openai/image)
* [OpenAI /v1/images/edits](/api-reference/endpoints/openai/image-edits)

## 最小请求

```json theme={null}
{
  "model": "gpt-image-1",
  "prompt": "一张简洁的 ApiGo 产品海报",
  "size": "1024x1024",
  "n": 1
}
```

## cURL 示例

```bash theme={null}
curl https://api-vip.apigo.ai/v1/images/generations \
  -H "Authorization: Bearer $YOUR API KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-1",
    "prompt": "一张简洁的 ApiGo 产品海报",
    "size": "1024x1024",
    "n": 1
  }'
```

## Python 示例

```python theme={null}
from openai import OpenAI

client = OpenAI(
    base_url="https://api-vip.apigo.ai/v1",
    api_key="<YOUR API KEY>",
)

response = client.images.generate(
    model="gpt-image-1",
    prompt="一张简洁的 ApiGo 产品海报",
    size="1024x1024",
)

print(response.data[0].url or response.data[0].b64_json[:80])
```

## Node.js 示例

```js theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api-vip.apigo.ai/v1",
  apiKey: process.env.YOUR API KEY,
});

const response = await client.images.generate({
  model: "gpt-image-1",
  prompt: "一张简洁的 ApiGo 产品海报",
  size: "1024x1024"
});

console.log(response.data[0].url ?? response.data[0].b64_json?.slice(0, 80));
```

## 最佳实践

* 文生图和图片编辑分开走不同 endpoint
* 如果是多轮编辑，服务端保留原图 ID、临时 URL 或上一轮结果
* 返回体可能是 URL 或 base64，统一转存层放到服务端
