Image Generation
Create stunning images from text descriptions using the OpenAI-compatible API.
Generate high-quality images using models like SDXL Lightning, Flux, and Stable Diffusion all through a standard /v1/images/generations endpoint.
Available Models
| Model | API ID | Tier | Resolution |
|---|---|---|---|
| Stable Diffusion 1.5 | stable-diffusion-1.5 | Free | 512×512 |
| SDXL Lightning | sdxl_lightning_4step.safetensors | Pro | 1024×1024 |
| Flux.1 Schnell | flux.1-schnell | Pro | 1024×1024 |
| Oxlo Image Pro | oxlo-image-pro | Premium | 1024×1024 |
Text-to-Image
Generate an image from a text prompt:
import openai
import base64
client = openai.OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key="<YOUR_API_KEY>"
)
response = client.images.generate(
model="sdxl_lightning_4step.safetensors",
prompt="A futuristic city skyline at sunset, digital art",
n=1,
size="1024x1024"
)
# Decode and save the image
image_data = base64.b64decode(response.data[0].b64_json)
with open("output.png", "wb") as f:
f.write(image_data)
print("Image saved to output.png")OpenAI Compatible: Oxlo.ai image generation works with
client.images.generate() from the official OpenAI SDK.Response Format
Images are returned as base64-encoded JSON:
json
{
"created": 1234567890,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhE..."
}
]
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID (e.g., sdxl_lightning_4step.safetensors) |
| prompt | string | Yes | Text description of the image to generate |
| n | integer | No | Number of images to generate (default: 1) |
| size | string | No | Image size (default: 1024x1024) |
Image-to-Image (img2img)
Transform an existing image using a text prompt. This uses the /v1/images/edits endpoint. Supported models: Stable Diffusion 1.5, SDXL Lightning, and Oxlo Image Pro.
Additional Parameters for img2img
| Parameter | Type | Required | Description |
|---|---|---|---|
| image | string | Yes | Base64-encoded source image (with or without data:image/... prefix) |
| prompt | string | Yes | Text describing the desired transformation |
| strength | float | No | How much to transform the original (0.0 = keep original, 1.0 = fully new). Default: 0.75 |
img2img Example
import openai
import base64
client = openai.OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key="<YOUR_API_KEY>"
)
# Read and encode source image
with open("source.jpg", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode("utf-8")
response = client.images.edit(
model="stable-diffusion-1.5",
image=f"data:image/jpeg;base64,{image_b64}",
prompt="Transform this into a watercolor painting",
extra_body={"strength": 0.75}
)
# Save result
result = base64.b64decode(response.data[0].b64_json)
with open("output.png", "wb") as f:
f.write(result)
print("Transformed image saved!")