SeedreamAISeedreamAI
📖 API Reference

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.

http
Authorization: Bearer sk-your-api-key-here
⚠️Keep your API Key secure. Do not expose it in client‑side code or public repositories. Each API Key is tied to your account and its credits balance.

🌐 Base URL

text
https://www.seedreams.app/api
POST/generate-image

Submit 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

NameTypeRequiredDefaultDescription
Content-TypestringRequiredapplication/jsonMust be application/json
AuthorizationstringRequiredBearer token. Format: Bearer sk-your-api-key

Request Body

NameTypeRequiredDefaultDescription
promptstringRequiredText prompt describing the image to generate. Max 1000 characters by default, 10000 for nano-banana-2, and 20000 for gpt-image-2.
modelstringOptionalgoogle/nano-banana-2The model to use for generation.
google/nano-banana-progoogle/nano-banana-2bytedance/seedream-v4bytedance/seedream-v4.5seedream/4.5-text-to-imageseedream/4.5-editseedream/5-lite-text-to-imageseedream/5-lite-image-to-imagebytedance/seedream-v5.0gpt-image-24o-Imagez-image
ratiostringOptional1:1Aspect ratio of the output image. Supported values vary by model. See the 'Model Capability Matrix' below for details.
1:14:33:44:55:416:99:163:22:321:9auto...
imagestring | string[]OptionalReference image URL(s) for image‑to‑image / editing tasks. Pass a single URL string or an array of URLs.
maxImagesnumberOptional4Number of images to generate (1–15). Multi-image generation is primarily supported by 'bytedance/seedream-v4'. Other models typically default to 1.
qualitystringOptionalOutput quality / resolution. Supports '1K/2K/4K' for Banana models and 'basic/high' for Seedream 4.5/5.0 models.
basichigh1K2K4K

Request Example

bash
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

json
{
  "code": 0,
  "message": "ok",
  "data": {
    "taskId": "task_abc123def456"
  }
}

Error Codes

-1
login_required
Missing or invalid API Key / authentication
-1
image_generation.error.empty_prompt
The prompt field is empty or missing
-1
image_generation.error.prompt_too_long
The prompt exceeds the maximum character limit
-1
my_credits.no_credits_description
Insufficient credits to process this request
-1
image_generation.error.generation_failed
The upstream generation service returned an error
-1
image_generation.error.unknown_error
An unexpected server error occurred

📊 Model Capability Matrix

Model CategorySupported RatiosMax ImagesQuality Options
Banana 21:1, 1:4, 1:8, 2:3, 3:2, 3:4, 4:1, 4:3, 4:5, 5:4, 8:1, 9:16, 16:9, 21:9, auto11K, 2K, 4K
Banana Pro1:1, 4:3, 3:4, 16:9, 9:16, 3:2, 2:3, 21:911K, 2K, 4K
Seedream v41:1, 4:3, 3:4, 16:9, 9:16, 3:2, 2:3, 21:91–15
Seedream 4.5 / 5.01:1, 4:3, 3:4, 16:9, 9:16, 3:2, 2:3, 21:91basic, high
GPT Image 2auto, 1:1, 5:4, 9:16, 21:9, 16:9, 4:3, 3:2, 4:5, 3:4, 2:31 (up to 16 refs)
4o-Image1:1, 3:2, 2:31
z-image1:1, 4:3, 3:4, 16:9, 9:161

Error Response Example

json
{
  "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 image field. 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, maxImages is ignored, image is 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:

javascript
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

python
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

NameTypeRequiredDefaultDescription
codenumberRequiredStatus code. 0 means success, -1 means error.
messagestringRequiredHuman-readable status message or error key.
dataobjectOptionalResponse payload. Only present on success.
💡Always check the 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