Happy Pony API Get an API key →

Human portrait

Pricing: Human portrait

No input image: describe a person by attributes (gender, age, nationality, body, face, hair, makeup, framing) and get photorealistic portraits of a new, made-up person: one to four per job on Qwen-Image 2.1, or one on MiniMax-H3-Image, which also renders 4K. The same job as a generation on www.happypony.io/human-portrait.

POST https://api.happypony.io/api/v1/jobs/human-portrait
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/human-portrait with Content-Type: application/json. Every field is optional; {} is a valid request.

Field Type Required Default Description
gender, age, shot, nationality_1, … string no left to the model Character attributes; the values each one takes are listed in Character values. age may also be a number.
shot_weight number no 1.3 when shot is set How strongly shot is held: 1 (subtle), 1.3, 1.5 (strong), 1.8 (very strong). Only with shot.
prompt_prefix string no none Free text added to the prompt right after the subject (setting, clothing, light, style). Up to 1000 characters. Without it the portrait is shot in soft studio light on a neutral background.
short_edge integer no 1080 Size of each image: 1080, 1440, 2048 (2K) or 4096 (4K). Pick it first: it decides which model values are allowed. At 2048 the image is 4 MP (2048x2048 at 1:1, 2720x1536 at 16:9); at 4096 it is 16 MP (4096x4096 at 1:1, 5472x3072 at 16:9).
model string no "z-image-text-to-image", or "minimax-h3-image" when short_edge is 4096 The engine. "z-image-text-to-image" (Qwen-Image 2.1) renders short_edge 1080 to 2048; "minimax-h3-image" (MiniMax-H3-Image) renders 1080 to 4096. Any other combination is a 400.
aspect_ratio string no "9:16" "16:9", "4:3", "1:1", "3:4", "9:16".
num_images integer no 1 Different portraits from the same attributes: 1 to 4 with "z-image-text-to-image", exactly 1 with "minimax-h3-image".

An attribute you leave out is decided by the model; it is not randomised. For variety across requests, pick the values yourself. nationality_2 blends a second nationality into the first, and beard applies to masculine subjects. The values must be spelled exactly as listed (they are case-sensitive); anything else is a 400.

Character values

