Back to Blog
Tutorial
5 min read
Getting Started with Z Image API Python SDK
Complete guide to integrate Z Image API into your Python projects. Learn installation, setup, and basic usage in under 10 minutes.
Introduction
Z Image API is a powerful image generation service with an easy-to-use Python SDK. This tutorial will guide you through your first image generation in minutes.
Installation
Install the Z Image API Python package using pip:
pip install zimageapi
Quick Start
Here's the simplest example showing how to generate your first image:
from zimageapi import ZImageAPI
# Initialize API client
api = ZImageAPI(api_key="your_api_key_here")
# Generate image
result = api.generate(
prompt="A cute cat sitting by the window",
width=1024,
height=1024
)
# Save image
result.save("output.png")
print("Image generated and saved!")
Configuration Options
Z Image API provides rich configuration options to customize your image generation:
- prompt: Image description text (required)
- width: Image width, default 1024
- height: Image height, default 1024
- style: Image style (optional)
- num_images: Number of images to generate, default 1
Advanced Usage
Generate multiple images in batch:
results = api.generate(
prompt="Futuristic city skyline",
width=1920,
height=1080,
num_images=4
)
for i, result in enumerate(results):
result.save(f"city_{i}.png")
Error Handling
It's recommended to add proper error handling:
try:
result = api.generate(prompt="Beautiful sunset")
result.save("sunset.png")
except Exception as e:
print(f"Generation failed: {e}")
Next Steps
Now that you've mastered the basics, you can:
- Explore advanced features
- Check out the complete documentation
- Visit pricing page to get API access