Image Generation and Edits
Image endpoints require an OpenAI group with Images API support. Call /v1/models first to verify that the current key can see an image model.
Generate an image
bash
curl https://codexapi.asia/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A clean studio photograph of a white ceramic cup.",
"size": "1024x1024",
"quality": "high",
"response_format": "b64_json"
}'The generated image is usually returned in data[0].b64_json. Some chat clients display only text and do not render Base64 image data automatically.
Decode with Python
python
import base64
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["CODEX_RELAY_API_KEY"],
base_url="https://codexapi.asia/v1",
)
result = client.images.generate(
model="gpt-image-2",
prompt="A minimal product photo of a desk lamp.",
size="1024x1024",
response_format="b64_json",
)
with open("image.png", "wb") as image_file:
image_file.write(base64.b64decode(result.data[0].b64_json))Edit an image
Image edits use a multipart form:
bash
curl https://codexapi.asia/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Change the background to pure white" \
-F "image=@input.png" \
-F "response_format=b64_json"Responses image tool
Models with Responses tool support can accept an image_generation tool in a /v1/responses request. Availability depends on the model, group, and upstream account capabilities.
The request succeeded but no image is visible
- Inspect the raw JSON for
b64_jsonor an image-tool result. - Confirm that the client can render Base64 images.
- Save the image with the Python example to isolate a display issue.
- If the response contains no image field, keep the request ID and verify that the selected model supports image output.