Field Values
gender Woman, Man
age 18, 20, 24, 28, 32, 36, 40, 44, 50, 56, 62, 70, 80
shot Head portrait, Head and shoulders portrait, Half-length portrait, Portrait, Full-length portrait, Full body, Close-up
nationality_1, nationality_2 see the list below
body_type Slim, Slight, Petite, Fit, Curvy, Voluptuous, Thick, Muscular, Buxom, Chubby, Plump, Stocky, Tall, Short
breast_size flat, small, medium, large, huge
butt_size small, medium, large, athletic
skin_tone fair, medium, dark, olive, tan, bronzed, golden, porcelain, alabaster, ebony, chocolate, caramel, honey, peach, ivory, rose, sand
skin_texture smooth, normal, dry, oily, combination, poreless, fine-textured, freckled, mole-covered, wrinkled, mature, youthful, dewy, matte, glowing, radiant
face_shape Oval, Round, Square, Heart, Diamond, Oblong, Long, Triangle, Inverted Triangle, Pear, Rectangle
jawline defined, soft, rounded, square, angular, sharp, delicate, strong, wide, narrow
eyes_color Amber, Blue, Brown, Green, Gray, Hazel, Violet, Heterochromia
eyes_shape Almond Eyes Shape, Asian Eyes Shape, Close-Set Eyes Shape, Deep Set Eyes Shape, Downturned Eyes Shape, Double Eyelid Eyes Shape, Hooded Eyes Shape, Monolid Eyes Shape, Oval Eyes Shape, Round Eyes Shape, Upturned Eyes Shape
nose_shape straight, aquiline, roman, button, upturned, broad, narrow, small, large, sharp, rounded, angular, delicate, defined
nose_size small, medium, large, wide, narrow, prominent, subtle, delicate
hair_color Auburn, Black, Jet Black, Blonde, Strawberry, Chestnut, Chocolate, Caramel, Copper, Gray, Honey, Mahogany, Platinum, Red, Silver, White, Burgundy, Multicolored, Pastel
hair_style Afro, Bald, Bangs, Bob, Blunt bob, Braided, Box braids, Bun, Top Knot, Buzz, Cornrows, Curly, Curly bob, Dreadlocks, Faux hawk, Layered, Long straight, Long ponytail, High ponytail, Mohawk, Pixie, Pompadour, Quiff, Shag, Short, Short curly, Side braid, Spiky, Undercut, Updo, Very long wave, Wavy, Wavy bob
hair_length Short, Medium, Long
beard Stubble Beard, Goatee, Full Beard, Van Dyke Beard, Soul Patch, Garibaldi Beard, Circle Beard, Corporate Beard, Balbo Beard, Ducktail Beard, Chinstrap Beard, Anchor Beard, Chevron Mustache, Horseshoe Mustache, Handlebar Mustache, Imperial Mustache, Pencil Mustache, Zappa Mustache
makeup Natural Makeup, Glam Makeup, Glowy Makeup, Dewy Makeup, Classic Makeup, Cut Crease Makeup, Edgy Makeup, Festival Makeup, Golden Makeup, Monochromatic Makeup, Party Makeup, Retro Makeup, Smokey Eye Makeup, Sunset Eye Makeup, Vintage Makeup, Watercolor Makeup, Anime Makeup, Artistic Makeup, Avant-garde Makeup, Bohemian Makeup
makeup_color Red, Pink, Coral, Peach, Mauve, Burgundy, Plum, Purple, Brown, Copper, Gold, Silver, Black, Wine, Raspberry, Orange, Nude, Berry

Nationalities (nationality_1, nationality_2): Afghan, Albanian, Algerian, American, Andorran, Angolan, Argentine, Armenian, Australian, Austrian, Azerbaijani, Bahamian, Bahraini, Bangladeshi, Barbadian, Belarusian, Belgian, Belizean, Beninese, Bhutanese, Bolivian, Bosnian Herzegovinian, Brazilian, British, Bruneian, Bulgarian, Burkinabe, Burmese, Burundian, Cambodian, Cameroonian, Canadian, Cape Verdian, Central African, Chadian, Chilean, Chinese, Colombian, Comoran, Congolese, Costa Rican, Croatian, Cuban, Cypriot, Czech, Danish, Djibouti, Dominican, Dutch, East Timorese, Ecuadorean, Egyptian, Emirian, Equatorial Guinean, Eritrean, Estonian, Ethiopian, Fijian, Filipino, Finnish, French, Gabonese, Gambian, Georgian, German, Ghanaian, Greek, Grenadian, Guatemalan, Guinean, Guyanese, Haitian, Honduran, Hungarian, Icelander, Indian, Indonesian, Iranian, Iraqi, Irish, Israeli, Italian, Ivorian, Jamaican, Japanese, Jordanian, Kazakhstani, Kenyan, Korean, Kuwaiti, Kyrgyz, Laotian, Latvian, Lebanese, Liberian, Libyan, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malawian, Malaysian, Maldivan, Malian, Maltese, Mauritanian, Mauritian, Mexican, Moldovan, Mongolian, Montenegrin, Moroccan, Mozambican, Namibian, Nepalese, New Zealander, Nicaraguan, Nigerian, North Korean, Norwegian, Omani, Pakistani, Palestinian, Panamanian, Paraguayan, Peruvian, Polish, Portuguese, Qatari, Romanian, Russian, Rwandan, Salvadoran, Samoan, Saudi, Scottish, Senegalese, Serbian, Singaporean, Slovakian, Slovenian, Somali, South African, South Korean, Spanish, Sri Lankan, Sudanese, Swazi, Swedish, Swiss, Syrian, Tajikistani, Tanzanian, Thai, Togolese, Tongan, Tunisian, Turkish, Turkmen, Ugandan, Ukrainian, Uruguayan, Uzbekistani, Venezuelan, Vietnamese, Welsh, Yemeni, Zambian, Zimbabwean.

