Image Generation
Provider Disclosure: VoidAI offers image generation services powered by multiple providers, including OpenAI's DALL·E and GPT-Image models, and Black Forest Labs' FLUX models. The specific provider used depends on the model you select in your API call.
Introduction
The Images API provides methods for generating images based on text prompts using various models from different providers. When you make an API call, the request is routed to the appropriate provider's technology.
Generations
The image generations endpoint allows you to create an original image given a text prompt. When using OpenAI's GPT Image, images can have a size of 1024x1024, 1024x1792 or 1792x1024 pixels.
By default, images are generated at hd
quality. Square, standard quality images are the fastest to generate.
You can request 1 image at a time with GPT Image and DALL·E 3 (request more by making parallel requests) or up to 10 images at a time using DALL·E 2 with the n
parameter.
from openai import OpenAI
import base64
client = OpenAI(api_key="yourapikey", base_url="https://api.voidai.app/v1")
prompt = "a white siamese cat"
result = client.images.generate(
model="gpt-image-1",
prompt=prompt,
size="1024x1024",
quality="standard",
n=1,
)
image_url = result.data[0].url
print(image_url)
More Advanced Image Generation
You can also generate images with more specific parameters:
from openai import OpenAI
import base64
client = OpenAI(api_key="yourapikey", base_url="https://api.voidai.app/v1")
result = client.images.generate(
model="gpt-image-1",
prompt="A photorealistic image of a mountain landscape with a lake",
size="1024x1024",
quality="hd",
n=1,
)
image_url = result.data[0].url
print(image_url)
You can also save generated images directly:
from openai import OpenAI
import requests
import os
client = OpenAI(api_key="yourapikey", base_url="https://api.voidai.app/v1")
response = client.images.generate(
model="gpt-image-1",
prompt="A futuristic cityscape at night with neon lights",
size="1024x1024",
quality="standard",
n=1,
)
# Get the image URL
image_url = response.data[0].url
# Download the image
image_response = requests.get(image_url)
image_response.raise_for_status()
# Save the image
with open("generated_image.png", "wb") as file:
file.write(image_response.content)
print(f"Image saved to generated_image.png")