Core API
Image API
Image requests use dedicated Images endpoints. KHaiXAPI currently supports OpenAI gpt-image-2 for image generation, editing, and asynchronous tasks.
Endpoints and Model
| Purpose | Final endpoint | Available model |
|---|---|---|
| Generation | POST https://api.khaix.net/v1/images/generations | gpt-image-2 |
| Editing | POST https://api.khaix.net/v1/images/edits | gpt-image-2 |
| Authentication | Authorization: Bearer $KHAIX_API_KEY | Uses the same gateway key |
Set the SDK Base URL to https://api.khaix.net/v1. When sending an HTTP request directly, use the complete URL shown above. Do not send gpt-image-2 to a text-model endpoint.
Image Generation
Send the prompt as JSON. The size determines the image tier, and n determines the number of images. Image results are usually returned in data[].b64_json or data[].url; refer to the response for the actual output format.
curl https://api.khaix.net/v1/images/generations \
-H "Authorization: Bearer $KHAIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Create an e-commerce hero image for a precision industrial sensor: brushed metal housing, seamless light-gray studio background, front three-quarter view, softbox lighting, the complete product centered, with no logo, readable text, or watermark",
"size": "1024x1024",
"quality": "high",
"background": "opaque",
"output_format": "png",
"n": 1
}'Other common fields include response_format, moderation, style, output_compression, and streaming-image fields. If model is omitted, Sub2API currently defaults to gpt-image-2 for images.
Image Editing
Edit requests can use JSON image URLs, including data:image/...;base64,..., or multipart file uploads. JSON edits use images[].image_url and optionally mask.image_url. The current implementation does not use OpenAI Files file_id values.
curl https://api.khaix.net/v1/images/edits \
-H "Authorization: Bearer $KHAIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Replace the product image background with a seamless light-gray studio background. Preserve the sensor's metal finish, edges, and natural shadow, and add no logo, readable text, or watermark",
"images": [
{"image_url": "data:image/png;base64,BASE64_DATA"}
],
"mask": {
"image_url": "data:image/png;base64,MASK_BASE64_DATA"
},
"size": "1024x1024",
"n": 1
}'curl https://api.khaix.net/v1/images/edits \
-H "Authorization: Bearer $KHAIX_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Replace the product image background with a seamless light-gray studio background. Preserve the sensor's metal finish, edges, and natural shadow, and add no logo, readable text, or watermark" \
-F "image=@sensor.png" \
-F "mask=@sensor-mask.png" \
-F "size=1024x1024"Asynchronous Tasks
For asynchronous processing, use /v1/images/generations/async or /v1/images/edits/async, then query the status with GET /v1/images/tasks/{task_id}. Asynchronous tasks depend on Sub2API object-storage configuration. Use synchronous endpoints when object storage is disabled; polling uses the same API key.
| Operation | URL | Description |
|---|---|---|
| Create generation task | POST /v1/images/generations/async | Returns a task ID |
| Create edit task | POST /v1/images/edits/async | Supports an image and mask |
| Query task | GET /v1/images/tasks/{task_id} | Returns status and result |
The stream field and asynchronous tasks are separate mechanisms. When task polling is required, do not also depend on a streaming response.
Image Billing
Images do not use the single Token formula applied to text models. Common billing dimensions include the number generated (n), size tier, and quality; edits may also incur image input Tokens. Refer to the current console configuration for final prices, multipliers, group permissions, and image-generation access.
| Model | Billing dimensions | Configuration guidance |
|---|---|---|
gpt-image-2 | 1K / 2K / 4K image output; edits may include image input Tokens | Enter image input / output prices for the channel or group |
Do not treat example prices in the documentation as live upstream prices. Administrators should maintain current channel prices in the Sub2API console, while users should refer to actual request records.
Common Errors
- 400: incompatible model:
gpt-image-2cannot be used in/v1/chat/completionsor text Responses examples. Use an Images endpoint instead. - 403: image generation not allowed: Check that the key's group has
allow_image_generationenabled and that an OpenAI image channel is configured for the group. - 413: request body too large: Compress or resize the Base64 image, or use a multipart file upload.
- Empty result or 502: Keep the request ID, model, and UTC time, then check whether the upstream image channel returned image data.
- 404: path concatenation error: Confirm that the Base URL ends at
/v1to avoid/v1/v1/images.