Generate images

Generate up to four images from a prompt and reference images.

POSThttps://inference.trymorse.ai/v1/images/generations

Generates up to four images from a prompt and optional reference images, and returns them inline as base64.

Image generation is not offered to API keys for now: GET /v1/models lists no image model to a key, and a key's request here gets 404 model_not_found. A Morse app login can still generate images.

Each image costs the model's micros_per_image, plus micros_per_reference for each reference image. Each image costs at least one credit. You pay only for the images delivered. If the request ends before the images return, you pay nothing.

curl -X POST https://inference.trymorse.ai/v1/images/generations \
  -H "Authorization: Bearer $MORSE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "flux-2-max",
    "prompt": "a red apple on a wooden table, morning light",
    "n": 2,
    "aspect_ratio": "16:9"
  }'
Response
{
  "created": 1792187825,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
      "mime_type": "image/png"
    },
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
      "mime_type": "image/png"
    }
  ]
}

Request body

Morse refuses any field not listed here, such as size, style, or user, with invalid_parameter.

modelstringRequired

An image model's id from GET /v1/models.

promptstringRequired
nintegerDefaults to 1
aspect_ratiostring

Defaults to 1:1. With reference images, it defaults to the ratio nearest the first reference image's.

One of 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, or 2:3.

resolutionstringDefaults to "1k"

Some models take 1k only.

One of 1k or 2k.

qualitystring

Applies only to models with a quality setting. Values include low, medium, and high.

response_format"b64_json"

Images always come back inline.

imagesarray of string

Reference images, as base64 data URLs of PNG, JPEG, or WebP images. Each model sets its own maximum, and some models take none. Each reference image adds to the price of every image.

Response

The images.

createdintegerRequired

Unix seconds.

dataarray of objectRequired

The images. If the provider returned fewer than n, data holds fewer, and you pay only for the images delivered.

Show 2 fields
b64_jsonstringRequired

The image, base64-encoded, with its metadata stripped.

mime_typestringRequired

One of image/png, image/jpeg, or image/webp.

Response headers

HeaderWhat it says
X-Morse-VersionThe running build. Every reply carries it.
X-FundingWhat pays for the request. With a key, the value is always credits. A request that Morse refuses before it bills anything has no X-Funding.
X-Request-IdAn id for this request. Quote it when you contact support about the request. An error that arrives after the request starts carries it too. A request that Morse refuses before it bills anything has no X-Request-Id.

Errors

Every error has the same shape. Errors explains it and when to retry.

400The request is malformed, or the model or its provider refused it.7 codes
invalid_request_body
The body is not a JSON object, a field has the wrong JSON type, or model is missing.
invalid_parameter
A field has a value the endpoint refuses. The message names the field.
duplicate_json_key
A JSON object in the body repeats a key.
remote_media
A reference image links a URL instead of a data: URL.
content_filter
The provider declined the prompt.
invalid_request
The provider rejected the request.
privacy_floor_unmet
The model's tier is below the API key's min_privacy. param is key.min_privacy, and the message names both tiers. GET /v1/models lists only the models the key may call. Morse refuses before it calls the model or holds any credit.
401The key is missing or wrong.3 codes
invalid_api_key
The Authorization header is missing or not Bearer, the key is unknown or revoked, a token that starts with sk_ is not a whole sk_morse_ key, or the bearer is no Morse key or login token at all, such as another service's API key (sk-proj-...).
api_key_expired
The key is past the expiry set on it. Make a new key, or set a later expiry before a key expires.
invalid_token
The bearer is shaped as a Morse login token (a JWT) but its signature fails or it has expired. An API key sends the whole sk_morse_ key.
402The account's credits, or what the key's spend limit has left, do not cover the request.2 codes
insufficient_balance
The balance is below the amount the request must hold. While the balance is negative, the API refuses every metered request.
key_spend_limit_reached
What the key's spend limit has left in its window is below the amount the request must hold. A limit that resets daily, weekly, or monthly sends Retry-After, the seconds until it resets. A limit that never resets sends none. Raise or remove the limit in the dashboard, and the next request is served.
403The key's account may not make this request.5 codes
account_disabled
Morse has disabled the key's account.
account_deleted
The key's account has been deleted.
account_under_18
The account's owner said they are under 18.
ip_not_allowed
The key allows requests only from its allowed IPs, and the request came from another address. The message names the address the proxy saw.
sealed_required
The key is sealed_only, and the request came unsealed. Send it inside POST /v1/sealed, as the Morse app does.
404The model does not exist, or it is not a model for this endpoint.1 code
model_not_found
No model of this endpoint's type has that name.
408The request body arrived too slowly.1 code
request_timeout
The request body did not arrive within one minute.
413The request body is too large.1 code
request_too_large
The body is over 32 MiB, or too large for the provider.
429The account is over its rate limit or its concurrency limit. Wait the number of seconds in Retry-After, then retry.2 codes
rate_limit_exceeded
The account used up its requests per minute. All of the account's keys and its owner's use of the Morse app share one budget.
concurrency_limit_exceeded
The account already has its maximum number of requests in flight. Retry-After is 1.
502The image provider failed or refused the request.3 codes
upstream_error
The provider failed, returned no images, or took more than 10 minutes.
upstream_unavailable
The provider is unavailable right now. Retry later, or choose another model.
upstream_refused
The provider refused the request, such as when it does not serve the model to Morse right now. Retry later, or choose another model.
503Morse or the provider is busy or unavailable. Retry the request later.3 codes
service_unavailable
Morse could not start the request. Retry it.
server_busy
Morse is busy. Retry-After is 1.
upstream_busy
The provider is overloaded. Try again shortly.