Images API
两个端点:生成(文字 → 图)、编辑(图 + 文字 → 图)。响应都是 OpenAI 标准结构 data[0].b64_json。
Gemini 系列图像模型(如 google/gemini-3.1-flash-image-preview)在本端点只能生成不能编辑。需要编辑请走 Gemini 原生协议。
生成图像
POST https://api.ofox.ai/v1/images/generations用 gpt-image-2
Python
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))实测输出:

用 gemini-3.1-flash-image-preview
同一端点也接受 Gemini 图像模型。不要传 n——网关会把 n 错误映射为 numberOfImages 字段并报 400,每次固定生成 1 张。
Python
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))实测输出:

参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | openai/gpt-image-2、google/gemini-3.1-flash-image-preview |
prompt | string | ✅ | 自然语言描述 |
quality | string | ✅ | auto / low / medium / high / standard / hd |
n | number | — | 1–10,默认 1。Gemini 模型不支持 |
size | string | — | auto / 1024x1024 / 1536x1024 / 1024x1536 / 256x256 / 512x512 / 1792x1024 / 1024x1792 |
output_format | string | — | png / jpeg / webp |
background | string | — | transparent / opaque / auto |
stream | boolean | — | 默认 false |
响应
{
"created": 1777385517,
"data": [
{ "b64_json": "<图片 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
}
}图片在 data[0].b64_json,自行 base64 解码后保存。
编辑图像
POST https://api.ofox.ai/v1/images/editsmultipart/form-data,需上传图片文件。
此端点仅支持 OpenAI / Azure OpenAI 模型。google/gemini-3.1-flash-image-preview 调用会返回 Image editing is not supported for model——改走 Gemini 原生协议编辑图像。
调用
Python
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))image 字段传本地文件路径(cURL 用 @ 前缀),不是 URL。
实测对比:
| 原图 | 编辑后 |
|---|---|
![]() | ![]() |
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | 推荐 openai/gpt-image-2 |
image | file | ✅ | PNG / JPEG 文件 |
prompt | string | ✅ | 编辑指令 |
quality | string | ✅ | low / medium / high |
n | number | — | 默认 1 |
size | string | — | auto 表示与原图一致 |
响应
与生成一致:
{
"created": 1777385669,
"data": [
{ "b64_json": "<编辑后图片 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 是输入图片消耗的 token,num_input_images 是输入图片张数。
支持的模型与价格见 模型目录 。
Last updated on
