Prompt
I need a simple SDK for image generation in Python
Latest observation
Oct 11, 2026
OpenAI APIWeb search: off
Sure — here’s a simple, clean Python SDK pattern for image generation that you can use as a starting point.
Minimal Python SDK Design
Features
- Simple
client.generate(...)interface - Easy to extend later
- Supports prompt, size, and count
- Uses
requests
Example SDK
image_sdk/client.py
import requests
class ImageGenerationClient:
def __init__(self, api_key: str, base_url: str = "https://api.example.com"):
self.api_key = api_key
self.base_url = base_url.rstrip("/")
def generate(self, prompt: str, size: str = "1024x1024", n: int = 1):
url = f"{self.base_url}/v1/images/generate"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
payload = {
"prompt": prompt,
"size": size,
"n": n,
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
return response.json()
image_sdk/__init__.py
from .client import ImageGenerationClient
__all__ = ["ImageGenerationClient"]
Usage
from image_sdk import ImageGenerationClient
client = ImageGenerationClient(api_key="your-api-key")
result = client.generate(
prompt="a futuristic city at sunset",
size="1024x1024",
n=1
)
print(result)
Optional: More SDK-Like Structure
If you want it to feel like a proper SDK, you can add:
exceptions.pymodels.pyconfig.py- async support with
httpx - image download helpers
- type hints and dataclasses
Better Version with Type Hints
from typing import Any, Dict
import requests
class ImageGenerationClient:
def __init__(self, api_key: str, base_url: str = "https://api.example.com"):
self.api_key = api_key
self.base_url = base_url.rstrip("/")
def generate(self, prompt: str, size: str = "1024x1024", n: int = 1) -> Dict[str, Any]:
url = f"{self.base_url}/v1/images/generate"
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json",
}
payload = {"prompt": prompt, "size": size, "n": n}
response = requests.post(url, json=payload, headers=headers, timeout=60)
response.raise_for_status()
return response.json()
If you want, I can also provide:
- a full package structure (
setup.py/pyproject.toml) - async version using
httpx - a wrapper for OpenAI-style image generation APIs
- a more polished SDK with retries, errors, and docs
If you want, I can generate the full SDK folder structure for you next.