| Server IP : 3.147.158.171 / Your IP : 216.73.216.216 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/api/scripts/ |
Upload File : |
"""
Test script for images.edit parameter support with gpt-image-1.5.
Empirically tests which parameters the OpenAI images.edit API actually accepts
for the gpt-image-1.5 model. Each parameter is tested individually, then a
combination test is run with all passing params.
Usage:
cd api
python scripts/test_image_edit.py
Cost: ~$0.50-1.00 in API calls.
"""
import io
import sys
from pathlib import Path
from dotenv import load_dotenv
# Load .env from api/ directory
env_path = Path(__file__).resolve().parent.parent / '.env'
load_dotenv(dotenv_path=env_path)
from openai import OpenAI, BadRequestError
client = OpenAI()
# Individual parameter tests to run
PARAM_TESTS = [
("size (1024x1024)", {"size": "1024x1024"}),
("size (auto)", {"size": "auto"}),
("size (1536x1024)", {"size": "1536x1024"}),
("quality (low)", {"quality": "low"}),
("quality (medium)", {"quality": "medium"}),
("quality (high)", {"quality": "high"}),
("quality (auto)", {"quality": "auto"}),
("output_format (png)", {"output_format": "png"}),
("output_format (jpeg)", {"output_format": "jpeg"}),
("output_format (webp)", {"output_format": "webp"}),
("background (transparent)", {"background": "transparent"}),
("background (opaque)", {"background": "opaque"}),
("background (auto)", {"background": "auto"}),
("input_fidelity (low)", {"input_fidelity": "low"}),
("input_fidelity (high)", {"input_fidelity": "high"}),
]
def generate_source_image() -> bytes:
"""Generate a small source image via images.generate to use as edit input."""
print("Generating source image for edit tests...")
response = client.images.generate(
model="gpt-image-1.5",
prompt="A simple red circle on a white background",
size="1024x1024",
quality="low",
output_format="png",
)
import base64
image_bytes = base64.b64decode(response.data[0].b64_json)
print(f" Source image generated ({len(image_bytes)} bytes)\n")
return image_bytes
def test_edit_param(name: str, extra_kwargs: dict, source_bytes: bytes) -> tuple[bool, str]:
"""Test a single parameter combination against images.edit.
Returns (passed, error_message).
"""
buf = io.BytesIO(source_bytes)
buf.name = "source.png"
try:
client.images.edit(
model="gpt-image-1.5",
prompt="Make the image blue",
image=buf,
**extra_kwargs,
)
return True, ""
except BadRequestError as e:
return False, str(e)
except Exception as e:
return False, f"{type(e).__name__}: {e}"
def main():
print("=" * 60)
print(" images.edit Parameter Test — gpt-image-1.5")
print("=" * 60)
print()
print(f"Tests to run: {len(PARAM_TESTS)}")
print("Estimated cost: ~$0.50-1.00")
print()
confirm = input("Proceed? [y/N] ").strip().lower()
if confirm != 'y':
print("Aborted.")
sys.exit(0)
print()
# Generate source image
source_bytes = generate_source_image()
# Run individual tests
results = []
for name, kwargs in PARAM_TESTS:
sys.stdout.write(f" Testing {name:<30s} ... ")
sys.stdout.flush()
passed, error = test_edit_param(name, kwargs, source_bytes)
status = "PASS" if passed else "FAIL"
print(status)
if error:
print(f" Error: {error[:120]}")
results.append((name, kwargs, passed, error))
# Combination test with all passing params
print()
passing_kwargs = {}
for name, kwargs, passed, _ in results:
if passed:
passing_kwargs.update(kwargs)
if passing_kwargs:
print(f"Running combination test with all passing params: {list(passing_kwargs.keys())}")
sys.stdout.write(" Testing combination ... ")
sys.stdout.flush()
combo_passed, combo_error = test_edit_param("combination", passing_kwargs, source_bytes)
combo_status = "PASS" if combo_passed else "FAIL"
print(combo_status)
if combo_error:
print(f" Error: {combo_error[:120]}")
else:
print("No individual params passed — skipping combination test.")
# Summary
print()
print("=" * 60)
print(" SUMMARY")
print("=" * 60)
print(f" {'Test':<35s} {'Result'}")
print(f" {'-'*35} {'-'*6}")
for name, _, passed, _ in results:
print(f" {name:<35s} {'PASS' if passed else 'FAIL'}")
if passing_kwargs:
print(f" {'combination':<35s} {'PASS' if combo_passed else 'FAIL'}")
print()
pass_count = sum(1 for _, _, p, _ in results if p)
fail_count = len(results) - pass_count
print(f" Passed: {pass_count} Failed: {fail_count}")
print()
if __name__ == "__main__":
main()