Image generation

POST /v1/images/generations creates images from a text description and returns them as base64. Image models appear in GET /v1/models with type: "image".

Request

FieldRequiredNotes
modelyesAn ID of an image model.
promptyesImage description, up to 4,000 characters.
nnoNumber of images, default 1. The per-model limit is max_images_per_request.
sizenoauto or WIDTHxHEIGHT, for example 1024x1024. Token-priced models only accept auto, 1024x1024, 1024x1536, and 1536x1024.
qualitynoFor token-priced models: low, medium, high, or auto.
response_formatnoOnly b64_json (default). Other values are rejected with 400.

Other fields are ignored. Media request bodies are limited to 64 KiB.

Examples

curl https://api.markas.ai.id/v1/images/generations \
  -H "Authorization: Bearer $MARKASAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "IMAGE_MODEL_ID", "prompt": "an orange cat asleep on a sofa", "n": 1}'
import base64, os
from openai import OpenAI

client = OpenAI(base_url="https://api.markas.ai.id/v1", api_key=os.environ["MARKASAI_API_KEY"])

img = client.images.generate(model="IMAGE_MODEL_ID", prompt="an orange cat asleep on a sofa", n=1, response_format="b64_json")
with open("image.png", "wb") as f:
    f.write(base64.b64decode(img.data[0].b64_json))
import { writeFile } from "node:fs/promises";
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.markas.ai.id/v1", apiKey: process.env.MARKASAI_API_KEY });

const img = await client.images.generate({
  model: "IMAGE_MODEL_ID",
  prompt: "an orange cat asleep on a sofa",
  n: 1,
  response_format: "b64_json",
});
await writeFile("image.png", Buffer.from(img.data[0].b64_json, "base64"));

Response

200 OK
{
  "created": 1790000000,
  "data": [{"b64_json": "/9j/4AAQSkZJRg..."}]
}

Images are returned in data[].b64_json; there is no image URL. revised_prompt is included when the model sends it. A request usually takes seconds to tens of seconds.

Billing

  • Per-image models: n × price per image is held up front, and only images actually delivered are billed.
  • Token-priced models: billed from the input tokens and image output tokens the model reports, at the per-million-token price.
  • Failed requests are not billed.
  • Disconnecting midway does not cancel generation: the images are still created and billed.

Common errors

  • 402 insufficient_balance: the balance is below the request's hold.
  • 404 model_not_found: wrong ID, or not an image model.
  • 400 invalid_request: a parameter or the description was rejected. The param field names it.
  • 403 key_spend_limit_exceeded: the key's spend limit is reached, including this request's hold.