Happy Pony API Get an API key →

Text to image

Pricing: Text to image

One prompt in, one image out. The same job as a generation on www.happypony.io/text-to-image.

POST https://api.happypony.io/api/v1/jobs/text-to-image
GET  https://api.happypony.io/api/v1/jobs/:requestId/status
GET  https://api.happypony.io/api/v1/jobs/:requestId
PUT  https://api.happypony.io/api/v1/jobs/:requestId/cancel

1) Create a request

POST https://api.happypony.io/api/v1/jobs/text-to-image with Content-Type: application/json.

Field Type Required Default Description
prompt string yes — What to draw.
aspect_ratio string no "1:1" "16:9", "4:3", "1:1", "3:4" or "9:16".
short_edge integer no 1080 1080, 1440 or 2048: the shorter side in pixels (16:9 at 1080 is 1920×1080, at 1440 2560×1440). An image is at most 2048×2048 pixels in all, so 2048 is 2048×2048 at 1:1, 2336×1760 at 4:3 and 2720×1536 at 16:9. With minimax-h3-image: 2048 (the default; the same sizes) or 4096, which is 16 megapixels: 4096×4096 at 1:1, 4736×3552 at 4:3, 5472×3072 at 16:9.
model string no "z-image-text-to-image" "z-image-text-to-image" or "minimax-h3-image" (MiniMax-H3-Image: finer detail and legible text, up to 16 megapixels; slower). A prompt under 400 characters is expanded into a detailed description before it is drawn, in either model.

Request body:

{
  "prompt": "A red fox in fresh snow at dawn, telephoto",
  "aspect_ratio": "16:9",
  "short_edge": 1080
}
curl -X POST https://api.happypony.io/api/v1/jobs/text-to-image \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"prompt": "A red fox in fresh snow at dawn, telephoto", "aspect_ratio": "16:9", "short_edge": 1080}'

Response 202 (fields: Create response):

{
  "request_id": "48213",
  "type": "text-to-image",
  "status": "IN_QUEUE",
  "credits": 4,
  "status_url": "https://api.happypony.io/api/v1/jobs/48213/status",
  "response_url": "https://api.happypony.io/api/v1/jobs/48213",
  "cancel_url": "https://api.happypony.io/api/v1/jobs/48213/cancel"
}

2) Poll for status

Poll the status_url until status is COMPLETED, FAILED or CANCELLED (fields: Status response). A queued job can be cancelled with PUT on the cancel_url (Cancel a request).

curl https://api.happypony.io/api/v1/jobs/48213/status -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48213",
  "type": "text-to-image",
  "status": "IN_PROGRESS",
  "created_at": "2026-10-05T10:00:00.000Z",
  "completed_at": null,
  "credits": 4,
  "eta_seconds": 12,
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}

3) Fetch the result

When status is COMPLETED, fetch the response_url (common fields: Result response):

curl https://api.happypony.io/api/v1/jobs/48213 -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48213",
  "type": "text-to-image",
  "status": "COMPLETED",
  "created_at": "2026-10-05T10:00:00.000Z",
  "completed_at": "2026-10-05T10:00:31.000Z",
  "credits": 4,
  "images": [{ "url": "https://…signed…", "format": "png" }],
  "expires_in": 259200,
  "parameters": { "prompt": "A red fox in fresh snow at dawn, telephoto", "model": "z-image-text-to-image",
                  "aspect_ratio": "16:9", "short_edge": 1080 },
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}
Field Type Description
images object[] One image.
parameters object prompt, model, aspect_ratio, short_edge.

Full example

Create, poll until done, download:

curl (bash)

