Quickstart
Create an API key, send your first image-generation request and retrieve the result.
This guide walks you through creating an API key, submitting an image-generation task and retrieving the result. Image, video and audio generation share the same media-task request structure: a model and its input. File uploads and webhook delivery are covered separately.
Before you start
- A PopNow account. Sign up at popnow.ai. API calls spend your PopNow balance, shown in USD; a new account starts at $0. Add funds in API billing before your first paid call.
- A terminal with
curl. The examples use bash. On Windows, use WSL or Git Bash.
1. Create an API key
Open the API console and choose Create key. Copy the key straight away: the full value is shown only once. Store it in an environment variable rather than hardcoding it:
export POPNOW_API_KEY="sk-popnow-..."Every key starts with sk-popnow-. Requests made with it use your API USD balance. Keep the key on your server; Authentication explains restrictions, rotation and what to do if a key leaks.
2. Send a task
Paste this into the same terminal. It asks a fast image model for one picture and costs about $0.01 USD (one US cent):
export POPNOW_API_KEY="sk-popnow-..." # your key from the API console
curl -X POST "https://api.popnow.ai/api/v1/jobs/createTask?wait=60" \
-H "Authorization: Bearer $POPNOW_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"model": "alibaba/z-image-turbo/text-to-image",
"input": {
"prompt": "A small red fox curled up in a teacup, soft morning light, studio photo"
}
}'What each part does:
modelidentifies the model and the task it performs. Find the available IDs on Models.inputis checked against that model's own input schema. Unknown fields are rejected, so typos fail fast instead of being ignored.Idempotency-Keymakes a retry safe: send the same key again after a timeout and you get the original task back instead of a second charge. See Idempotency.?wait=60keeps the connection open for up to 60 seconds. If the task finishes within that time, its result can return in the same response.
3. Read the result
A finished task looks like this:
{
"code": 200,
"msg": "success",
"data": {
"taskId": "job_01JH8Z4Q5W2N7R3K9M6P1C0VXD",
"model": "alibaba/z-image-turbo/text-to-image",
"state": "succeeded",
"output": {
"assets": [
{
"url": "https://…signed-link…",
"expiresAt": "2026-10-16T09:20:00Z",
"mime": "image/png",
"width": 1024,
"height": 1024
}
]
},
"costUsd": "0.01",
"settled": true
},
"request_id": "req_…"
}
stateissucceeded. A task that could not finish saysfailedand carries anerrorCode; see Errors.output.assets[0].urlis a signed link to the file. It works for about 20 minutes and needs no API key. Read the task again to request a fresh link.costUsdis the USD decimal string to use for the amount: the final charge whensettledistrue, or the hold whilesettledisfalse. Older integer amount fields may still appear for compatibility; ignore them.
If the task takes more than 60 seconds, the response is a 202 with state: "queued" and a taskId instead. Poll the task until it reaches a final state:
curl "https://api.popnow.ai/api/v1/jobs/recordInfo?taskId=job_..." \
-H "Authorization: Bearer $POPNOW_API_KEY"Check every few seconds until state is succeeded, failed or expired. In production, pass a callBackUrl and let a webhook tell you instead.
The same request in code
const API = 'https://api.popnow.ai/api/v1';
const headers = {
Authorization: `Bearer ${process.env.POPNOW_API_KEY}`,
'Content-Type': 'application/json',
};
const created = await fetch(`${API}/jobs/createTask`, {
method: 'POST',
headers: { ...headers, 'Idempotency-Key': crypto.randomUUID() },
body: JSON.stringify({
model: 'alibaba/z-image-turbo/text-to-image',
input: { prompt: 'A small red fox curled up in a teacup, soft morning light' },
}),
}).then((r) => r.json());
if (created.code !== 200) throw new Error(`${created.code} ${created.msg}`);
// Poll until the task reaches a final state.
let task;
do {
await new Promise((r) => setTimeout(r, 3000));
const res = await fetch(`${API}/jobs/recordInfo?taskId=${created.data.taskId}`, { headers });
task = (await res.json()).data;
} while (task.state === 'queued' || task.state === 'running');
console.log(task.state, task.output?.assets?.[0]?.url);import os, time, uuid, requests
API = "https://api.popnow.ai/api/v1"
headers = {"Authorization": f"Bearer {os.environ['POPNOW_API_KEY']}"}
created = requests.post(
f"{API}/jobs/createTask",
headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
json={
"model": "alibaba/z-image-turbo/text-to-image",
"input": {"prompt": "A small red fox curled up in a teacup, soft morning light"},
},
timeout=30,
).json()
if created["code"] != 200:
raise RuntimeError(f'{created["code"]} {created["msg"]}')
# Poll until the task reaches a final state.
while True:
time.sleep(3)
task = requests.get(
f"{API}/jobs/recordInfo",
headers=headers,
params={"taskId": created["data"]["taskId"]},
timeout=30,
).json()["data"]
if task["state"] not in ("queued", "running"):
break
print(task["state"], task.get("output", {}).get("assets", [{}])[0].get("url"))With the official SDKs. The Python and JavaScript SDKs send the idempotency key and poll for you. Install them from PyPI and npm:
pip install popnownpm install popnowfrom popnow import PopNow
client = PopNow() # reads POPNOW_API_KEY
task = client.images.generate(
model="alibaba/z-image-turbo/text-to-image",
prompt="A small red fox curled up in a teacup, soft morning light",
)
print(task.state, task.urls[0])import { PopNow } from 'popnow';
const popnow = new PopNow(); // reads POPNOW_API_KEY
const task = await popnow.jobs.createAndWait({
model: 'alibaba/z-image-turbo/text-to-image',
input: { prompt: 'A small red fox curled up in a teacup, soft morning light' },
});
console.log(task.state, task.output?.assets?.[0]?.url);The response envelope
Every JSON response has the same four fields:
{ "code": 200, "msg": "success", "data": { }, "request_id": "req_…" }code is a business code, not an HTTP status: 200 means success, anything else is an error listed on Errors. Branch on code, never on the wording of msg. Quote request_id when you contact support.

