Skip to content
English

Image Generation Integration

Generate images using the OpenAI Images API, save Base64 results, and troubleshoot model permissions and timeouts.

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 , then confirm the image API and parameters in the console model catalog .

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.

  • 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.

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

Section titled “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.

SituationTroubleshooting Method
400 parameter not supportedRemove optional parameters such as custom size and quality, then verify one by one
403 / 404Check the image model ID, key permissions, and the full API path
Long wait timeSet a reasonable timeout for generation and display an in-progress status to avoid repeated submissions from continuous clicking
No image after timeoutFirst check the call logs; not receiving a result does not mean the upstream did not process the request
Want to edit an existing imageImage 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 . Fees are based on this site’s real-time model catalog; for retry strategy, see Timeouts and Retries .