Image generation
Generating and editing images through the OpenAI-compatible images endpoints.
POST /openai/v1/images/generationsRequest#
curl https://api.portmodels.com/openai/v1/images/generations \
-H "Authorization: Bearer $PORTMODELS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A lighthouse at dusk, long exposure",
"model": "p-image",
"n": 1,
"size": "1024x1024"
}'| Field | Required | Notes |
|---|---|---|
prompt | yes | What to generate |
model | no | A model key from /v1/models; specify one explicitly, such as p-image |
n | no | Number of images; supported counts depend on the selected model |
size | no | Model-supported dimensions, e.g. 1024x1024 |
Image dimensions are model-specific, and the API does not resize unsupported
requests automatically. For p-image, each side must be from 256 to 1440 pixels
and divisible by 16. Examples include 1024x1024 and 1440x816; 1792x1024
is not supported. See the model size reference
before using another size.
Response#
{
"created": 1771200000,
"data": [
{ "url": "https://...", "revised_prompt": "..." }
],
"usage": { "cost": 0.04 }
}Providers return either a url or a b64_json payload per image; whichever
the provider sent is what you get, alongside revised_prompt when the provider
supplies one.
usage.cost is the credit cost of the generation, markup included.
Notes#
- Image pricing is per image and varies sharply between models. Check the cost of one generation before you loop.
- Hosted image URLs from providers are usually short-lived. If the user needs to keep an image, download it and store it with file storage rather than saving the URL.
- The
promptfield is required; a request without it returns400. - If the response says that the selected model rejected the request parameters, check the selected model's size rules before retrying. Do not repeat an unsupported size unchanged.
Image editing#
Use the OpenAI-compatible multipart endpoint to edit an existing image:
POST /openai/v1/images/editscurl https://api.portmodels.com/openai/v1/images/edits \
-H "Authorization: Bearer $PORTMODELS_API_KEY" \
-F model=pruna-ai/p-image-edit \
-F prompt="Add warm sunset light" \
-F [email protected]Choose a model that advertises image_edit support. The image field accepts
an uploaded image; models that support multiple inputs can use repeated
image[] fields, with a maximum of four images per request. Use PNG, JPEG,
or WebP for broad compatibility; other formats depend on the selected model.
Each uploaded image must be no larger than 10 MB, and the complete multipart
request, including all images and form fields, must fit within 20 MB.
Upload and URL-input support are model-specific. Some models accept only
HTTPS source URLs through a JSON images array. If the selected model does
not support the supplied input format or options, the API returns 400
without generating or charging for an image. It does not discard the source
image, switch to generation, or publish an upload to obtain a public URL.
Multipart options such as n and seed are sent as text fields but must
contain whole integers. Start with n=1; larger counts and output sizes must
be supported by the selected model. The response has the same data and
usage.cost shape as image generation.
For pruna-ai/p-image-edit, size must be one of 1024x1024, 1184x896,
896x1184, 1376x768, 768x1376, 1248x832, or 832x1248.
Use 1376x768 for a wide frame. 1792x1024 is not supported. See the
model size reference.
The pruna-ai/p-image-edit prompt limit is 2,000 characters. When using an
image-edit PortModel, its saved instructions count toward that limit alongside
your prompt. Shorten the combined instructions if the API reports a prompt
length error. Known unsupported inputs are rejected before generation.
For other failures, retain the response's error.log_id and your client
request ID. Include the model, requested size, failure time and image metadata
in a problem report; omit the image contents, prompt,
credentials and full HTTP captures.