Hubridge

图像生成

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-2OpenAI 图像生成/编辑模型

请在 模型广场 查看当前可用图像模型及定价。

图像生成

POST /v1/images/generations

根据文本提示词生成图片。

请求体

字段类型必填说明
modelstring图像模型 slug
promptstring图像描述提示词
ninteger生成张数,默认 1
sizestring尺寸,如 1024x1024
qualitystring质量,如 standardhd
response_formatstringurlb64_json,默认 url
stylestring风格,如 vividnatural(部分模型支持)

示例:

{
  "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)

字段类型必填说明
modelstring图像模型 slug
promptstring编辑描述提示词
imagefile参考图片(PNG,小于 4MB)
ninteger生成张数
sizestring输出尺寸,如 1024x1024
maskfile蒙版图片(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