# Gen Img GPT API

Raw request pattern:

```bash
curl -X POST http://192.168.40.11:20128/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $GEN_IMG_API_KEY" \
  -H "Accept: text/event-stream" \
  -d '{"model":"cx/gpt-5.5-image","prompt":"A cute cat wearing a hat","n":1,"size":"auto","quality":"auto","background":"auto","image_detail":"high","output_format":"png"}'
```

Use the script instead of raw curl when possible:

```bash
export GEN_IMG_API_KEY='...'
scripts/gen_img_gpt.py --prompt 'A cute cat wearing a hat' --output cat.png
```

## Reference images

The endpoint accepts an `image` field for reference images. The script exposes this as `--image`, `--input-ref`, or `--image-url`:

```bash
scripts/gen_img_gpt.py \
  --input-ref style.jpg \
  --input-ref character.png \
  --prompt 'Use the first image as style reference and the second as character identity reference. Create a new scene.' \
  --output scene.png
```

Local refs are converted to `data:image/...;base64,...`. URL/data URL refs are passed through. With one ref the script sends `image`; with multiple refs it sends `images` and also keeps the first ref in `image` for compatibility.

The endpoint may return JSON or SSE. The script handles common OpenAI image response fields: `data[0].url`, `data[0].b64_json`, `data[0].base64`, `data[0].image_base64`.
