Skip to Content

Images API

Two endpoints: Generate (text → image) and Edit (image + text → image). Both responses follow the OpenAI standard shape data[0].b64_json.

Gemini image models (e.g. google/gemini-3.1-flash-image-preview) on this endpoint only support generation, not editing. For editing, use the Gemini native protocol.

Generate images

POST https://api.ofox.ai/v1/images/generations

With gpt-image-2

gen.py
import base64 from openai import OpenAI client = OpenAI(api_key="YOUR_OFOX_API_KEY", base_url="https://api.ofox.ai/v1") resp = client.images.generate( model="openai/gpt-image-2", prompt="A simple red apple on a white table", size="1024x1024", quality="low", output_format="png", ) with open("output.png", "wb") as f: f.write(base64.b64decode(resp.data[0].b64_json))

Sample output:

Red apple generated by gpt-image-2

With gemini-3.1-flash-image-preview

The same endpoint also accepts Gemini image models. Do not pass n — the gateway maps n incorrectly to the numberOfImages field and returns 400. Each call produces exactly one image.

gen_gemini.py
import base64 from openai import OpenAI client = OpenAI(api_key="YOUR_OFOX_API_KEY", base_url="https://api.ofox.ai/v1") resp = client.images.generate( model="google/gemini-3.1-flash-image-preview", prompt="A simple red apple on a white table, photorealistic", size="1024x1024", quality="low", output_format="png", ) with open("output.png", "wb") as f: f.write(base64.b64decode(resp.data[0].b64_json))

Sample output:

Red apple generated by Gemini

Parameters

ParameterTypeRequiredDescription
modelstringopenai/gpt-image-2, google/gemini-3.1-flash-image-preview
promptstringNatural-language description
qualitystringauto / low / medium / high / standard / hd
nnumber1–10, default 1. Not supported by Gemini models
sizestringauto / 1024x1024 / 1536x1024 / 1024x1536 / 256x256 / 512x512 / 1792x1024 / 1024x1792
output_formatstringpng / jpeg / webp
backgroundstringtransparent / opaque / auto
streambooleanDefault false

Response

{ "created": 1777385517, "data": [ { "b64_json": "<image Base64>", "index": 0 } ], "model": "openai/gpt-image-2", "size": "1024x1024", "quality": "low", "usage": { "input_tokens": 14, "input_tokens_details": { "text_tokens": 14 }, "output_tokens": 208, "total_tokens": 222 } }

The image lives in data[0].b64_json — base64-decode and save it.

Edit images

POST https://api.ofox.ai/v1/images/edits

multipart/form-data — you must upload an image file.

This endpoint only supports OpenAI / Azure OpenAI models. Calling it with google/gemini-3.1-flash-image-preview returns Image editing is not supported for model — switch to editing via the Gemini native protocol.

Call

edit.py
import base64 from openai import OpenAI client = OpenAI(api_key="YOUR_OFOX_API_KEY", base_url="https://api.ofox.ai/v1") with open("apple.png", "rb") as f: resp = client.images.edit( model="openai/gpt-image-2", image=f, prompt="把苹果改成绿色,其他保持不变", size="auto", quality="low", ) with open("apple_edited.png", "wb") as out: out.write(base64.b64decode(resp.data[0].b64_json))

The image field takes a local file path (with the @ prefix in cURL), not a URL.

Before / after:

OriginalEdited
Original red appleEdited green apple

Parameters

ParameterTypeRequiredDescription
modelstringRecommended: openai/gpt-image-2
imagefilePNG / JPEG file
promptstringEdit instruction
qualitystringlow / medium / high
nnumberDefault 1
sizestringauto keeps the original size

Response

Same shape as generation:

{ "created": 1777385669, "data": [ { "b64_json": "<edited image Base64>", "index": 0 } ], "model": "openai/gpt-image-2", "size": "auto", "quality": "low", "usage": { "input_tokens": 1041, "input_tokens_details": { "image_tokens": 1024, "text_tokens": 17 }, "num_input_images": 1, "output_tokens": 358, "total_tokens": 1399 } }

usage.input_tokens_details.image_tokens is the tokens consumed by the input image; num_input_images is the input image count.

See supported models and pricing in the Model Catalog .

Last updated on