Request body:

{
  "gender": "Woman",
  "age": 28,
  "nationality_1": "Korean",
  "shot": "Half-length portrait",
  "hair_style": "Long straight",
  "hair_color": "Black",
  "makeup": "Natural Makeup",
  "prompt_prefix": "Photo of a person in a cream knit sweater, soft window light.",
  "aspect_ratio": "3:4",
  "short_edge": 1080,
  "num_images": 2
}
curl -X POST https://api.happypony.io/api/v1/jobs/human-portrait \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"gender": "Woman", "age": 28, "nationality_1": "Korean", "shot": "Half-length portrait", "hair_style": "Long straight", "aspect_ratio": "3:4", "num_images": 2}'

Response 202 (fields: Create response):

{
  "request_id": "48365",
  "type": "human-portrait",
  "status": "IN_QUEUE",
  "credits": 6,
  "status_url": "https://api.happypony.io/api/v1/jobs/48365/status",
  "response_url": "https://api.happypony.io/api/v1/jobs/48365",
  "cancel_url": "https://api.happypony.io/api/v1/jobs/48365/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/48365/status -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48365",
  "type": "human-portrait",
  "status": "IN_PROGRESS",
  "created_at": "2026-10-08T10:00:00.000Z",
  "completed_at": null,
  "credits": 6,
  "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/48365 -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48365",
  "type": "human-portrait",
  "status": "COMPLETED",
  "created_at": "2026-10-08T10:00:00.000Z",
  "completed_at": "2026-10-08T10:00:52.000Z",
  "credits": 6,
  "images": [{ "url": "https://…signed…", "format": "png" }, { "url": "https://…signed…", "format": "png" }],
  "expires_in": 259200,
  "parameters": { "gender": "Woman", "age": "28", "shot": "Half-length portrait", "nationality_1": "Korean",
                  "hair_style": "Long straight", "shot_weight": 1.3, "prompt_prefix": null,
                  "model": "z-image-text-to-image", "aspect_ratio": "3:4", "short_edge": 1080, "num_images": 2 },
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}
Field Type Description
images object[] One image per portrait (num_images).
parameters object The attributes you set (age as a string), shot_weight when there is a shot, prompt_prefix, model, aspect_ratio, short_edge and num_images.

Full example

Create, poll until done, download:

curl (bash)

# Needs curl and jq. Usage: HP_KEY=hp_… ./portrait.sh
JOB=$(curl -s -X POST https://api.happypony.io/api/v1/jobs/human-portrait \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"gender": "Man", "age": 36, "nationality_1": "Italian", "shot": "Head and shoulders portrait",
       "beard": "Stubble Beard", "hair_style": "Quiff", "num_images": 2}')
echo "$JOB" | jq .
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 "portrait-$((++i)).$FORMAT" "$URL"; done

Python

# pip install requests   |   HP_KEY=hp_… python portrait.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}/human-portrait", headers=H, json={
    "gender": "Woman",
    "age": 28,
    "nationality_1": "Korean",
    "shot": "Half-length portrait",
    "hair_style": "Long straight",
    "prompt_prefix": "Photo of a person in a cream knit sweater, soft window light.",
    "aspect_ratio": "3:4",
    "num_images": 2,
})
job.raise_for_status()
job = job.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"portrait-{job['request_id']}-{i}.{image['format']}", "wb") as f:
        f.write(requests.get(image["url"]).content)

虚拟人像

价格:虚拟人像

无需输入图片:用属性(性别、年龄、国籍、身材、面部、发型、妆容、取景)描述一个人,生成写实风格的新虚构人物肖像:使用 Qwen-Image 2.1 每个任务 1 到 4 张,使用 MiniMax-H3-Image 每个任务 1 张(它也支持 4K)。与在 www.happypony.io/human-portrait 上生成的任务完全相同。

