Image generation
Generate images from a text prompt with a model of kind image, returned inline as base64.
Generate an image#
POST /v1/images/generations generates up to 4 images from a prompt.
image is offered yet404 model_not_found for every model id. The samples below show the request for when one is offered.Set PANWARD_IMAGE_MODEL to the id of a model of kind image from the model catalog. An id that is not a canonical id answers 404 model_not_found.
cat > body.json <<EOF {"model": "$PANWARD_IMAGE_MODEL", "prompt": "A plain line drawing of a hospital ward", "n": 1} EOF curl https://api.panward.ai/v1/images/generations \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @body.json -o image.json jq -r '.data[0].b64_json' image.json | base64 --decode > ward.png
import base64, os import requests r = requests.post( "https://api.panward.ai/v1/images/generations", headers={"Authorization": f"Bearer {os.environ['PANWARD_API_KEY']}"}, json={ "model": os.environ["PANWARD_IMAGE_MODEL"], "prompt": "A plain line drawing of a hospital ward", "n": 1, }, ) r.raise_for_status() for i, image in enumerate(r.json()["data"]): with open(f"ward-{i}.png", "wb") as f: f.write(base64.b64decode(image["b64_json"]))
import { writeFile } from "node:fs/promises"; const response = await fetch("https://api.panward.ai/v1/images/generations", { method: "POST", headers: { Authorization: `Bearer ${process.env.PANWARD_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: process.env.PANWARD_IMAGE_MODEL, prompt: "A plain line drawing of a hospital ward", n: 1, }), }); if (!response.ok) throw new Error(`image: ${response.status}`); const { data } = (await response.json()) as { data: Array<{ b64_json: string }> }; for (const [i, image] of data.entries()) await writeFile(`ward-${i}.png`, Buffer.from(image.b64_json, "base64"));
Images are returned inline#
Images come back in the response as base64 in b64_json. Panward stores no inference content, so hosted image URLs are not offered: response_format: "url" is refused with 400 unsupported_parameter. Decode and save the images yourself, as the samples do.
Request fields#
| Field | Required | Values | Limits | Notes |
|---|---|---|---|---|
| model | Yes | string | Canonical id of a model of kind `image`. | |
| prompt | Yes | string | max length 32000 | |
| n | No | integer | min 1; max 4 | |
| size | No | string | Width x height in pixels; allowed values depend on the model. | |
| response_format | No | b64_json | Only inline base64 is offered; `url` returns `400 unsupported_parameter`. | |
| seed | No | integer | ||
| user | No | string | max length 256 | Accepted for compatibility and ignored. Never stored, never forwarded upstream. |
user field is accepted for compatibility and ignored. It is never stored and never forwarded upstream.Receipts and billing#
The receipt's response.emitted hash covers the whole JSON body, base64 included, so keep the response as received if you want to verify it.
The response carries the same headers as a chat completion, among them panward-receipt-id, panward-tier and panward-region, and the request has a receipt like any other (Receipts and verification). panward-hold-until-verified: true is accepted: the response waits until the verification level is known and the answer is 503 verification_unavailable instead of an unverified one.
Images are billed per image.