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
| Model | Credit cost | Notes |
|---|---|---|
gpt-image-2 (default) | 1 fast / 8 medium / 20 high | Recommended. 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.0 | 3 | Professional Plan required. |
nano-banana-2 | 5 | Professional Plan required. Supports up to 5 reference images. |
standard (deprecated) | 1 | Leonardo Phoenix 1.0. Kept for backwards compatibility. |
premium (deprecated) | 5 | Higher-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
| Name | Type / Possible Values | Description | Required |
|---|---|---|---|
| prompt | string | The topic or subject for which the image is being generated. | Yes |
| style | string: "photo" (default), "illustration", "watercolor", "fantasy", "anime", "3d", "isometric", "general", "none" | Specifies the visual style of the generated image. | No |
| size | string: 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 |
| numImages | integer between 1 and 4 (default: 1) | Specifies the number of images to be generated. | No |
| model | string: "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 |
| quality | string: depends on model | Quality 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 |
| referenceImages | array 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 |
| enhancePrompt | string: "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 |
| preserveOriginal | boolean (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 |
| generateAltText | boolean (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:
| Name | Type | Description |
|---|---|---|
| url | string | The URL of the generated image. |
| alt | string | Suggested 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:
| Status | Meaning |
|---|---|
| 400 Bad Request | Invalid parameters or request format. |
| 401 Unauthorized | Invalid or missing API key. |
| 402 Payment Required | Insufficient credits. |
| 403 Forbidden | Selected model or quality requires the Professional Plan. |
| 429 Too Many Requests | Rate limit exceeded. |
| 500 Internal Server Error | Server-side error. |
Need Help?
If you need additional assistance with the KoalaImages API, please contact us.