4Z API

Python DALL·E

Overview

The API provides three main features:

  1. Text-to-image (DALL·E 3 and DALL·E 2)
  2. Image edit (DALL·E 2 only)
  3. Image variations (DALL·E 2 only)

1. Image generation

Basic usage

from openai import OpenAI
client = OpenAI(
    base_url="https://4zapi.com/v1",
    api_key=key
)

response = client.images.generate(
  model="gpt-image-2",
  prompt="a white siamese cat",
  size="1024x1024",
  quality="standard",
  n=1,
)

image_url = response.data[0].url

Parameters

  • Sizes: 1024x1024, 1024x1792, 1792x1024
  • Quality: standard (default), hd (DALL·E 3 only)
  • Count:
    • DALL·E 3: 1 image per request
    • DALL·E 2: up to 10 images per request

2. Image edit (DALL·E 2)

Example

from openai import OpenAI
client = OpenAI(
    base_url="https://4zapi.com/v1",
    api_key=key
)

response = client.images.edit(
  model="gpt-image-2",
  image=open("sunlit_lounge.png", "rb"),
  mask=open("mask.png", "rb"),
  prompt="A sunlit indoor lounge area with a pool containing a flamingo",
  n=1,
  size="1024x1024"
)
image_url = response.data[0].url

Requirements

  • Image and mask must be PNG
  • Must be square
  • File size < 4MB
  • Image and mask must share the same dimensions

3. Variations (DALL·E 2)

Example

from openai import OpenAI
client = OpenAI(
    base_url="https://4zapi.com/v1",
    api_key=key
)

response = client.images.create_variation(
  model="gpt-image-2",
  image=open("corgi_and_cat_paw.png", "rb"),
  n=1,
  size="1024x1024"
)

image_url = response.data[0].url

Requirements

  • PNG format
  • Square image
  • File size < 4MB

Prompt tips

DALL·E 3

  • Prompts are auto-optimized
  • You can disable optimization with:
I NEED to test how the tool works with extremely simple prompts. 
DO NOT add any detail, just use it AS-IS:

Notes

Content moderation

  • Strict content policy
  • Violations return errors

Image URLs

  • Valid for 1 hour
  • Base64 output is also available