# Needs curl and jq. Usage: HP_KEY=hp_… ./t2i.sh
JOB=$(curl -s -X POST https://api.happypony.io/api/v1/jobs/text-to-image \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"prompt": "A red fox in fresh snow at dawn, telephoto", "aspect_ratio": "16:9", "short_edge": 1080}')
STATUS_URL=$(echo "$JOB" | jq -r .status_url)
RESPONSE_URL=$(echo "$JOB" | jq -r .response_url)

while :; do
  STATUS=$(curl -s "$STATUS_URL" -H "Authorization: Bearer $HP_KEY" | jq -r .status)
  [ "$STATUS" = IN_QUEUE ] || [ "$STATUS" = IN_PROGRESS ] || break
  sleep 5
done
echo "$STATUS"
curl -s "$RESPONSE_URL" -H "Authorization: Bearer $HP_KEY" | jq -r '.images[] | "\(.format) \(.url)"' |
  while read -r FORMAT URL; do curl -s -o "image-$((++i)).$FORMAT" "$URL"; done

Python

# pip install requests   |   HP_KEY=hp_… python t2i.py
import os, time, requests

BASE = "https://api.happypony.io/api/v1/jobs"
H = {"Authorization": f"Bearer {os.environ['HP_KEY']}"}

job = requests.post(f"{BASE}/text-to-image", headers=H, json={
    "prompt": "A red fox in fresh snow at dawn, telephoto",
    "aspect_ratio": "16:9",
    "short_edge": 1080,
}).json()
print("job", job["request_id"], "costs", job["credits"], "credits")

while (s := requests.get(job["status_url"], headers=H).json())["status"] in ("IN_QUEUE", "IN_PROGRESS"):
    time.sleep(5)

result = requests.get(job["response_url"], headers=H).json()
if result["status"] != "COMPLETED":
    raise SystemExit(f"{result['status']}: {result.get('error', '')}")
for i, image in enumerate(result["images"]):
    with open(f"image-{job['request_id']}-{i}.{image['format']}", "wb") as f:
        f.write(requests.get(image["url"]).content)

TypeScript

// Node 18+ (global fetch).   HP_KEY=hp_… npx tsx t2i.ts
import { writeFile } from 'node:fs/promises';

const BASE = 'https://api.happypony.io/api/v1/jobs';
const H = { Authorization: `Bearer ${process.env.HP_KEY}`, 'Content-Type': 'application/json' };

const job = await (await fetch(`${BASE}/text-to-image`, {
  method: 'POST', headers: H,
  body: JSON.stringify({ prompt: 'A red fox in fresh snow at dawn, telephoto', aspect_ratio: '16:9', short_edge: 1080 }),
})).json();

let status = 'IN_QUEUE';
while (status === 'IN_QUEUE' || status === 'IN_PROGRESS') {
  await new Promise((r) => setTimeout(r, 5000));
  status = (await (await fetch(job.status_url, { headers: H })).json()).status;
}
const result = await (await fetch(job.response_url, { headers: H })).json();
if (result.status !== 'COMPLETED') throw new Error(`${result.status}: ${result.error ?? ''}`);
for (const [i, image] of result.images.entries()) {
  await writeFile(`image-${job.request_id}-${i}.${image.format}`, Buffer.from(await (await fetch(image.url)).arrayBuffer()));
}

文生图

价格:文生图

一条提示词生成一张图片。与在 www.happypony.io/text-to-image 上生成的任务完全相同。

POST https://api.happypony.io/api/v1/jobs/text-to-image
GET  https://api.happypony.io/api/v1/jobs/:requestId/status
GET  https://api.happypony.io/api/v1/jobs/:requestId
PUT  https://api.happypony.io/api/v1/jobs/:requestId/cancel

1) 创建请求

POST https://api.happypony.io/api/v1/jobs/text-to-image,Content-Type: application/json。

字段 类型 必填 默认值 说明
prompt string 是 — 要画的内容。
aspect_ratio string 否 "1:1" "16:9"、"4:3"、"1:1"、"3:4" 或 "9:16"。
short_edge integer 否 1080 1080、1440 或 2048:短边像素数(16:9 配 1080 即 1920×1080,配 1440 即 2560×1440)。单张图片总像素不超过 2048×2048,因此 2048 在 1:1 下为 2048×2048,4:3 下为 2336×1760,16:9 下为 2720×1536。使用 minimax-h3-image 时:2048(默认,尺寸同上)或 4096,即 1600 万像素:1:1 下为 4096×4096,4:3 下为 4736×3552,16:9 下为 5472×3072。
model string 否 "z-image-text-to-image" "z-image-text-to-image" 或 "minimax-h3-image"(MiniMax-H3-Image:细节更精细、文字清晰可读,最高 1600 万像素;速度较慢)。两个模型都会先把少于 400 个字符的提示词扩写成详细描述再绘制。

请求体:

{
  "prompt": "A red fox in fresh snow at dawn, telephoto",
  "aspect_ratio": "16:9",
  "short_edge": 1080
}
curl -X POST https://api.happypony.io/api/v1/jobs/text-to-image \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"prompt": "A red fox in fresh snow at dawn, telephoto", "aspect_ratio": "16:9", "short_edge": 1080}'

响应 202(字段见创建响应):

{
  "request_id": "48213",
  "type": "text-to-image",
  "status": "IN_QUEUE",
  "credits": 4,
  "status_url": "https://api.happypony.io/api/v1/jobs/48213/status",
  "response_url": "https://api.happypony.io/api/v1/jobs/48213",
  "cancel_url": "https://api.happypony.io/api/v1/jobs/48213/cancel"
}

2) 轮询状态

