OpenAI
OpenAI Image Generation
Creates an image given a prompt. Returns a URL or base64-encoded JSON of the generated image(s).
POST
v1/images/generationsAuthorizations
Authorizationstringheaderrequired
Use the following format for authentication: Bearer sk-pat-您的AccessToken
密钥的值使用HAI Gateway的个人访问令牌(以 sk-pat- 开头),无需在OpenAI处单独申请 API Key。
Base URL
Body 参数
modelstringbodyrequired
图像模型,如 gpt-image-2
promptstringbodyrequired
图像的文字描述
nintegerbody
生成张数,默认 1
sizestringbody
1024x1024 / 1536x1024 / 1024x1536 / auto
qualitystringbody
low / medium / high / auto
backgroundstringbody
背景模式:transparent / opaque / auto,默认 auto,仅 GPT image 系列
output_formatstringbody
图像编码格式:png / jpeg / webp,默认 png,仅 GPT image 系列
output_compressionintegerbody
JPEG / WebP 压缩等级(0 – 100),默认 100,仅 output_format 为 jpeg / webp 时生效
response_formatstringbody
url / b64_json,仅 DALL-E 系列;GPT image 系列固定返回 base64
moderationstringbody
内容过滤:auto / low,仅 GPT image 系列
streambooleanbody
是否启用流式返回(增量图像),默认 false,仅 GPT image 系列
完整参数说明请参考 OpenAI 官方文档。
cURL
curl https://api.hai.network/openai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-pat-您的Access Token" \
-d '{
"model": "gpt-image-2",
"prompt": "A children'\''s book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter.",
"n": 1,
"size": "1024x1024",
"quality": "high"
}'200
{
"created": 1713833628,
"data": [
{
"b64_json": "..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}