图像生成
OpenAI 兼容 images/generations 与 images/edits 接口
Hubridge Gateway 提供 OpenAI 兼容图像生成与编辑 接口,除 对话补全 外可直接调用。
Base URL:https://api.hubridge.net
鉴权
Authorization: Bearer YOUR_API_KEY图像生成使用 Content-Type: application/json;图像编辑使用 multipart/form-data。
常用模型
| 模型 slug | 说明 |
|---|---|
gpt-image-2 | OpenAI 图像生成/编辑模型 |
请在 模型广场 查看当前可用图像模型及定价。
图像生成
POST /v1/images/generations根据文本提示词生成图片。
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 图像模型 slug |
prompt | string | 是 | 图像描述提示词 |
n | integer | 否 | 生成张数,默认 1 |
size | string | 否 | 尺寸,如 1024x1024 |
quality | string | 否 | 质量,如 standard、hd |
response_format | string | 否 | url 或 b64_json,默认 url |
style | string | 否 | 风格,如 vivid、natural(部分模型支持) |
示例:
{
"model": "gpt-image-2",
"prompt": "A cute cat sitting on a windowsill, watercolor style",
"n": 1,
"size": "1024x1024"
}cURL
curl -X POST "https://api.hubridge.net/v1/images/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cute cat sitting on a windowsill, watercolor style",
"n": 1,
"size": "1024x1024"
}'响应示例
{
"created": 1710000000,
"data": [
{
"url": "https://example.com/image.png",
"revised_prompt": "A cute cat sitting on a windowsill, watercolor style"
}
]
}Python(OpenAI SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://api.hubridge.net/v1",
api_key="YOUR_API_KEY",
)
response = client.images.generate(
model="gpt-image-2",
prompt="A cute cat sitting on a windowsill, watercolor style",
n=1,
size="1024x1024",
)
print(response.data[0].url)Node.js(OpenAI SDK)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.hubridge.net/v1",
apiKey: "YOUR_API_KEY",
});
const response = await client.images.generate({
model: "gpt-image-2",
prompt: "A cute cat sitting on a windowsill, watercolor style",
n: 1,
size: "1024x1024",
});
console.log(response.data[0]?.url);图像编辑
POST /v1/images/edits基于参考图与提示词生成编辑结果;可选 mask 指定编辑区域(透明部分将被重绘)。
请求体(multipart/form-data)
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 图像模型 slug |
prompt | string | 是 | 编辑描述提示词 |
image | file | 是 | 参考图片(PNG,小于 4MB) |
n | integer | 否 | 生成张数 |
size | string | 否 | 输出尺寸,如 1024x1024 |
mask | file | 否 | 蒙版图片(PNG,透明区域为编辑范围) |
cURL
curl -X POST "https://api.hubridge.net/v1/images/edits" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Add a red scarf to the cat" \
-F "image=@/path/to/cat.png" \
-F "n=1" \
-F "size=1024x1024"带蒙版示例:
curl -X POST "https://api.hubridge.net/v1/images/edits" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Replace the sky with a sunset" \
-F "image=@/path/to/photo.png" \
-F "mask=@/path/to/mask.png" \
-F "size=1024x1024"响应示例
{
"created": 1710000000,
"data": [
{
"url": "https://example.com/edited.png"
}
]
}完整 Schema
字段细节与错误码见 API 参考 · Gateway 中的「OpenAI 图像生成」「OpenAI 图像编辑」章节,以及 数据模型 中的 ImageGenerationRequest / ImageEditRequest。
