Image generation
Generate images from a text prompt, through the Interactions API or the OpenAI-compatible images route.
How an order works
Each image is one order. The price is held when the order is placed, charged once the image is delivered, and released if generation fails. Images generated from the free allowance are not charged.
Interactions API
Send a create request to POST /v1/interactions with op set to create and mode set to background, along with model, prompt, width and height. width and height are required together and must be one of the model's sizes. The Idempotency-Key header is required. The returned id is the order ID. Poll with op set to get and interaction_id set to that ID until the order succeeds, fails or is cancelled. On success, result.download_url is a download link valid for 15 minutes.
curl https://api.inferway.ai/v1/interactions \
-H "Authorization: Bearer $INFERWAY_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"op": "create",
"mode": "background",
"model": "inferway/image-gen-v1",
"prompt": "a red panda riding a bicycle",
"width": 1024,
"height": 1024
}'OpenAI-compatible route
POST /v1/images/generations accepts the OpenAI Images request shape, with n from 1 to 4, and each image is one order. Send an Idempotency-Key on every call. The official OpenAI SDKs retry a timed-out request on their own without sending a key, so a retry without one becomes a new order that is charged when it succeeds.
import os
import uuid
from openai import OpenAI
client = OpenAI(base_url="https://api.inferway.ai/v1", api_key=os.environ["INFERWAY_API_KEY"])
resp = client.images.generate(
model="inferway/image-gen-v1",
prompt="a red panda riding a bicycle",
size="1024x1024",
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)Sizes
Each model accepts only the sizes it serves. Any other size is refused with invalid_size, and the error message lists the sizes available.
| Model | Sizes |
|---|---|
inferway/image-gen-v1 | 1024×1024 · 1024×768 · 768×1024 · 1280×720 · 720×1280 |
Free images
Each account gets a small free allowance of standard-size images each day.
- Up to 7 free images per account per UTC day, reset at 00:00 UTC. The exact daily limit is the daily_limit in the free_alternative of a 402 response.
- Only the standard model at its standard sizes is free.
- Free images apply when the account balance (including gift credit) cannot cover the order, or the Project budget refuses it. A request the balance covers is billed and does not use the allowance.
- An image the platform fails or expires gives its free image back. A queued free order that is cancelled gives it back too; once generation has started, cancelling does not.
- When the day's allowance is used up and the balance cannot cover the order, the request is refused with 402. It is never billed instead. If a Project budget refused the order, the 402 carries the code budget_exceeded; raise the budget or wait for the next billing period.
- When too many free images are already waiting, the request is refused with 429 and the error code free_image_queue_busy, with Retry-After: 30. Nothing is claimed, so retrying after the wait is safe.
Check the text in your images
Long passages of text, calligraphic fonts and small print in an image may contain typos or garbled characters, so check the result after generation.