Skip to main content

Overview

Generate stunning images from text prompts using leading image generation models from providers like Black Forest Labs, Stability AI, and more.

Quick Start

curl https://api.compilelabs.com/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "black-forest-labs/flux-1-schnell",
    "prompt": "A beautiful sunset over the ocean"
  }'

Supported Models

Parameters

  • model: The image generation model to use
  • prompt: Text description of desired image
  • size: Output dimensions (e.g., “1024x1024”)
  • n: Number of images to generate (1-4)
  • response_format: “url” or “b64_json”

Example

import openai

client = openai.OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.compilelabs.com/v1"
)

response = client.images.generate(
    model="black-forest-labs/flux-1-schnell",
    prompt="A sleek modern laptop on a desk with natural lighting, minimalist style",
    size="1024x1024",
    n=1
)

print(response.data[0].url)

Listing Available Models

Get a list of all available image generation models:
curl "https://api.compilelabs.com/v1/models?type=text_to_image" \
  -H "Authorization: Bearer YOUR_API_KEY"

Common Image Sizes

Different models support different output sizes:

Standard Sizes

  • 1024x1024: 1 megapixel - Fastest, most common size
  • 1024x1792: ~1.8 megapixels - Portrait orientation
  • 1792x1024: ~1.8 megapixels - Landscape orientation
  • 2048x2048: 4 megapixels - Higher quality

Example

curl https://api.compilelabs.com/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "black-forest-labs/flux-1-schnell",
    "prompt": "A futuristic cityscape",
    "size": "1024x1024"
  }'

Pricing Examples

Image generation is billed per megapixel. Here are approximate costs for common models and sizes:

Flux 1 Schnell

  • 1024x1024 (1 MP): ~$0.003 per image
  • 1024x1792 (1.8 MP): ~$0.005 per image
  • 2048x2048 (4 MP): ~$0.012 per image

Stable Diffusion XL (SDXL)

  • 1024x1024 (1 MP): ~$0.02 per image
  • 1024x1792 (1.8 MP): ~$0.036 per image

Qwen Image

  • 1024x1024 (1 MP): ~$0.02 per image
  • 2048x2048 (4 MP): ~$0.08 per image

Saving Images from Base64

Instead of using URLs, you can request images in base64 format and save them directly:
import openai
import base64

client = openai.OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.compilelabs.com/v1"
)

response = client.images.generate(
    model="black-forest-labs/flux-1-schnell",
    prompt="A beautiful sunset over the ocean",
    size="1024x1024",
    n=1,
    response_format="b64_json"
)

# Decode base64 and save the image
image_data = base64.b64decode(response.data[0].b64_json)

with open("generated_image.png", "wb") as f:
    f.write(image_data)

print("Image saved as generated_image.png")

Next Steps