Overview
Streaming Image API
Call any route below directly. The API returns an SSE stream.
Method
POSTPath
/v1/responsesAuth
Authorization: Bearer sk-your-keyAccept
text/event-streamDirect Responses streaming image generation.
Text to Image
Text to Image: curl Example
curl --location 'https://cdn.aiswing.fun/v1/responses' \
--header 'Authorization: Bearer sk-your-key' \
--header 'Content-Type: application/json' \
--header 'Accept: text/event-stream' \
--data '{
"model": "gpt-image-2",
"input": [{
"role": "user",
"content": [{
"type": "input_text",
"text": "A premium product poster, clean studio lighting, no text, no watermark"
}]
}],
"tools": [{
"type": "image_generation",
"size": "3840x2160",
"quality": "high",
"output_format": "png"
}],
"stream": true
}'
Use 3840x2160 for 4K landscape and 2160x3840 for 4K portrait.
Image to Image
Image to Image: With Reference Images
curl --location 'https://cdn.aiswing.fun/v1/responses' \
--header 'Authorization: Bearer sk-your-key' \
--header 'Content-Type: application/json' \
--header 'Accept: text/event-stream' \
--data '{
"model": "gpt-image-2",
"input": [{
"role": "user",
"content": [
{"type": "input_image", "image_url": "data:image/png;base64,iVBORw0KGgoAAA..."},
{"type": "input_text", "text": "Keep the same subject, turn it into a cinematic product poster"}
]
}],
"tools": [{
"type": "image_generation",
"size": "3840x2160",
"quality": "high",
"output_format": "png"
}],
"stream": true
}'
Use data:image/png;base64,... for reference images.
Three Routes
cdn
https://cdn.aiswing.fun/v1/responsesDefault recommended routegpt
https://gpt.aiswing.fun/v1/responsesBackup routecodex
https://codex.aiswing.fun/v1/responsesBackup routeRequest Parameters
modelModelRecommended: gpt-image-2.
promptPromptRequired. Describe subject, style, composition, lighting, colors, and unwanted text or watermark.
sizeResolutionSupports common sizes, 4K sizes, and auto.
qualityQualityOptional: auto, low, medium, high.
formatOutput FormatOptional: png, jpeg, webp.
reference_imagesReference ImagesOptional array for image-to-image.
SSE Streaming Events
response.image_generation_call.partial_imagePreview imageRead partial_image_b64.
response.completedFinal imageUsually in response.output[].result.
[DONE]DoneSSE stream termination marker.
JavaScript Streaming Example
const endpoint = "https://cdn.aiswing.fun/v1/responses";
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Authorization": "Bearer sk-your-key",
"Content-Type": "application/json",
"Accept": "text/event-stream"
},
body: JSON.stringify({
model: "gpt-image-2",
input: [{
role: "user",
content: [{ type: "input_text", text: "4K product poster, clean studio lighting" }]
}],
tools: [{
type: "image_generation",
size: "3840x2160",
quality: "high",
output_format: "png"
}],
stream: true
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const chunks = buffer.split("\n\n");
buffer = chunks.pop() || "";
for (const chunk of chunks) {
const line = chunk.split("\n").find((x) => x.startsWith("data:"));
if (!line) continue;
const raw = line.slice(5).trim();
if (raw === "[DONE]") break;
const event = JSON.parse(raw);
const b64 = event.b64_json || event.partial_image_b64 || event.response?.output?.find?.((x) => x.result)?.result;
if (b64) document.querySelector("img").src = `data:image/png;base64,${b64}`;
}
}