GPT-Image-2
Generate and edit high-quality images using OpenAI's GPT-Image-2 model with support for reference images and aspect ratio control
Tool Overview
The GPT-Image-2 tool provides access to OpenAI's latest image generation model. It supports text-to-image generation and image editing with reference pictures, delivering high-quality results across a variety of aspect ratios.
Tool Identifier
gpt-image-2-api
Parameters
Required Parameters
prompt
- Type:
string(required) - Description: Text description of the image to generate or edit
- Validation: Must be a non-empty string
- Example:
"A futuristic city skyline at dusk with glowing neon lights"
Optional Parameters
image_list
- Type:
string[](optional) - Default:
[](empty array, text-to-image mode) - Format: Array of complete HTTP/HTTPS URLs (e.g.,
["https://cdn.sjinn.ai/uploads/image.jpg"]) - Validation: If provided, must be an array with non-empty string elements
aspect_ratio
- Type:
string(optional) - Default:
"auto" - Supported Values:
"auto"- Automatically select the optimal aspect ratio"1:1"- Square format"16:9"- Widescreen landscape"9:16"- Portrait mobile"3:2"- Classic landscape"2:3"- Classic portrait
- Validation: If an unsupported value is provided, defaults to
"auto"
Pricing
- 100 credits per task
Request Examples
Text-to-Image
curl -X POST https://sjinn.ai/api/un-api/create_tool_task \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tool_type": "gpt-image-2-api",
"input": {
"prompt": "A futuristic city skyline at dusk with glowing neon lights",
"aspect_ratio": "16:9"
}
}'
Image Editing with Reference
curl -X POST https://sjinn.ai/api/un-api/create_tool_task \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tool_type": "gpt-image-2-api",
"input": {
"prompt": "Make the background a snowy mountain landscape",
"image_list": ["https://cdn.sjinn.ai/uploads/photo.jpg"],
"aspect_ratio": "3:2"
}
}'
Using JavaScript
const response = await fetch('https://sjinn.ai/api/un-api/create_tool_task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
tool_type: 'gpt-image-2-api',
input: {
prompt: 'A futuristic city skyline at dusk with glowing neon lights',
aspect_ratio: '16:9',
},
}),
});
const result = await response.json();
console.log('Task ID:', result.data.task_id);
Using Python
import requests
url = 'https://sjinn.ai/api/un-api/create_tool_task'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'tool_type': 'gpt-image-2-api',
'input': {
'prompt': 'A futuristic city skyline at dusk with glowing neon lights',
'image_list': ['https://cdn.sjinn.ai/uploads/reference.jpg'],
'aspect_ratio': '16:9'
}
}
response = requests.post(url, json=data, headers=headers)
result = response.json()
print('Task ID:', result['data']['task_id'])
Response Examples
Success Response
{
"success": true,
"errorMsg": "",
"error_code": 0,
"data": {
"task_id": "550e8400-e29b-41d4-a716-446655440000"
}
}
Error Response (Invalid Parameters)
{
"success": false,
"errorMsg": "prompt is required",
"error_code": 400
}
Best Practices
-
Prompt Optimization:
- Use detailed, descriptive prompts for best results
- Include style, lighting, and mood descriptions
- Specify camera angle or perspective if needed (e.g., "aerial view", "close-up portrait")
-
Reference Image Usage:
- Provide high-quality, publicly accessible image URLs
- Use reference images to guide style or subject consistency
- Multiple reference images can be combined for complex edits
-
Aspect Ratio Selection:
- Use
"1:1"for social media square posts - Use
"16:9"for banners and widescreen content - Use
"9:16"for mobile/story format - Leave as
"auto"to let the model decide based on the prompt
- Use