POST https://api.happypony.io/api/v1/jobs/human-portrait
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/human-portrait,Content-Type: application/json。所有字段均为可选;{} 也是合法请求。

字段 类型 必填 默认值 说明
gender, age, shot, nationality_1, … string 否 由模型决定 人物属性;每个字段的可选值见人物属性取值。age 也可以传数字。
shot_weight number 否 设置了 shot 时为 1.3 shot 取景的强度:1(轻微)、1.3、1.5(强)、1.8(很强)。仅在设置 shot 时可用。
prompt_prefix string 否 无 紧跟在人物描述之后加入提示词的自由文本(场景、服装、光线、风格),最多 1000 个字符。不传时使用柔和的棚拍光和中性背景。
short_edge integer 否 1080 每张图片的尺寸:1080、1440、2048(2K)或 4096(4K)。请先选尺寸:它决定了可用的 model。2048 为 4 MP(1:1 为 2048x2048,16:9 为 2720x1536);4096 为 16 MP(1:1 为 4096x4096,16:9 为 5472x3072)。
model string 否 "z-image-text-to-image";short_edge 为 4096 时为 "minimax-h3-image" 生成引擎。"z-image-text-to-image"(Qwen-Image 2.1)支持 short_edge 1080 到 2048;"minimax-h3-image"(MiniMax-H3-Image)支持 1080 到 4096。其他组合返回 400。
aspect_ratio string 否 "9:16" "16:9", "4:3", "1:1", "3:4", "9:16"。
num_images integer 否 1 用同一组属性生成的不同肖像数量:"z-image-text-to-image" 为 1 到 4 张,"minimax-h3-image" 只能为 1 张。

未传的属性由模型决定,不会随机选取;如需在多次请求间获得变化,请自行挑选取值。nationality_2 会把第二个国籍混入第一个,beard 适用于男性形象。取值必须与下表的拼写完全一致(区分大小写),否则返回 400。

人物属性取值

字段 取值
gender Woman, Man
age 18, 20, 24, 28, 32, 36, 40, 44, 50, 56, 62, 70, 80
shot Head portrait, Head and shoulders portrait, Half-length portrait, Portrait, Full-length portrait, Full body, Close-up
nationality_1, nationality_2 见下方列表
body_type Slim, Slight, Petite, Fit, Curvy, Voluptuous, Thick, Muscular, Buxom, Chubby, Plump, Stocky, Tall, Short
breast_size flat, small, medium, large, huge
butt_size small, medium, large, athletic
skin_tone fair, medium, dark, olive, tan, bronzed, golden, porcelain, alabaster, ebony, chocolate, caramel, honey, peach, ivory, rose, sand
skin_texture smooth, normal, dry, oily, combination, poreless, fine-textured, freckled, mole-covered, wrinkled, mature, youthful, dewy, matte, glowing, radiant
face_shape Oval, Round, Square, Heart, Diamond, Oblong, Long, Triangle, Inverted Triangle, Pear, Rectangle
jawline defined, soft, rounded, square, angular, sharp, delicate, strong, wide, narrow
eyes_color Amber, Blue, Brown, Green, Gray, Hazel, Violet, Heterochromia
eyes_shape Almond Eyes Shape, Asian Eyes Shape, Close-Set Eyes Shape, Deep Set Eyes Shape, Downturned Eyes Shape, Double Eyelid Eyes Shape, Hooded Eyes Shape, Monolid Eyes Shape, Oval Eyes Shape, Round Eyes Shape, Upturned Eyes Shape
nose_shape straight, aquiline, roman, button, upturned, broad, narrow, small, large, sharp, rounded, angular, delicate, defined
nose_size small, medium, large, wide, narrow, prominent, subtle, delicate
hair_color Auburn, Black, Jet Black, Blonde, Strawberry, Chestnut, Chocolate, Caramel, Copper, Gray, Honey, Mahogany, Platinum, Red, Silver, White, Burgundy, Multicolored, Pastel
hair_style Afro, Bald, Bangs, Bob, Blunt bob, Braided, Box braids, Bun, Top Knot, Buzz, Cornrows, Curly, Curly bob, Dreadlocks, Faux hawk, Layered, Long straight, Long ponytail, High ponytail, Mohawk, Pixie, Pompadour, Quiff, Shag, Short, Short curly, Side braid, Spiky, Undercut, Updo, Very long wave, Wavy, Wavy bob
hair_length Short, Medium, Long
beard Stubble Beard, Goatee, Full Beard, Van Dyke Beard, Soul Patch, Garibaldi Beard, Circle Beard, Corporate Beard, Balbo Beard, Ducktail Beard, Chinstrap Beard, Anchor Beard, Chevron Mustache, Horseshoe Mustache, Handlebar Mustache, Imperial Mustache, Pencil Mustache, Zappa Mustache
makeup Natural Makeup, Glam Makeup, Glowy Makeup, Dewy Makeup, Classic Makeup, Cut Crease Makeup, Edgy Makeup, Festival Makeup, Golden Makeup, Monochromatic Makeup, Party Makeup, Retro Makeup, Smokey Eye Makeup, Sunset Eye Makeup, Vintage Makeup, Watercolor Makeup, Anime Makeup, Artistic Makeup, Avant-garde Makeup, Bohemian Makeup
makeup_color Red, Pink, Coral, Peach, Mauve, Burgundy, Plum, Purple, Brown, Copper, Gold, Silver, Black, Wine, Raspberry, Orange, Nude, Berry

