Generate images

Submit an image task and get a task_id right away. Text-to-image and image-to-image share this endpoint — pass image_urls for image-to-image.

POSThttps://api.jiufeng.ai/v1/images/generations
4 differences from the OpenAI API
  1. size is an aspect ratio (e.g. 2:3), not pixels; values like 1024x1024 are rejected
  2. Resolution goes in resolution (1K / 2K / 4K)
  3. Reference images go in image_urls — no separate edit endpoint
  4. Asynchronous: submitting returns a task_id, not the image

Got a task_id? Poll Query tasks for the result, or wait for a Webhook callback.

Models

modelBest forPrice (credits / image)
gpt-image-2Posters, infographics, charts, comics — legible text in many languages; cheapest per image1K / 2K / 4K: 0.08 / 0.142 / 0.208
gpt-image-2.5-extGPT Image 2.5: photoreal product shots and portraits; edits from a reference photo1K / 2K / 4K: 0.212 / 0.28 / 0.38

GPT Image 2.5 comes in two versions, picked with version: flare (the default) and sunburst (detail that holds up when zoomed in). Both cost the same. Total = per-image price × n; the price depends only on the model, resolution and image count — size and quality don't change it. Full list: Pricing.

Request parameters

promptstringrequired
The prompt.
modelstringoptionaldefault gpt-image-2
Must match the model name exactly. GET /v1/models lists the models your key can use.
gpt-image-2gpt-image-2.5-ext
sizestringoptional
Aspect ratio, not pixels; 1024x1024 is rejected. Send it explicitly for predictable output.
gpt-image-2auto1:13:22:34:33:45:44:516:99:162:11:23:11:321:99:21gpt-image-2.5-ext (default auto)auto1:116:99:164:33:43:22:35:44:521:9
resolutionstringoptional2.5 defaults to 1K
Resolution; affects the price. Send it explicitly.
1K2K4K
versionstringoptionaldefault flare
gpt-image-2.5-ext only. Same price; any other value is rejected.
flaresunburst
nintegeroptionaldefault 1
Number of images, billed per image. gpt-image-2.5-ext accepts 1–4.
image_urlsstring[]optional
Reference / source images, up to 15, as public https:// URLs.
qualitystringoptional
Optional — the Jiufeng web app leaves it out. Doesn't affect the price.
autolowmediumhigh
webhookstringoptional
Callback base URL; on terminal states the platform POSTs to <webhook>/callback. See Webhooks.
languagestringoptional
Language of error messages.
zhenkoja

Full example: submit and wait

Cap the wait and back off between polls. Result files are kept for 30 days — copy them before they expire.

# 1. Submit and note the task_id
curl https://api.jiufeng.ai/v1/images/generations \
  -H "Authorization: Bearer $JF_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-image-2", "prompt": "A Shiba Inu running through a neon cyberpunk city", "size": "16:9", "resolution": "1K"}'
 
# 2. Poll every few seconds until status is completed or failed
curl https://api.jiufeng.ai/v1/tasks/$TASK_ID \
  -H "Authorization: Bearer $JF_KEY"
import time
import requests
 
API = "https://api.jiufeng.ai/v1"
HEADERS = {"Authorization": "Bearer sk-YOUR_KEY"}
 
resp = requests.post(f"{API}/images/generations", headers=HEADERS, json={
    "model": "gpt-image-2.5-ext",
    "version": "sunburst",
    "prompt": "A Shiba Inu running through a neon cyberpunk city",
    "size": "16:9",
    "resolution": "1K",
})
resp.raise_for_status()
task_id = resp.json()["data"][0]["task_id"]
 
delay = 1
deadline = time.time() + 300   # cap the wait
while time.time() < deadline:
    task = requests.get(f"{API}/tasks/{task_id}", headers=HEADERS).json()["data"]
    if task["status"] == "completed":
        urls = [u for item in task["result"]["images"] for u in item["url"]]
        print(urls)          # download within 30 days
        break
    if task["status"] == "failed":
        raise RuntimeError(task["error"]["message"])
    time.sleep(delay)
    delay = min(delay * 2, 8)
else:
    raise TimeoutError(task_id)
const API = "https://api.jiufeng.ai/v1";
const headers = {
  Authorization: "Bearer sk-YOUR_KEY",
  "Content-Type": "application/json",
};
 
const submit = await fetch(`${API}/images/generations`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    model: "gpt-image-2",
    prompt: "A Shiba Inu running through a neon cyberpunk city",
    size: "16:9",
    resolution: "1K",
  }),
}).then((r) => r.json());
const taskId = submit.data[0].task_id;
 
const deadline = Date.now() + 300_000; // cap the wait
for (let delay = 1000; ; delay = Math.min(delay * 2, 8000)) {
  if (Date.now() > deadline) throw new Error(`timeout ${taskId}`);
  const { data: task } = await fetch(`${API}/tasks/${taskId}`, { headers }).then((r) => r.json());
  if (task.status === "completed") {
    console.log(task.result.images.flatMap((i) => i.url)); // download within 30 days
    break;
  }
  if (task.status === "failed") throw new Error(task.error.message);
  await new Promise((r) => setTimeout(r, delay));
}

Response fields

Submitting returns a task_id. Once generation finishes, Query tasks returns the result under data.result.images:

FieldMeaning
data.statuspending → processing → completed or failed
data.result.images[].urlArray of image URLs; the first is images[0].url[0], all of them images.flatMap(i => i.url)
data.result.images[].expires_atExpiry time (Unix seconds); result files are kept for 30 days
data.credits_costCredits actually charged for this task
data.errorPresent on failure: { message, type, param, code }

Common errors

HTTPWhenWhat to do
400Invalid parameters; or model misspelled / not enabled for your key (model_not_available)Update the request as the error message says; GET /v1/models lists usable models
401Missing key (missing_api_key) or invalid keyCheck Authorization: Bearer sk-…
402Insufficient credits, key quota exhausted, or key expiredTop up, raise the cap, or create a new key
429Rate limitedBack off per the Retry-After header and retry

Full list: Errors.

Generate images · Jiufeng Open API