image generation

Select a compatible endpoint, submit the prompt, and save the returned image.

Create image

Models that support the OpenAI image format use POST /v1/images/generations:

curl --fail-with-body https://dunduntoken.com/v1/images/generations \
 -H "Authorization: Bearer $DUNDUN_API_KEY" -H "Content-Type: application/json" \
 -d '{"model":"IMAGE_MODEL_ID","prompt":"白色背景上的蓝色陶瓷杯,柔和自然光","n":1}'

Replace the model with a picture model that is actually available on the site. Do not copy size, mass, and response format from other models; succeed with the fewest parameters first, then add options allowed by the target model.

Read and save

Common results are at data, and the image might be url or b64_json. It is also possible to encounter vendor-specific structures that should be parsed according to the selected protocol. Entries with only description text or revised prompt are not equal to images.

The return URL may be time-sensitive and should be downloaded to a storage you manage as soon as possible. Base64 should be decoded as binary, do not write the complete string directly into a PNG file.

Gemini and plug-in models

Gemini image native interface may return inlineData through generateContent. The unified endpoint capabilities of Wan, Qwen, Seedream and other models are determined by the corresponding plug-ins and configurations. Do not send Gemini content chunks directly to the OpenAI image endpoint.

Failure troubleshooting

Check model, input prompt, size, quantity, material access and price configuration. Client timeouts do not prove build failure; do not retry the same charge request indefinitely.

Python example of saving results

Run after installing openai. The example only automatically decodes inline data; the remote URL is handed over to the controlled download process to avoid sending the site’s Key to the storage domain name:

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

client = OpenAI(api_key=os.environ["DUNDUN_API_KEY"], base_url="https://dunduntoken.com/v1", timeout=600, max_retries=0)
result = client.images.generate(model="IMAGE_MODEL_ID", prompt="白色背景上的蓝色陶瓷杯", n=1)
for index, image in enumerate(result.data or []):
    if image.b64_json:
        payload = base64.b64decode(image.b64_json, validate=True)
        path = Path(f"image-{index}.bin")
        path.write_bytes(payload)
        print(path)
    elif image.url:
        print("请通过受控下载流程保存:", image.url)

The binary extension needs to be adjusted after confirming the true format. The production environment limits the download size, domain name, and redirection. Do not directly grab any address returned by the model.

Parameters are added item by item

First generate one, and then verify the size, quality, background, output format and other options supported by the current model. Don’t default to accepting the same enumeration for all models; check batch quantities against limits and budget first.

Acceptance and long requests

Verify that actual images are being returned, checking the format, size, body, and text. Some plug-ins will wait for asynchronous generation within the HTTP request, and the task may still continue after the client times out; the subsequent processing is judged based on the call record, and “no picture received” cannot be used to directly infer that no fees have been incurred.