MorphogenDocs
API

Images

POST /v1/images/generations: image generation.

POST/v1/images/generations

Generates images from a text description. The format is compatible with OpenAI Images: client.images.generate(...) works. The response is synchronous, and the image arrives in the body as b64_json. There is no image hosting, so the response_format: "url" mode is not supported.

Headers

HeaderValue
AuthorizationBearer <key>. Required. x-api-key: <key> is accepted instead
Content-Typeapplication/json
X-Morphogen-Spacespc_…: the spending space. Optional

Request body

modelstringrequired

An image model from GET /v1/models: for example flux-2-klein or gpt-image-1-mini.

promptstringrequired

The image description.

ninteger

The number of images, from 1 to 10. 1 by default.

sizestring

The size, for example 1024x1024. Allowed values depend on the model.

qualitystring

The quality, for example low. Not all models support it.

aspect_ratiostring

The aspect ratio, for example 16:9.

output_formatstring

The file format: png, jpeg or webp, if the model supports them.

seedinteger

A seed for reproducibility, if the model accepts one.

input_referencesarray

Source images for models that can edit.

Streaming is not supported, and stream: true gives 400. Images have no PII masking: the prompt goes to the model unchanged, and an explicit X-PII-Masking: on gives 400.

Request example

curl https://api.morphogen.ru/v1/images/generations \
  -H "Authorization: Bearer $MORPHOGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "flux-2-klein",
    "prompt": "красное яблоко на белом столе"
  }' | jq -r '.data[0].b64_json' | base64 -d > apple.jpg

Response example

{
  "created": 1760104212,
  "data": [{ "b64_json": "/9j/4AAQSkZJRgABAQ...", "media_type": "image/jpeg" }],
  "usage": { "cost": 0.014 }
}

In the example the b64_json string is cut. Images weigh megabytes, so the response is not buffered and arrives whole.

Errors

400unsupported_response_formatThe request asks for response_format: "url". Only b64_json is supported.
400image_streaming_unsupportedThe request has stream: true.
400invalid_image_countn is not an integer from 1 to 10.
400model_category_mismatchThe model is not in the image category.
400pii_masking_unsupported_endpointThe request has X-PII-Masking: on.
401invalid_api_keyThe key is missing, invalid, revoked or expired.
402insufficient_fundsThe balance does not cover the request reserve.
403model_not_allowedThe model is not in the key's list.
404model_not_foundThere is no such model in the catalog.
429rate_limit_exceededThe request limit per minute is exceeded.

Other codes: Errors. Guide: Images and video.

On this page