Skip to content

Create images

Generate images from a prompt, or edit images you send with it. OpenAI Images compatible, with signed links or base64 output and the cost in usage.

Markdown
On this page
POST/v1/images/generations

Generates images, or edits the images you send in images. The request and response follow OpenAI's Images API, so images.generate in the OpenAI SDKs works against this endpoint. Keys, project budgets, key limits, presets, tags and request records work as for POST /chat/completions. Walkthrough: Image generation.

Request body

modelstringrequired

An image model id (for example openai/gpt-image-2), or a preset as @name whose model makes images (for example @image). List image models with GET /models?kind=image.

promptstringrequired

What to draw, or how to change the images in images.

ninteger

How many images, from 1 to the model's maxN.

sizestring

Exact size such as 1024x1024, for models that take one (sizes, sizeRule).

aspect_ratiostring

Such as 16:9, for models that take one (aspectRatios).

resolutionstring

A resolution tier such as 2K (resolutions).

qualitystring

A quality level such as high (qualities).

seedinteger

For repeatable results, on models that support it.

output_formatstring

png, jpeg, webp or svg, as the model allows (outputFormats).

imagesarray

Up to 16 source images for editing or as references (the model's maxInputImages decides): a public https:// URL, a data:<type>;base64,… URI, { "url" }, { "image_url": { "url" } } or { "b64_json", "mime_type" }.

maskstring | object

A mask for inpainting, in the same forms, on models with mask.

response_formatstring

url (default) for a signed link, or b64_json for the bytes inline. When Lykia's storage is not available the default is b64_json.

provider_optionsobject

Provider-specific options from the model's allow-list (providerOptions). Anything else returns 400.

modelsstring[]

Fallback models, as in chat.

providerobject

Provider preferences: order, only, ignore, allow_fallbacks. See Provider routing.

userstring

and metadata (object) — Tags stored with the request record and never sent to the provider. See Tags and usage breakdown.

Values the model does not support are rejected with 400 and the field's name in metadata.param, never dropped.

Example

Request
curl https://api.getlykia.com/v1/images/generations \
  -H "Authorization: Bearer $LYKIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-image-2",
    "prompt": "A watercolor lighthouse on a cliff at dawn",
    "size": "1024x1024",
    "quality": "medium",
    "user": "tenant-42",
    "metadata": { "feature": "blog-covers" }
  }'
Response200
{
    "id": "gen-1795463382-brqoiL7tycyIA73O",
    "object": "image.generation",
    "created": 1795463382,
    "model": "openai/gpt-image-2",
    "provider": "openai",
    "data": [
        {
            "mime_type": "image/png",
            "width": 1024,
            "height": 1024,
            "url": "https://files.example.com/media/gen-1795463382-brqoiL7tycyIA73O/0.png?X-Amz-Expires=3600&X-Amz-Signature=5f0c9e…",
            "expires_at": "2026-11-23T20:49:42.898Z"
        }
    ],
    "usage": {
        "images": 1,
        "cost": 0.05425,
        "is_byok": false,
        "cost_details": {
            "upstream_cost": 0.05425,
            "platform_fee": 0,
            "is_byok": false
        },
        "units": {
            "input_text_tokens": 50,
            "input_image_tokens": 0,
            "output_image_tokens": 1800
        }
    }
}

Response

idstring

The request id (also in the X-Generation-Id header).

objectstring

Always image.generation.

createdinteger

Unix time.

modelstring

The model that made the images; with a preset, the real model.

providerstring

The provider that served the request.

dataarray

One item per image.

urlstring

A signed link to the original file in Lykia's storage, valid for one hour (response_format: "url").

b64_jsonstring

The image bytes in base64 (response_format: "b64_json").

mime_typestring

For example image/png.

width

, height (integer) — When known.

revised_promptstring

When the provider rewrote the prompt.

expires_atstring

When url stops working (ISO 8601).

usageobject

images (the number of images), cost in USD, is_byok, cost_details (upstream_cost, platform_fee, is_byok) and units (what was billed, such as images, megapixels or tokens by type).

Headers: X-Generation-Id, X-Lykia-Cost (the cost in USD) and X-Lykia-Preset when model was a preset.

Errors

StatusCodeWhen
400unsupported_inputAn unsupported value or provider_options entry (metadata.param), or an option combination that is not priced yet ("not priced yet"; it works with your own provider key).
400bad_requestA malformed or out-of-range field, such as n above maxN (metadata.param).
400unsupported_modelThe model does not make images.
400storage_not_configuredresponse_format: "url" while Lykia's storage is not available.
402insufficient_creditsThe balance, key limit or project budget cannot cover the reservation.
403platform_sales_disabledThe provider is not offered on Lykia credits yet; add your own key for it.
403byok_only_no_keyThe project only allows its own provider keys and has none for this model.
408timeoutAn asynchronous provider did not finish in time (provider_code: image_wait_exceeded). Not charged.
429provider_busyLykia's connection to the provider is at its limit of requests at once; retry after Retry-After.

Other codes are as in Errors. A provider that charges for a rejected request (for example on content grounds) is reported with metadata.billed_by_provider: true, and that cost is charged.