Images
LLM API provides dedicated OpenAI-compatible image endpoints for text-to-image
generation and image editing. Generated images are returned as base64 data in
data[].b64_json; the exact model, size, quality, and output format support is
catalog-dependent.
Generate an image
POST /v1/images/generations accepts a JSON body:
curl -X POST "https://api.llmapi.ai/v1/images/generations" \
-H "Authorization: Bearer $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A tiny bookstore in a rainy neon city",
"size": "1024x1024",
"quality": "low"
}'
Set stream: true with partial_images when the model supports incremental
renders. Those renders arrive as SSE events. Without streaming, wait for the
complete JSON response and decode each data[].b64_json value locally.
{
"created": 1715000000,
"data": [{ "b64_json": "iVBORw0KGgoAAA..." }],
"usage": {
"input_tokens": 12,
"output_tokens": 500,
"total_tokens": 512
}
}
For example, decode an image in Python:
import base64
from pathlib import Path
image = response.json()["data"][0]["b64_json"]
Path("generated.png").write_bytes(base64.b64decode(image))
Generation fields
| Field |
Description |
model |
Image model ID. The model catalog is authoritative for supported parameters. |
prompt |
Text description or edit instruction. Required for both generation and editing. |
size |
Requested dimensions, such as 1024x1024 or auto, where supported. |
quality |
low, medium, high, xhigh, max, or auto, depending on the model. |
n |
Number of images to generate, if supported. |
output_format |
png, jpeg, or webp, where supported. |
background |
auto, opaque, or transparent, where supported. |
output_compression |
JPEG/WebP compression value from 0 to 100. |
stream / partial_images |
Enable SSE and choose how many intermediate renders to emit. |
Unsupported parameters are rejected by some models and ignored by others, so
check the model capability data before relying on a parameter.
Edit an image
POST /v1/images/edits uses multipart/form-data. Upload one or more images
under image[], and optionally upload a PNG mask:
curl -X POST "https://api.llmapi.ai/v1/images/edits" \
-H "Authorization: Bearer $LLM_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Turn the sky into a pink sunset" \
-F "image[]=@photo.png"
Repeat image[] for multi-image editing. A mask identifies the editable area
when the selected model supports masked edits; the mask should be a PNG with
the dimensions expected by the model. The edit response uses the same
data[].b64_json and usage shape as image generation.
curl -X POST "https://api.llmapi.ai/v1/images/edits" \
-H "Authorization: Bearer $LLM_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Replace the sign with a blank wooden sign" \
-F "image[]=@street.png" \
-F "mask=@sign-mask.png" \
-F "output_format=png"
Streaming partial renders
For models that support image streaming, request partial renders explicitly:
{
"model": "gpt-image-2",
"prompt": "A watercolor lighthouse",
"size": "1024x1024",
"stream": true,
"partial_images": 2
}
The server returns SSE events containing intermediate base64 image data. They
are previews, not additional final images; use the final event/result for the
completed asset. If a model does not advertise streaming support, use the
normal synchronous request.
Notes
- Image models are billed according to the selected model, quality, size, number of images, and output token usage. Start with a low-quality, small render while integrating.
- Dedicated image endpoints are separate from chat-based image models. For models that return images through a multimodal chat response, use Chat Completions and see Image Generation.
- The Models page shows current image models and capabilities.
- Image data is returned inline as base64 rather than as a permanent gateway-hosted URL. Decode it promptly and store it in your own object storage if it must be retained.
- Common failures include unsupported size or quality, oversized uploads, insufficient credits, rate limiting, and upstream provider errors.
API operation: POST /v1/images/generations
API operation: POST /v1/images/edits