Skip to main content
Generate stunning images from text prompts using advanced AI models including Stable Diffusion and SDXL. Kelly AI provides access to multiple pre-trained models optimized for different styles and use cases.

Generate an image

Create images from text descriptions using the generate() method.
1

Import and initialize

from kellyapi import KellyAPI

kelly = KellyAPI(api_key="your_api_key")
2

Generate your image

image_data = await kelly.generate(
    prompt="A serene mountain landscape at sunset",
    model="PhotoPerfect",
    width=1024,
    height=1024
)
3

Save the result

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

Parameters

prompt
str
required
The text description of the image you want to generate. Be specific and descriptive for best results.
negative_prompt
str
Describes what you don’t want in the image. The default value excludes common unwanted elements like distorted anatomy, bad art, blurriness, and NSFW content.
model
str
default:"PhotoPerfect"
The AI model to use for generation. Different models excel at different styles.
width
int
default:"1024"
Image width in pixels. Common values: 512, 768, 1024.
height
int
default:"1024"
Image height in pixels. Common values: 512, 768, 1024.

Available models

Retrieve the list of available models for your API key.
models = await kelly.sd_models()
print(models)

Complete example

import asyncio
from kellyapi import KellyAPI

async def generate_image():
    kelly = KellyAPI(api_key="your_api_key")
    
    # Generate a detailed image
    image_data = await kelly.generate(
        prompt="A futuristic cityscape with flying cars, neon lights, and towering skyscrapers, cyberpunk style, highly detailed",
        negative_prompt="blurry, low quality, distorted",
        model="PhotoPerfect",
        width=1024,
        height=768
    )
    
    # Save the image
    with open("cityscape.png", "wb") as f:
        f.write(image_data)
    
    print("Image generated successfully!")

# Run the async function
asyncio.run(generate_image())

Use cases

Portrait generation

image_data = await kelly.generate(
    prompt="Professional headshot of a confident business woman, studio lighting, sharp focus",
    width=512,
    height=768
)

Artistic landscapes

image_data = await kelly.generate(
    prompt="Fantasy landscape with floating islands, waterfalls, magical atmosphere, oil painting style",
    width=1024,
    height=576
)

Product visualization

image_data = await kelly.generate(
    prompt="Modern wireless headphones on a clean white background, product photography, studio lighting",
    width=1024,
    height=1024
)
The generate() method returns raw image data as bytes. Save it to a file or convert it to a PIL Image object for further processing.
For best results, use detailed prompts with specific descriptors like lighting conditions, art styles, and quality indicators (e.g., “highly detailed”, “sharp focus”, “professional photography”).

Build docs developers (and LLMs) love