Image Generation API
Integrate powerful AI image generation into your applications. Supports multiple models including Seedream, Nano Banana, GPT Image 2, 4o‑Image, and more.
🔐 Authentication
All API requests must include a valid API Key in the Authorization header. API Keys are prefixed with sk- and can be generated from the API Keys management page.
Authorization: Bearer sk-your-api-key-here
🌐 Base URL
https://www.seedreams.app/api
/generate-imageSubmit an image generation task. The endpoint validates your credentials, checks credit balance, and dispatches the generation task asynchronously. A taskId is returned immediately, which you can use to poll the task status.
Request Headers
Request Body
Request Example
curl -X POST https://www.seedreams.app/api/generate-image \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-api-key" \
-d '{
"prompt": "A serene mountain landscape at sunset with vivid colors",
"model": "seedream/5-lite-text-to-image",
"ratio": "16:9",
"quality": "high"
}'Response
Success Response
{
"code": 0,
"message": "ok",
"data": {
"taskId": "task_abc123def456"
}
}Error Codes
📊 Model Capability Matrix
Error Response Example
{
"code": -1,
"message": "my_credits.no_credits_description"
}Model Notes
- Text‑to‑Image models — Generate images from a text prompt only. Models: google/nano-banana seedream/4.5-text-to-image seedream/5-lite-text-to-image gpt-image-2 z-image
- Image‑to‑Image / Edit models — Require one or more reference images via the
imagefield. Models: seedream/4.5-edit seedream/5-lite-image-to-image google/nano-banana-pro gpt-image-2 4o-Image - z-image — Always generates a single image,
maxImagesis ignored,imageis not supported. - GPT Image 2 — Supports both text-to-image and image-to-image. Each request costs 2 credits and accepts up to 16 reference image URLs in upstream mode.
- 4o‑Image — Only supports ratios: 1:1 3:2 2:3.
- Credits — Each generation request deducts credits from your account. The cost varies by model and quality setting. Pro/HD models cost more credits per generation.
🚀 Complete Workflow Example
Here's a complete JavaScript/Node.js example showing how to create an image generation task and poll for the result:
const API_BASE = "https://www.seedreams.app/api";
const API_KEY = "sk-your-api-key";
// Step 1: Create an image generation task
async function createImageTask() {
const response = await fetch(`${API_BASE}/generate-image`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`,
},
body: JSON.stringify({
prompt: "A futuristic city skyline at dusk, neon lights reflecting on water",
model: "seedream/5-lite-text-to-image",
ratio: "16:9",
quality: "high",
}),
});
const result = await response.json();
if (result.code !== 0) {
throw new Error(`Task creation failed: ${result.message}`);
}
return result.data.taskId;
}
// Step 2: Poll for task completion
async function pollTaskStatus(taskId, maxAttempts = 60, interval = 3000) {
for (let i = 0; i < maxAttempts; i++) {
const response = await fetch(
`${API_BASE}/generate-image?taskId=${taskId}`,
{ headers: { "Authorization": `Bearer ${API_KEY}` } }
);
const result = await response.json();
if (result.code !== 0) {
throw new Error(`Query failed: ${result.message}`);
}
const { status, resultUrl, errorCode } = result.data;
console.log(`[Attempt ${i + 1}] Status: ${status}`);
if (status === "completed" && resultUrl) {
return resultUrl;
}
if (status === "failed" || errorCode !== 0) {
throw new Error(`Generation failed with error code: ${errorCode}`);
}
await new Promise((r) => setTimeout(r, interval));
}
throw new Error("Polling timed out");
}
// Run the workflow
(async () => {
const taskId = await createImageTask();
console.log("Task created:", taskId);
const imageUrl = await pollTaskStatus(taskId);
console.log("Image ready:", imageUrl);
})();🐍 Python Example
import requests
import time
API_BASE = "https://www.seedreams.app/api"
API_KEY = "sk-your-api-key"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
}
# Step 1: Create task
resp = requests.post(f"{API_BASE}/generate-image", headers=headers, json={
"prompt": "A serene Japanese garden in autumn",
"model": "seedream/5-lite-text-to-image",
"ratio": "3:2",
"quality": "high",
})
data = resp.json()
assert data["code"] == 0, f"Error: {data['message']}"
task_id = data["data"]["taskId"]
print(f"Task created: {task_id}")
# Step 2: Poll status
for attempt in range(60):
resp = requests.get(
f"{API_BASE}/generate-image",
headers={"Authorization": f"Bearer {API_KEY}"},
params={"taskId": task_id},
)
result = resp.json()
assert result["code"] == 0, f"Query error: {result['message']}"
status = result["data"]["status"]
print(f"[Attempt {attempt + 1}] Status: {status}")
if status == "completed":
print(f"Image URL: {result['data']['resultUrl']}")
break
elif status == "failed":
raise Exception(f"Failed with error code: {result['data']['errorCode']}")
time.sleep(3)📋 Response Format
All API responses follow a consistent JSON envelope format:
Response Envelope
code field first. A value of 0 indicates a successful operation. Any negative value indicates an error — refer to the message field for the specific error key.Need help? Contact us at contact@seedreams.app
