---
title: "Image Generation Integration"
description: "Generate images using the OpenAI Images API, save Base64 results, and troubleshoot model permissions and timeouts."
headingIds: {"API and Setup":"section-1","Generate and Save an Image":"section-2","Confirm Model Support Before Adding Parameters":"section-3","Troubleshooting":"section-4"}
---

<aside className="docs-publication" data-pagefind-ignore>

Documentation maintained by [1ZheAI](https://1zheai.com/en/editorial/#publisher). [Sources and corrections](https://1zheai.com/en/editorial/).

Found an error? [Contact support](mailto:support@1zheai.com) with the page address and a description. Do not send API keys or account credentials.

</aside>
The public model catalog on this site currently lists `gpt-image-1.5` and `chatgpt-image-latest` (verified on 2026-10-16). Before use, first query [available models for your key ](/en/docs/api-models/), then confirm the image API and parameters in the [console model catalog ](https://1zheai.com/model-catalog?lng=en).

This page provides integration examples following the OpenAI Images protocol; no paid image generation was performed during this documentation update, so the examples below should not be treated as having been tested across all model, size, and quality combinations.

## API and Setup

- Full endpoint: `POST https://1zheai.com/v1/images/generations`
- OpenAI SDK Base URL: `https://1zheai.com/v1`
- Use the `ONEZHE_API_KEY` environment variable on this site.
- Install the Python SDK: `python -m pip install openai`.

## Generate and Save an Image

Save as `generate-image.py`, then run `python generate-image.py` in the terminal:

```python
import base64
import os
from pathlib import Path
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ONEZHE_API_KEY"],
    base_url="https://1zheai.com/v1",
    timeout=300.0,
    max_retries=0,
)
result = client.images.generate(
    model=os.environ.get("ONEZHE_IMAGE_MODEL", "gpt-image-1.5"),
    prompt="一只白色陶瓷茶杯放在浅灰色桌面上，柔和自然光，无文字。",
)
if not result.data:
    raise RuntimeError("响应没有图片数据，请检查错误信息与调用日志。")
item = result.data[0]
if item.b64_json:
    target = Path("generated-image.png")
    target.write_bytes(base64.b64decode(item.b64_json, validate=True))
    print(f"图片已保存到 {target.resolve()}")
elif item.url:
    print("返回的是图片地址，请及时下载：", item.url)
else:
    raise RuntimeError("响应没有 b64_json 或 url。")
```

The example uses the default output format. If you specify JPEG / WebP or another format, change the file extension accordingly when saving. Do not write the Base64 string directly to a text file and rename it to PNG.

## Confirm Model Support Before Adding Parameters

First verify with a request containing only `model` and `prompt`. Parameters such as size, quality, transparent background, and output format are not universally supported across all image models; do not directly copy model names or proprietary parameters from other providers.

When `data[].b64_json` is returned, perform Base64 decoding; when `data[].url` is returned, download it promptly and do not treat the temporary URL as permanent storage. The application must arrange its own result storage.

## Troubleshooting

| Situation | Troubleshooting Method |
| --- | --- |
| 400 parameter not supported | Remove optional parameters such as custom size and quality, then verify one by one |
| 403 / 404 | Check the image model ID, key permissions, and the full API path |
| Long wait time | Set a reasonable timeout for generation and display an in-progress status to avoid repeated submissions from continuous clicking |
| No image after timeout | First check the call logs; not receiving a result does not mean the upstream did not process the request |
| Want to edit an existing image | Image editing is a different API and input method; the text-to-image example on this page cannot directly replace it |

For protocol parameter reference, see [OpenAI Image Generation Reference ](https://developers.openai.com/api/reference/resources/images/methods/generate). Fees are based on this site's real-time model catalog; for retry strategy, see [Timeouts and Retries ](/en/docs/retries/).
