KoalaImages API

The KoalaImages API generates high-quality AI images from a selection of leading models. Credits are charged per generated image; the cost depends on the chosen model and quality setting.

Sample Output

A few images produced through this API. All generated with gpt-image-2 at quality: medium. Click any image to see the exact request that produced it.

Models

ModelCredit costNotes
gpt-image-2 (default)1 fast / 8 medium / 20 highRecommended. Supports reference images and the preserveOriginal lossless flag. The fast quality is available on all plans; medium and high require the Professional Plan.
ideogram-3.03Professional Plan required.
nano-banana-25Professional Plan required. Supports up to 5 reference images.
standard (deprecated)1Leonardo Phoenix 1.0. Kept for backwards compatibility.
premium (deprecated)5Higher-quality Leonardo Phoenix 1.0. Kept for backwards compatibility.

Endpoint

POST https://koala.sh/api/image-generation/

Example Request

fetch("https://koala.sh/api/image-generation/", {
    method: "POST",
    headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        prompt: "cat",
        style: "watercolor",
        size: "1024x1024",
        numImages: 1,
        model: "gpt-image-2",
        quality: "medium",
        enhancePrompt: "on",
        generateAltText: true
    })
});

Example Response

[{
    "url": "https://koala.sh/api/image/v2-cnfjk-1g1wf.jpg",
    "alt": "A watercolor painting of a tabby cat with bright green eyes"
}]

Heads up: The API returns the image URL before the image has finished generating, so you can use the URL immediately. Requesting the URL right away blocks for a few seconds until the image is ready.

Parameters

NameType / Possible ValuesDescriptionRequired
promptstringThe topic or subject for which the image is being generated.Yes
stylestring: "photo" (default), "illustration", "watercolor", "fantasy", "anime", "3d", "isometric", "general", "none"Specifies the visual style of the generated image.No
sizestring: pixel dimensions like "1024x1024" (default), "1152x896", "1216x832", "1344x768", "1536x640", "640x1536", "768x1344", "832x1216", "896x1152", "1792x1008", or "1008x1792"; or aspect-ratio shorthand like "1:1", "5:4", "3:2", "16:9", "21:9", "9:21", "9:16", "2:3", "4:5", "square", "portrait", or "landscape"Specifies the dimensions of the generated image. For gpt-image-2, the requested size is snapped to the nearest native dimension: 1024x1024, 1536x1024, 1024x1536, 1792x1008, or 1008x1792. Other models accept the listed dimensions directly.No
numImagesinteger between 1 and 4 (default: 1)Specifies the number of images to be generated.No
modelstring: "gpt-image-2" (default), "ideogram-3.0", "nano-banana-2", "standard" (deprecated), "premium" (deprecated)Specifies the model used for image generation. The Professional Plan is required for ideogram-3.0, nano-banana-2, premium, and gpt-image-2 at medium or high quality. See the Models section above for credit costs.No
qualitystring: depends on modelQuality setting for the image generation. Only applies to certain models. For gpt-image-2: "fast" (default, 1 credit), "medium" (8 credits), or "high" (20 credits). For ideogram-3.0: "turbo" (default, 3 credits).No
referenceImagesarray of strings (URLs)Array of image URLs to use as reference when generating a new image. Supported for gpt-image-2 and nano-banana-2 models. Maximum 5 reference images allowed.No
enhancePromptstring: "on" (default) or "off"Controls whether the API will automatically enhance your prompt to improve image generation results. Default is "on" unless style is set to "none".No
preserveOriginalboolean (default: false)When true, stores the raw PNG returned by the model instead of re-encoding it as JPEG, for maximum image quality. Only honored for the gpt-image-2 model (other models hand back already-compressed CDN URLs). The image URL still ends in .jpg, but the response will be served with Content-Type: image/png for the first 30 days; after that, the stored asset is transcoded to JPEG in place to bound storage.No
generateAltTextboolean (default: false)When true, the prompt enhancer also produces a short accessible description of the image and returns it in the response's alt field. When false (default), alt is always returned but is an empty string.No

Response Format

If successful, the API will return a JSON array of objects with the following properties:

NameTypeDescription
urlstringThe URL of the generated image.
altstringSuggested alt text describing the image. Always returned; empty unless the request set generateAltText: true.

Image Generation Time

Images are usually generated within 8-15 seconds. However, if there is high load or downtime with one of our providers, this can take much longer. Our system will automatically handle downtime that lasts even several hours. In very rare cases, it can take a few hours until the image is ready at the provided URL.

Complete Example

// Function to generate images
async function generateImages(prompt, style = "photo", size = "1024x1024", numImages = 1) {
  try {
    const response = await fetch("https://koala.sh/api/image-generation/", {
      method: "POST",
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        prompt,
        style,
        size,
        numImages,
        model: "gpt-image-2",
        quality: "fast", // "medium" or "high" cost more credits
        enhancePrompt: "on",
        generateAltText: true // populates the response's alt field
        // For 'gpt-image-2' you can also include:
        // referenceImages: ["https://example.com/image1.jpg", "https://example.com/image2.jpg"],
        // preserveOriginal: true  // store the raw PNG for maximum quality
      })
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const images = await response.json();
    return images;
  } catch (error) {
    console.error("Error generating images:", error);
    return null;
  }
}

// Example usage
async function main() {
  const images = await generateImages(
    "A majestic mountain landscape with a lake reflecting the sunrise",
    "watercolor",
    "1536x640",
    2
  );
  
  if (images) {
    console.log(`Generated ${images.length} images:`);
    images.forEach((image, index) => {
      console.log(`Image ${index + 1}: ${image.url}`);
      if (image.alt) {
        console.log(`  Alt: ${image.alt}`);
      }
    });
  }
}

main();

Error Handling

The API returns standard HTTP status codes for different error conditions:

StatusMeaning
400 Bad RequestInvalid parameters or request format.
401 UnauthorizedInvalid or missing API key.
402 Payment RequiredInsufficient credits.
403 ForbiddenSelected model or quality requires the Professional Plan.
429 Too Many RequestsRate limit exceeded.
500 Internal Server ErrorServer-side error.

Need Help?

If you need additional assistance with the KoalaImages API, please contact us.