国籍(nationality_1、nationality_2):Afghan, Albanian, Algerian, American, Andorran, Angolan, Argentine, Armenian, Australian, Austrian, Azerbaijani, Bahamian, Bahraini, Bangladeshi, Barbadian, Belarusian, Belgian, Belizean, Beninese, Bhutanese, Bolivian, Bosnian Herzegovinian, Brazilian, British, Bruneian, Bulgarian, Burkinabe, Burmese, Burundian, Cambodian, Cameroonian, Canadian, Cape Verdian, Central African, Chadian, Chilean, Chinese, Colombian, Comoran, Congolese, Costa Rican, Croatian, Cuban, Cypriot, Czech, Danish, Djibouti, Dominican, Dutch, East Timorese, Ecuadorean, Egyptian, Emirian, Equatorial Guinean, Eritrean, Estonian, Ethiopian, Fijian, Filipino, Finnish, French, Gabonese, Gambian, Georgian, German, Ghanaian, Greek, Grenadian, Guatemalan, Guinean, Guyanese, Haitian, Honduran, Hungarian, Icelander, Indian, Indonesian, Iranian, Iraqi, Irish, Israeli, Italian, Ivorian, Jamaican, Japanese, Jordanian, Kazakhstani, Kenyan, Korean, Kuwaiti, Kyrgyz, Laotian, Latvian, Lebanese, Liberian, Libyan, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malawian, Malaysian, Maldivan, Malian, Maltese, Mauritanian, Mauritian, Mexican, Moldovan, Mongolian, Montenegrin, Moroccan, Mozambican, Namibian, Nepalese, New Zealander, Nicaraguan, Nigerian, North Korean, Norwegian, Omani, Pakistani, Palestinian, Panamanian, Paraguayan, Peruvian, Polish, Portuguese, Qatari, Romanian, Russian, Rwandan, Salvadoran, Samoan, Saudi, Scottish, Senegalese, Serbian, Singaporean, Slovakian, Slovenian, Somali, South African, South Korean, Spanish, Sri Lankan, Sudanese, Swazi, Swedish, Swiss, Syrian, Tajikistani, Tanzanian, Thai, Togolese, Tongan, Tunisian, Turkish, Turkmen, Ugandan, Ukrainian, Uruguayan, Uzbekistani, Venezuelan, Vietnamese, Welsh, Yemeni, Zambian, Zimbabwean.

