使用我们强大的 AI 模型将您的创意转化为精美图像和视频
测试并探索支持多种模型和输出格式的图像生成 API
fetch('https://api.imagegpt.online/generate/text-image', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
},
body: JSON.stringify({
"prompt": "Photorealistic portrait of the same person (keep his real face unchanged). A man with medium curly brown hair, light skin, and soft features sits relaxed, forearms on a light blue table, holding a small white puppy with a red collar. He wears a cozy color-block knitted sweater (beige, tan, light blue, black) with ribbed neck and cuffs, a silver watch, and a turquoise-beaded bracelet. Soft diffused lighting, smooth steel-blue background, slightly elevated front angle warm, intimate, digital photo",
"width": 512,
"height": 512,
"model": "FLUX-SCHNELL",
"outputType": "binary",
"outputFormat": "png"
})
})
.then(response => response.blob())
.then(blob => {
const imageUrl = URL.createObjectURL(blob);
console.log('Image URL:', imageUrl);
// Display in img tag: document.getElementById('myImg').src = imageUrl;
})
.catch(error => console.error('Error:', error));使用15+个AI模型的统一REST API — 支持文生图和图生图,多种输出格式,积分定价。
https://api.imagegpt.online/generate/text-image所有请求必须在请求头中包含API密钥。请保密您的API密钥。
x-api-key: YOUR_API_KEY缺失或无效的API密钥返回 401 Unauthorized 响应。
发送包含以下字段的JSON请求体:
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model* | string | — | 用于生成的模型ID。 |
prompt* | string | — | 想要生成的图像的文本描述。 |
width | number | 512 | 输出图像宽度(像素)。 |
height | number | 512 | 输出图像高度(像素)。 |
outputType | string | "binary" | 输出格式:"binary"、"url"或"base64"。 |
outputFormat | string | "png" | 图像文件格式:"png"或"jpg"。 |
image | string[] | — | 输入图像URL数组(最多3个)。仅图生图时必填。 |
* 必填字段。
响应形状取决于您选择的 outputType :
outputType: "binary"
const blob = await response.blob();
const url = URL.createObjectURL(blob);outputType: "url"
{
"success": true,
"taskId": "imagegpt_img-...",
"url": "https://...",
"creditsDeducted": 3
}outputType: "base64"
{
"success": true,
"taskId": "imagegpt_img-...",
"base64": "/9j/4QWm...",
"creditsDeducted": 3
}使用fetch API的最小文生图请求:
fetch('https://api.imagegpt.online/generate/text-image', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY'
},
body: JSON.stringify({
model: 'FLUX-SCHNELL',
prompt: 'A futuristic city at sunset, photorealistic',
width: 512,
height: 512,
outputType: 'url',
outputFormat: 'png'
})
})
.then(res => res.json())
.then(data => console.log('Image URL:', data.url));对于图生图,添加 image 数组:
body: JSON.stringify({
model: 'FLUX-KONTEXT',
prompt: 'Same person, wearing a red jacket',
image: ['https://example.com/input.jpg'],
width: 512,
height: 512,
outputType: 'url',
outputFormat: 'png'
})积分按每张生成的图像收费:
适合草稿的快速轻量模型。
e.g. Flux Schnell, Z Image Turbo
日常生成任务的均衡品质。
e.g. GPT Image 1.0, Seedream, Nova Canvas
生产级输出的最高保真度。
e.g. Nano Banana Pro, Seedream 4.0, Ideogram
ImageGPT 禁止 NSFW、色情、成人、剥削性、欺骗性或有害的 AI 生成内容。内容审核适用于受支持的图像和视频生成。