轮询 status_url,直到 status 变为 COMPLETED、FAILED 或 CANCELLED(字段见状态响应)。排队中的任务可以向 cancel_url 发送 PUT 取消(见取消请求)。

curl https://api.happypony.io/api/v1/jobs/48213/status -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48213",
  "type": "text-to-image",
  "status": "IN_PROGRESS",
  "created_at": "2026-10-05T10:00:00.000Z",
  "completed_at": null,
  "credits": 4,
  "eta_seconds": 12,
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}

3) 获取结果

status 为 COMPLETED 后,获取 response_url(通用字段见结果响应):

curl https://api.happypony.io/api/v1/jobs/48213 -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48213",
  "type": "text-to-image",
  "status": "COMPLETED",
  "created_at": "2026-10-05T10:00:00.000Z",
  "completed_at": "2026-10-05T10:00:31.000Z",
  "credits": 4,
  "images": [{ "url": "https://…signed…", "format": "png" }],
  "expires_in": 259200,
  "parameters": { "prompt": "A red fox in fresh snow at dawn, telephoto", "model": "z-image-text-to-image",
                  "aspect_ratio": "16:9", "short_edge": 1080 },
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}
字段 类型 说明
images object[] 一张图片。
parameters object prompt、model、aspect_ratio、short_edge。

完整示例

创建、轮询直到完成、下载:

curl (bash)

# Needs curl and jq. Usage: HP_KEY=hp_… ./t2i.sh
JOB=$(curl -s -X POST https://api.happypony.io/api/v1/jobs/text-to-image \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"prompt": "A red fox in fresh snow at dawn, telephoto", "aspect_ratio": "16:9", "short_edge": 1080}')
STATUS_URL=$(echo "$JOB" | jq -r .status_url)
RESPONSE_URL=$(echo "$JOB" | jq -r .response_url)

while :; do
  STATUS=$(curl -s "$STATUS_URL" -H "Authorization: Bearer $HP_KEY" | jq -r .status)
  [ "$STATUS" = IN_QUEUE ] || [ "$STATUS" = IN_PROGRESS ] || break
  sleep 5
done
echo "$STATUS"
curl -s "$RESPONSE_URL" -H "Authorization: Bearer $HP_KEY" | jq -r '.images[] | "\(.format) \(.url)"' |
  while read -r FORMAT URL; do curl -s -o "image-$((++i)).$FORMAT" "$URL"; done

Python

# pip install requests   |   HP_KEY=hp_… python t2i.py
import os, time, requests

BASE = "https://api.happypony.io/api/v1/jobs"
H = {"Authorization": f"Bearer {os.environ['HP_KEY']}"}

job = requests.post(f"{BASE}/text-to-image", headers=H, json={
    "prompt": "A red fox in fresh snow at dawn, telephoto",
    "aspect_ratio": "16:9",
    "short_edge": 1080,
}).json()
print("job", job["request_id"], "costs", job["credits"], "credits")

while (s := requests.get(job["status_url"], headers=H).json())["status"] in ("IN_QUEUE", "IN_PROGRESS"):
    time.sleep(5)

result = requests.get(job["response_url"], headers=H).json()
if result["status"] != "COMPLETED":
    raise SystemExit(f"{result['status']}: {result.get('error', '')}")
for i, image in enumerate(result["images"]):
    with open(f"image-{job['request_id']}-{i}.{image['format']}", "wb") as f:
        f.write(requests.get(image["url"]).content)

TypeScript

// Node 18+ (global fetch).   HP_KEY=hp_… npx tsx t2i.ts
import { writeFile } from 'node:fs/promises';

const BASE = 'https://api.happypony.io/api/v1/jobs';
const H = { Authorization: `Bearer ${process.env.HP_KEY}`, 'Content-Type': 'application/json' };

const job = await (await fetch(`${BASE}/text-to-image`, {
  method: 'POST', headers: H,
  body: JSON.stringify({ prompt: 'A red fox in fresh snow at dawn, telephoto', aspect_ratio: '16:9', short_edge: 1080 }),
})).json();

let status = 'IN_QUEUE';
while (status === 'IN_QUEUE' || status === 'IN_PROGRESS') {
  await new Promise((r) => setTimeout(r, 5000));
  status = (await (await fetch(job.status_url, { headers: H })).json()).status;
}
const result = await (await fetch(job.response_url, { headers: H })).json();
if (result.status !== 'COMPLETED') throw new Error(`${result.status}: ${result.error ?? ''}`);
for (const [i, image] of result.images.entries()) {
  await writeFile(`image-${job.request_id}-${i}.${image.format}`, Buffer.from(await (await fetch(image.url)).arrayBuffer()));
}