Search

Search HiAPI models, tools, and resources.

Back to blog
Tutorial4 min read

How to Use Imagen 4 API: First Image in 5 Minutes

Choosing among Fast / standard / Ultra, with curl and Python examples, parameters, and error codes.

HiAPI EditorialImagen 4API IntegrationText to Image

TL;DR

  • Imagen 4 (Google-Imagen4) is a text-to-image model at $0.06 per image: one prompt, one aspect ratio, one image — built for portrait photography, natural close-ups, and product stills. Try it on the model page; new accounts get 200 free credits.
  • The series has two more tiers: imagen4-fast at $0.03 for high-volume drafting, and imagen4-ultra at $0.09 for finished-detail output.
  • Everything runs on the HiAPI /v1/tasks endpoint: submit for a taskId, poll for the result, then download from output[0].url.

What it does

  • Text to image, no reference needed: the prompt describes the whole frame, and aspect_ratio is required (1:1, 16:9, 9:16, 3:4, 4:3, auto).
  • Three tiers, one family: Fast for drafts, standard for everyday production, Ultra for detail — three model IDs you can stage across one project.
  • One image per call: no batch count, pixel size, or output format parameters; change the seed to reroll.

Here's a real output from the standard tier:

Sunlit Scandinavian living room with linen sofa; oak shelves and a monstera plant; editorial interior photography

Sunlit Scandinavian living room

Google-Imagen4, 16:9, 1280×720, $0.06.

Try this prompt →

Three tiers: which to use

imagen4-fastGoogle-Imagen4 (standard)imagen4-ultra
Per image$0.03$0.06$0.09
RoleHigh-volume drafts, picking directionsEveryday productionFinished detail, materials, lettering
$10 yields333 images166 images111 images
Best forBrainstorms, sketch roundsRegular deliveryFinal assets, detail-critical frames

The calling convention is identical across the three — change only the model field; the parameter structure matches too, except the seed type (see the table). There's a dedicated guide for each sibling: Imagen 4 Fast API guide and Imagen 4 Ultra API guide. For scene-by-scene recipes, see the prompt guide.

Two ways to start

Browser, 3 steps: open the model page → paste the prompt and pick an aspect ratio → generate. A standard image is $0.06.

API, 3 steps: POST /v1/tasks to submit → take the taskId → GET /v1/tasks/<taskId> until success, then download.

curl: your first image

curl -X POST https://api.hiapi.ai/v1/tasks \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: your-unique-key-001" \
  -d '{
  "model": "Google-Imagen4",
  "input": {
    "prompt": "Sunlit Scandinavian living room with linen sofa; oak shelves and a monstera plant; editorial interior photography",
    "aspect_ratio": "16:9"
  }
}'

Switch tiers by changing model to imagen4-fast or imagen4-ultra. The response carries the taskId you'll poll with.

Python: submit, poll, download

import time, uuid, requests

BASE = "https://api.hiapi.ai/v1/tasks"
HEADERS = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
}

payload = {
    "model": "Google-Imagen4",
    "input": {
        "prompt": "Sunlit Scandinavian living room with linen sofa; oak shelves and a monstera plant; editorial interior photography",
        "aspect_ratio": "16:9",
    },
}

# Submit: the Idempotency-Key makes network retries safe
resp = requests.post(
    BASE,
    headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
    json=payload,
    timeout=30,
)
resp.raise_for_status()
task_id = resp.json()["taskId"]

# Poll: queued -> handling -> archiving -> success / fail
while True:
    task = requests.get(f"{BASE}/{task_id}", headers=HEADERS, timeout=30).json()
    print(task["status"])
    if task["status"] in ("success", "fail"):
        break
    time.sleep(3)

if task["status"] == "success":
    image_url = task["output"][0]["url"]   # temporary URL — download promptly
    img = requests.get(image_url, timeout=60)
    with open("output_image", "wb") as f:  # name the extension to match the actual format
        f.write(img.content)
    print("saved")

Parameters

FieldRequiredValuesNotes
promptyes1–5,000 charsWhat the frame contains
aspect_ratioyes1:1 / 16:9 / 9:16 / 3:4 / 4:3 / autoOutput aspect, required
negative_promptno≤5,000 charsWhat to keep out
seednostandard & Ultra: string (≤500 chars); Fast: integerSame inputs + same seed reproduce the image

All three models share this table. Any field outside it returns a 400.

Errors you'll actually hit

StatusMeaningWhat to do
400 INVALID_REQUESTMalformed body (missing prompt or aspect_ratio, bad enum value, unknown field)Fix the payload against the parameter table
402 INSUFFICIENT_QUOTAOut of credits (no charge)Top up and retry
429 RATE_LIMITEDRate limitedSlow your submission rate
409 / 422 IDEMPOTENCY_KEY_*Same idempotency key resubmitted (processing / payload mismatch)Generate a fresh key
415 UNSUPPORTED_MEDIA_TYPEWrong request formatCheck Content-Type: application/json

Terminal failures use codes like CONTENT_POLICY_VIOLATION, TASK_FAILED, and TASK_TIMEOUT; failed tasks refund in full.

Before you ship

  • Callbacks: pass "callback": {"url": "https://..."} at the request top level and HiAPI notifies your service at the terminal state.
  • Persist outputs: output[0].url is temporary — download it into your own storage right away.
  • Be explicit about aspect: aspect_ratio is required; pick 9:16 deliberately for vertical social content.
  • Seed types differ by tier: Fast takes an integer, standard and Ultra take strings — convert when reusing a composition across tiers.

FAQ

  • Yes, all three models share one calling convention — change only the model field.
  • No, there are no pixel-size or format parameters. aspect_ratio sets the frame; each call returns one image.
  • Yes, failures are free. Credits held at creation are refunded in full at the terminal failure state.
  • Yes, zoom in on rendered text. Poster-style images occasionally gain or lose a letter — inspect the lettering at full size before publishing.

Next: copy the living-room prompt above and generate a test image, then batch-produce from the scene templates in the prompt guide.

Generate it with HiAPI

Choose a model, enter your prompt, and see the result.

HiAPI Blog

Related articles

HiAPI

Generate it with HiAPI

Start generating