Skip to content

Image Generation

LibertAI offers image generation models with competitive pricing.
Generate high-quality images from text prompts using our API.

Loading models & pricing...

Available Models

Pricing

Image generation pricing is per image generated.

API Endpoints

LibertAI provides two compatible endpoints for image generation:

1. Stable Diffusion WebUI API (sdapi)

Compatible with Stable Diffusion WebUI format.

Endpoint: POST https://api.libertai.io/sdapi/v1/txt2img

Request Body:

json
{
  "model": "z-image-turbo",
  "prompt": "a cute cat, anime style",
  "width": 512,
  "height": 512
}

Response:

json
{
  "images": ["<base64_encoded_image>"]
}

2. OpenAI Compatible API

Compatible with OpenAI's image generation format.

Endpoint: POST https://api.libertai.io/v1/images/generations

Request Body:

json
{
  "model": "z-image-turbo",
  "prompt": "a cute cat, anime style",
  "size": "512x512"
}

Response:

json
{
  "data": [
    {
      "b64_json": "<base64_encoded_image>"
    }
  ]
}

Usage Examples

Using curl

bash
curl -s -X POST "https://api.libertai.io/sdapi/v1/txt2img" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-image-turbo",
    "prompt": "a cute cat, anime style",
    "width": 512,
    "height": 512
  }' \
  | jq -r '.images[0]' | base64 -d > output.png
bash
curl -s -X POST "https://api.libertai.io/v1/images/generations" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-image-turbo",
    "prompt": "a cute cat, anime style",
    "size": "512x512"
  }' \
  | jq -r '.data[0].b64_json' | base64 -d > output.png

Using Python

python
from openai import OpenAI
import base64

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.libertai.io/v1"
)

response = client.images.generate(
    model="z-image-turbo",
    prompt="a cute cat, anime style",
    size="512x512",
    response_format="b64_json"
)

# Save the image
image_data = base64.b64decode(response.data[0].b64_json)
with open("output.png", "wb") as f:
    f.write(image_data)

Using JavaScript/TypeScript

javascript
import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.libertai.io/v1'
});

const response = await client.images.generate({
  model: 'z-image-turbo',
  prompt: 'a cute cat, anime style',
  size: '512x512',
  response_format: 'b64_json'
});

// Save the image
const imageData = Buffer.from(response.data[0].b64_json, 'base64');
fs.writeFileSync('output.png', imageData);

Parameters

Required

  • model: The model ID to use for generation (e.g., z-image-turbo)
  • prompt: Text description of the image to generate

sdapi optional parameters

  • width: Image width in pixels (default: 1024)
  • height: Image height in pixels (default: 1024)
  • steps: Number of steps (default: 9, more steps = higher quality but slower)
  • seed: Seed to use to maintain consistency across generations
  • remove_background: Enable to remove the background of the image after the generation (default: false)

OpenAI-compatible optional parameters

  • size: Image size in format WIDTHxHEIGHT (e.g., 512x512, default 1024x1024)
  • n: Number of images to generate. Only n=1 is supported right now, multiple images will be supported in the future
  • remove_background: Enable to remove the background of the image after the generation (default: false)