GPT-Image-2 Image Generation (OpenAI-HK)
API Configuration
- Base URL:
https://api.openai-hk.com - Auth:
Bearer hk-{API_KEY} - Endpoints:
- Text-to-image:
POST /v1/images/generations - Image-to-image:
POST /v1/images/edits
Quick Start
# Text-to-image
curl https://api.openai-hk.com/v1/images/generations \
-H "Authorization: Bearer hk-$API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "your prompt",
"n": 1,
"size": "1024x1024",
"quality": "low"
}'
Available Models
| Model | Description |
|---|
| ------- | ------------- |
gpt-image-2 | Latest GPT image generation v2 |
gpt-image-1.5 | Previous version |
gpt-image-1 | Original GPT image |
Quality Options
| Quality | Description | Approx Cost |
|---|
| --------- | ------------- | -------------- |
low | Fast, ~800 credits (1024x1024) | 800 积分 |
medium | Balanced, ~3000 credits | 3000 积分 |
high | Maximum quality | Higher |
auto | Model decides (default) | - |
Size Options
Square
1024x1024 (1K)2048x2048 (2K)2880x2880 (4K)
Widescreen 16:9
1280x720 (1K)2048x1152 (2K)3840x2160 (4K)
Story 9:16
720x1280 (1K)1152x2048 (2K)2160x3840 (4K)
Other Ratios
5:4, 4:5, 4:3, 3:4, 3:2, 2:3, 21:9
Image Generation Script
# Text-to-image
python3 /root/.openclaw/workspace/skills/hk-gpt-image-2/scripts/generate_image.py \
--api-key "hk-xxx" \
--prompt "一只可爱的橘猫" \
--model gpt-image-2 \
--size 1024x1024 \
--quality low \
--output "/root/.openclaw/media/images/$(date +%Y-%m-%d)-$RANDOM.png"
# Image-to-image (edit)
python3 /root/.openclaw/workspace/skills/hk-gpt-image-2/scripts/generate_image.py \
--api-key "hk-xxx" \
--prompt "把这只猫变成蓝色" \
--input-image /path/to/cat.png \
--output "/root/.openclaw/media/images/$(date +%Y-%m-%d)-$RANDOM.png"
Workflows
Text-to-Image (文生图)
- User provides prompt
- Choose model (default:
gpt-image-2), size (default: 1024x1024), quality (default: low) - Call
/v1/images/generations - Download and save image to
/root/.openclaw/media/images/ - Deliver to user
Image-to-Image (图生图)
- User provides reference image(s) and prompt
- Call
/v1/images/edits with multipart form - Download and save result
- Deliver to user
Notes
- Default output directory:
/root/.openclaw/media/images/ - Filename format:
YYYY-MM-DD-RANDOM.png - Max reference images for edit: Multiple (no strict limit)
- For best quality, use
quality: high but costs more credits - Response format supports both
url (default) and b64_json