请求体:

{
  "gender": "Woman",
  "age": 28,
  "nationality_1": "Korean",
  "shot": "Half-length portrait",
  "hair_style": "Long straight",
  "hair_color": "Black",
  "makeup": "Natural Makeup",
  "prompt_prefix": "Photo of a person in a cream knit sweater, soft window light.",
  "aspect_ratio": "3:4",
  "short_edge": 1080,
  "num_images": 2
}
curl -X POST https://api.happypony.io/api/v1/jobs/human-portrait \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"gender": "Woman", "age": 28, "nationality_1": "Korean", "shot": "Half-length portrait", "hair_style": "Long straight", "aspect_ratio": "3:4", "num_images": 2}'

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

{
  "request_id": "48365",
  "type": "human-portrait",
  "status": "IN_QUEUE",
  "credits": 6,
  "status_url": "https://api.happypony.io/api/v1/jobs/48365/status",
  "response_url": "https://api.happypony.io/api/v1/jobs/48365",
  "cancel_url": "https://api.happypony.io/api/v1/jobs/48365/cancel"
}

2) 轮询状态

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

curl https://api.happypony.io/api/v1/jobs/48365/status -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48365",
  "type": "human-portrait",
  "status": "IN_PROGRESS",
  "created_at": "2026-10-08T10:00:00.000Z",
  "completed_at": null,
  "credits": 6,
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}

3) 获取结果

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

curl https://api.happypony.io/api/v1/jobs/48365 -H "Authorization: Bearer $HP_KEY"
{
  "request_id": "48365",
  "type": "human-portrait",
  "status": "COMPLETED",
  "created_at": "2026-10-08T10:00:00.000Z",
  "completed_at": "2026-10-08T10:00:52.000Z",
  "credits": 6,
  "images": [{ "url": "https://…signed…", "format": "png" }, { "url": "https://…signed…", "format": "png" }],
  "expires_in": 259200,
  "parameters": { "gender": "Woman", "age": "28", "shot": "Half-length portrait", "nationality_1": "Korean",
                  "hair_style": "Long straight", "shot_weight": 1.3, "prompt_prefix": null,
                  "model": "z-image-text-to-image", "aspect_ratio": "3:4", "short_edge": 1080, "num_images": 2 },
  "status_url": "…", "response_url": "…", "cancel_url": "…"
}
字段 类型 说明
images object[] 每张肖像一张图片(共 num_images 张)。
parameters object 你设置的属性(age 为字符串)、有 shot 时的 shot_weight,以及 prompt_prefix、model、aspect_ratio、short_edge 和 num_images。

完整示例

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

curl (bash)

# Needs curl and jq. Usage: HP_KEY=hp_… ./portrait.sh
JOB=$(curl -s -X POST https://api.happypony.io/api/v1/jobs/human-portrait \
  -H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
  -d '{"gender": "Man", "age": 36, "nationality_1": "Italian", "shot": "Head and shoulders portrait",
       "beard": "Stubble Beard", "hair_style": "Quiff", "num_images": 2}')
echo "$JOB" | jq .
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 "portrait-$((++i)).$FORMAT" "$URL"; done

Python

# pip install requests   |   HP_KEY=hp_… python portrait.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}/human-portrait", headers=H, json={
    "gender": "Woman",
    "age": 28,
    "nationality_1": "Korean",
    "shot": "Half-length portrait",
    "hair_style": "Long straight",
    "prompt_prefix": "Photo of a person in a cream knit sweater, soft window light.",
    "aspect_ratio": "3:4",
    "num_images": 2,
})
job.raise_for_status()
job = job.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"portrait-{job['request_id']}-{i}.{image['format']}", "wb") as f:
        f.write(requests.get(image["url"]).content)