プラットフォームガイド

Image generation

Generate images with text-to-image or image-to-image models and handle URL or Base64 results.

Choose an image model

Filter the Models and pricing page by Image first. Confirm the model name, supported endpoint, and billing unit. Size, quality, and reference-image support vary by model.

Use the catalog as the source of truth Do not apply this example when the catalog does not list an image endpoint for the model.

Send a generation request

Image generation uses the OpenAI-compatible Images API. A request needs at least model and prompt; choose size, quality, style, and response_format only when the model supports them.

bash
curl https://api.moloop.io/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "YOUR_IMAGE_MODEL_ID",
    "prompt": "A clean product photo of a ceramic cup on a wood table",
    "size": "1024x1024",
    "n": 1,
    "response_format": "url"
  }'

Parameters and responses

ParameterDescription
promptDescribe the subject, composition, style, and constraints.
sizeUse a size supported by the model, such as 1024x1024.
response_formaturl is convenient for downloads; b64_json is useful when your server stores the bytes.
nNumber of images to create; more images usually cost more.

A successful response usually returns url or b64_json in the data array. URLs can expire, so production services should download the result immediately and store it in their own object storage.

javascript
const response = await fetch("https://api.moloop.io/v1/images/generations", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer YOUR_API_KEY",
  },
  body: JSON.stringify({
    model: "YOUR_IMAGE_MODEL_ID",
    prompt: "A paper-cut illustration of a city at sunrise",
    size: "1024x1024",
    response_format: "url",
  }),
});

const result = await response.json();
const imageUrl = result.data?.[0]?.url;

Troubleshooting

  1. 401: check that the API key is complete, enabled, and not expired.

  2. 400: check that the model supports the Images API and that size, quality, and other parameters are allowed.

  3. 429: reduce concurrency and use exponential backoff; do not regenerate without a limit.

  4. The result cannot be opened: download the URL immediately, or use b64_json and save it server-side.