选一个模型,输入你的提示词,直接查看生成结果。
HiAPI Blog
HiAPI
现在就用 HiAPI 生成
Seedream ships on hiapi as four distinct tiers — seedream-5.0-flash, seedream-5.0-lite, seedream-5.0-pro, and legacy seedream-4.5 — and each one bills differently. Pick the wrong tier or the wrong resolution for the job and you can pay 2-4x more per image for no visible quality gain. This guide shows the actual pricing shape of each tier and a working code pattern for calling the cheapest model that still meets your bar.
You'll build a small Python client that creates a Seedream image task through hiapi's unified task API, waits for the result, and picks resolution/model combinations deliberately instead of defaulting to whatever a tutorial copy-pasted. Before anything else, grab an API key from your hiapi dashboard — every request below sends it as Authorization: Bearer sk-....
Current per-image pricing (always confirm against the live pricing page before you ship, since rates do change):
seedream-5.0-flash — flat $0.025/image, same price for text-to-image and image-to-image. Cheapest tier on the platform; best for drafts, thumbnails, and anything you'll regenerate several times before picking a winner.seedream-5.0-lite — flat $0.035/image, and critically, the same price whether you render at 2K or 4K. There's no cost reason to ever request 2K on this tier — 4K is a free upgrade.seedream-4.5 (legacy) — flat $0.045/image for both endpoints.seedream-5.0-pro — resolution-tiered, not flat: text-to-image is $0.05 at 1K and $0.10 at 2K; image-to-image is $0.06 at 1K and $0.10 at 2K. On this tier, resolution is where your budget actually goes — a 1K draft costs roughly half of a 2K final render.That asymmetry is the whole optimization: lite rewards requesting higher resolution (it's free), pro punishes it (it roughly doubles cost). Treat them differently in your calling code instead of hard-coding one resolution everywhere.
Every Seedream call goes through the same async task endpoints: create with POST /v1/tasks, then either poll GET /v1/tasks/{taskId} or receive a webhook callback. Model ids are bare — no leading models/ or vendor prefix.
import os
import time
import requests
API_KEY = os.environ["HIAPI_API_KEY"] # starts with sk-
BASE_URL = "https://api.hiapi.ai/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
def create_task(model: str, input_payload: dict) -> str:
resp = requests.post(f"{BASE_URL}/tasks", headers=HEADERS,
json={"model": model, "input": input_payload}, timeout=30)
resp.raise_for_status()
return resp.json()["data"]["taskId"]
def wait_task(task_id: str, interval: float = 3.0, timeout: float = 180.0) -> dict:
deadline = time.time() + timeout
while time.time() < deadline:
resp = requests.get(f"{BASE_URL}/tasks/{task_id}", headers=HEADERS, timeout=30)
resp.raise_for_status()
data = resp.json()["data"]
if data["status"] == "success":
return data
if data["status"] == "fail":
raise RuntimeError(data["error"])
time.sleep(interval)
raise TimeoutError(f"task {task_id} did not finish within {timeout}s")
# seedream-5.0-lite: 4K costs the same $0.035 as 2K, so always ask for 4K here.
task_id = create_task(
"seedream-5.0-lite/text-to-image",
{"prompt": "a minimalist product photo of a ceramic mug on a wooden table", "resolution": "4K"},
)
result = wait_task(task_id)
image_url = result["output"][0]["url"]
print(image_url)
resolution on seedream-5.0-lite only accepts 2K or 4K (no 1K). seedream-5.0-pro instead accepts 1K/2K and additionally requires aspect_ratio (one of 1:1, 4:3, 3:4, 16:9, 9:16, 2:3, 3:2, 21:9) — each Seedream tier has a slightly different input schema, so don't assume one model's accepted fields carry over to another.
Pick the tier programmatically, not by habit. Keep a small cost table next to your call site and route by budget/quality need instead of hard-coding one model everywhere — treat the numbers as a cache of the pricing page, not the source of truth:
SEEDREAM_COST_USD = {
("seedream-5.0-flash", None): 0.025,
("seedream-5.0-lite", "2K"): 0.035,
("seedream-5.0-lite", "4K"): 0.035, # same price — always prefer 4K
("seedream-5.0-pro", "1K"): 0.05, # text-to-image; i2i 1K is $0.06
("seedream-5.0-pro", "2K"): 0.10,
}
def pick_model_for_draft_vs_final(is_final: bool) -> tuple[str, dict]:
if not is_final:
return "seedream-5.0-flash", {} # $0.025, iterate freely
return "seedream-5.0-pro", {"resolution": "2K"} # $0.10, one shot at the end
Prefer callbacks to tight polling. Add callback to the create request instead of looping wait_task every few seconds in high-volume pipelines:
task_id_resp = requests.post(
f"{BASE_URL}/tasks", headers=HEADERS,
json={
"model": "seedream-5.0-lite/text-to-image",
"input": {"prompt": "...", "resolution": "4K"},
"callback": {"url": "https://yourapp.example.com/webhooks/hiapi", "when": "final"},
},
timeout=30,
)
Your webhook handler receives one POST when the task reaches a terminal state (success or fail) instead of your worker burning requests in a poll loop. Polling is still the simpler option if you can't expose a public HTTPS endpoint (local dev, internal tools) — pick callbacks once you're running this at real volume.
Dedupe before you create a task, not after. The task API bills on creation, so a retried request (timeout, crashed worker, redeployed queue consumer) that resubmits the same job bills twice. Before calling create_task, check your own store for an existing task keyed by (model, input_hash) and skip creation if one's already in flight or already succeeded — hiapi's task endpoint has no built-in dedupe, so this has to live in your code.
Handle auth failures explicitly. An invalid or revoked key returns HTTP 401 with a structured body, not a generic error page:
{"error": {"code": "permission_denied", "type": "hiapi_error", "request_id": "..."}}
Check for error.code == "permission_denied" specifically so a bad key fails fast instead of retrying into a timeout.
Which Seedream model is cheapest for quick drafts or icons?
seedream-5.0-flash at a flat $0.025/image — the cheapest tier on the platform, same price for text-to-image and image-to-image.
Does asking for 4K instead of 2K cost more on Seedream 5.0 Lite?
No. seedream-5.0-lite is a flat $0.035/image regardless of whether resolution is 2K or 4K, so request 4K by default on this tier.
How much does Seedream 5.0 Pro cost per image?
It's resolution-tiered: text-to-image is $0.05 at 1K and $0.10 at 2K; image-to-image is $0.06 at 1K and $0.10 at 2K. Unlike lite, resolution genuinely changes your bill here.
How do I avoid getting billed twice if my job retries?
The task API has no server-side idempotency key, so dedupe client-side: store a key for (model, input_hash) before calling create_task and skip creation if that key is already in flight or already succeeded.
Should I poll or use a webhook callback?
Poll GET /v1/tasks/{taskId} if you can't expose a public HTTPS endpoint (local dev, scripts). Switch to callback.url + when: "final" once you're running real volume — it replaces a poll loop with a single push notification per task.
What does an invalid API key return?
HTTP 401 with {"error": {"code": "permission_denied", "type": "hiapi_error", "request_id": "..."}}. Check for that error code explicitly rather than retrying a bad key into a timeout.
Can I use these prices without an API key first?
No — every /v1/tasks call requires a valid Authorization: Bearer sk-... header from a real key created in your dashboard; there's no keyless or trial-without-signup path for production generation.