Skip to content

Image

This quickstart walks you through generating your first image with SIRAYA Model Router.

Image generation

curl https://llm.siraya.ai/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: <API_KEY>" \
    -d '{
    "model": "imagen-4.0-generate-001",
    "prompt": "A cute baby sea otter",
  }'

from openai import OpenAI
import base64
import os

client = OpenAI(
    api_key="<API_KEY>", # Replace with your Key "sk-***"
    base_url="https://llm.siraya.ai/v1"
)

prompt = """A cute baby sea otter."""

result = client.images.generate(
    model="imagen-4",
    prompt=prompt,
)

print(result)
  • https://llm.siraya.ai/v1/images/generations is the base URL
  • <API_KEY> is your API Key generated in API page.
  • model is the model name, such as gpt-image-2, available model list can be access in Model page.
  • prompt is the prompt.
  • async (boolean, optional, default false) — when false, the request waits for generation to finish and returns the finished image. When true, the request returns immediately with an image id while generation runs in the background; there's no status/poll endpoint for images, so pass callbackUrl to receive the result.
  • callbackUrl (string, optional) — only used when async is true. The full URL the router will POST to once generation completes (or fails). This is the only way to retrieve the result of an async image job.

Example response

{
    "created": 1774716098,
    "data": [
        {
            "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zUAAAAg3..."
        }
    ]
}

Asynchronous generation

Some image models can take a while. Set async: true to return immediately with an image id instead of waiting, and get the result later via a callback.

No poll or download endpoint

Unlike video generation, async image generation has no status/poll endpoint and no separate download endpoint. callbackUrl is required to actually get the result — without it you only get the initial acknowledgment and have no way to retrieve the generated image.

curl https://llm.siraya.ai/v1/images/generations  \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer " \
    -d '{
    "model": "imagen-4.0-generate-001",
    "prompt": "A cute baby sea otter",
    "async": true,
    "callbackUrl": "https://your-app.com/webhooks/siraya-image"
  }'

Example response — the job is accepted; status is processing and no image yet:

{
  "id": "img_n6Sn-1aIT3z8x-QF3xxD0wiUTjl6s31...",
  "object": "image",
  "status": "processing",
  "created_at": 1779869107,
  "model": "imagen-4.0-generate-001"
}

Callback

When the job finishes, the router sends a POST to your callbackUrl. The request body is identical to the synchronous response — the finished image as base64 under data[], not a URL:

{
  "created": 1779869112,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zUAAAAg3..."
    }
  ],
  "error": {}
}

Your endpoint should respond 2xx to acknowledge receipt. If generation failed, the error object is populated and data is empty.