GPT-Image-2
curl --request POST \
--url https://api.gravitex.ai/v1/images/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"image": [
"<string>"
],
"n": 123,
"size": "<string>",
"quality": "<string>",
"background": "<string>",
"output_format": "<string>",
"output_compression": 123,
"moderation": "<string>",
"user": "<string>"
}
'import requests
url = "https://api.gravitex.ai/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"image": ["<string>"],
"n": 123,
"size": "<string>",
"quality": "<string>",
"background": "<string>",
"output_format": "<string>",
"output_compression": 123,
"moderation": "<string>",
"user": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
image: ['<string>'],
n: 123,
size: '<string>',
quality: '<string>',
background: '<string>',
output_format: '<string>',
output_compression: 123,
moderation: '<string>',
user: '<string>'
})
};
fetch('https://api.gravitex.ai/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gravitex.ai/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'prompt' => '<string>',
'image' => [
'<string>'
],
'n' => 123,
'size' => '<string>',
'quality' => '<string>',
'background' => '<string>',
'output_format' => '<string>',
'output_compression' => 123,
'moderation' => '<string>',
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.gravitex.ai/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": [\n \"<string>\"\n ],\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"output_compression\": 123,\n \"moderation\": \"<string>\",\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.gravitex.ai/v1/images/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": [\n \"<string>\"\n ],\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"output_compression\": 123,\n \"moderation\": \"<string>\",\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gravitex.ai/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": [\n \"<string>\"\n ],\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"output_compression\": 123,\n \"moderation\": \"<string>\",\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyImage Series
GPT-Image-2
OpenAI GPT-Image-2: generations for text-to-image, edits for image-to-image
POST
/
v1
/
images
/
generations
GPT-Image-2
curl --request POST \
--url https://api.gravitex.ai/v1/images/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"image": [
"<string>"
],
"n": 123,
"size": "<string>",
"quality": "<string>",
"background": "<string>",
"output_format": "<string>",
"output_compression": 123,
"moderation": "<string>",
"user": "<string>"
}
'import requests
url = "https://api.gravitex.ai/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"image": ["<string>"],
"n": 123,
"size": "<string>",
"quality": "<string>",
"background": "<string>",
"output_format": "<string>",
"output_compression": 123,
"moderation": "<string>",
"user": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
image: ['<string>'],
n: 123,
size: '<string>',
quality: '<string>',
background: '<string>',
output_format: '<string>',
output_compression: 123,
moderation: '<string>',
user: '<string>'
})
};
fetch('https://api.gravitex.ai/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.gravitex.ai/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'prompt' => '<string>',
'image' => [
'<string>'
],
'n' => 123,
'size' => '<string>',
'quality' => '<string>',
'background' => '<string>',
'output_format' => '<string>',
'output_compression' => 123,
'moderation' => '<string>',
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.gravitex.ai/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": [\n \"<string>\"\n ],\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"output_compression\": 123,\n \"moderation\": \"<string>\",\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.gravitex.ai/v1/images/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": [\n \"<string>\"\n ],\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"output_compression\": 123,\n \"moderation\": \"<string>\",\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.gravitex.ai/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": [\n \"<string>\"\n ],\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"output_compression\": 123,\n \"moderation\": \"<string>\",\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_bodyIntroduction
GPT-Image-2 offers real-world intelligence, multilingual understanding, 4K resolution support and a smart routing layer, exposed through two complementary endpoints:| Endpoint | Focus | Description |
|---|---|---|
POST /v1/images/generations | Text-to-image | Generate images straight from a text prompt โ the recommended entry point for T2I |
POST /v1/images/edits | Image-to-image | Professional editing: inpainting on the source image, multi-reference blending and other fine-grained edits; accepts both JSON and multipart/form-data |
b64_json) plus usage token stats.
Capability comparison
| Capability | OpenAI official API | Gravitex AI (generations endpoint) |
|---|---|---|
| Text-to-image | โ Supported | โ Supported |
| Image-to-image | โ edits endpoint only | โ Additionally supported |
| Mixed text + image input | โ | โ Supported |
In OpenAIโs official definition,
/v1/images/generations for gpt-image-2 is a text-only endpoint: it accepts a text prompt and does not support passing images for image-to-image; official I2I is available only through /v1/images/edits. We have extended /v1/images/generations with image-to-image support โ send a text prompt together with images and the model will re-create, restyle, reference or inpaint based on your input.Authentication
string
required
Bearer Token, e.g.
Bearer sk-xxxxxxxxxxstring
required
application/json for JSON requests; multipart/form-data for file uploadsSupported models
| Model ID | Description |
|---|---|
gpt-image-2 | OpenAI GPT-Image-2, multi-size including 4K, available on both endpoints |
Parameters
Both endpoints accept the same parameter set.string
required
Fixed value
gpt-image-2string
required
Image description (text-to-image) or edit instruction (image-to-image)
string | string[]
Input image(s) for image-to-image. A string for one image, an array for several; URL or base64 data URI. Omit for text-to-image
integer
default:"1"
Number of images to generate,
1-10string
default:"1024x1024"
Image size, see the size table below
string
default:"high"
Image quality:
low, medium, high, autostring
default:"auto"
Background opacity:
auto or opaque. Passing transparent returns an errorstring
default:"png"
Output image format:
png, jpegnumber
default:"100"
Compression level
0โ100, applies to jpeg onlystring
default:"auto"
Moderation strictness:
auto or low (more permissive)string
End-user identifier, used for abuse detection
size values
| Value | Description |
|---|---|
1024x1024 | Square (default) |
1024x1536 | Portrait |
1536x1024 | Landscape |
2880x2880 | 4K square |
2048x3072 | 4K portrait |
3072x2048 | 4K landscape |
Custom WxH | Each dimension must be a multiple of 16; total pixels 655,360 โ 8,294,400 |
quality values
| Value | Description |
|---|---|
low | Low quality, fastest generation |
medium | Medium quality |
high | High quality (default) |
auto | Automatically pick the best quality |
Text-to-image: POST /v1/images/generations
Generate an image from a text description. Pass model and prompt only, and the image is returned at the requested size and quality โ ideal for creative generation and asset production driven purely by text.
Request examples
- Basic
- All parameters
curl -X POST "https://api.gravitex.ai/v1/images/generations" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A white cat running under the stars, cyberpunk style",
"size": "1024x1536",
"quality": "high",
"n": 1
}'
curl -X POST "https://api.gravitex.ai/v1/images/generations" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A beautiful medieval European princess with long golden hair and big blue eyes, wearing an ornate white lace gown and a crystal crown, standing on the balcony of an ancient castle in the sunlight.",
"n": 1,
"size": "2048x1152",
"quality": "medium",
"background": "opaque",
"output_format": "jpeg",
"output_compression": 95,
"moderation": "low",
"user": "biz_test_001"
}'
Response example
{
"created": 1786436787,
"background": "opaque",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUh..."
}
],
"output_format": "png",
"quality": "medium",
"size": "2048x1152",
"usage": {
"input_tokens": 65,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 65
},
"output_tokens": 1413,
"output_tokens_details": {
"image_tokens": 1413,
"text_tokens": 0
},
"total_tokens": 1478
}
}
This endpoint also supports image-to-image. Add an
image field to a text-to-image request (URL or base64 data URI โ a string for one image, an array for several) and the request is routed to the image editing flow automatically: one unified endpoint, no switching required.There is no hard cap on the number of input images โ the limit comes from the upstream total token budget. Each image may be up to 50MB.- Single image
- Multi-image blend
- base64 input
curl -X POST "https://api.gravitex.ai/v1/images/generations" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Add some tulips to this picture",
"image": "https://example.com/input.png",
"n": 1,
"size": "2048x1152",
"quality": "medium",
"background": "opaque",
"output_format": "jpeg",
"output_compression": 95,
"moderation": "low",
"user": "biz_test_001"
}'
curl -X POST "https://api.gravitex.ai/v1/images/generations" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Blend the style of the two images",
"image": [
"https://example.com/input1.jpeg",
"https://example.com/input2.jpeg"
],
"n": 1,
"size": "2048x1152",
"quality": "medium",
"output_format": "jpeg",
"output_compression": 95,
"user": "biz_test_001"
}'
curl -X POST "https://api.gravitex.ai/v1/images/generations" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Summer countryside scenery, clear blue sky with fluffy clouds, a winding clear stream, lush grass on both banks, 8K ultra HD, healing forest style",
"image": "data:image/png;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2...",
"n": 1,
"size": "2048x1152",
"quality": "medium",
"output_format": "jpeg",
"output_compression": 95,
"user": "biz_test_001"
}'
usage.input_tokens_details.image_tokens is greater than 0, reflecting the tokens consumed by the input images:
{
"created": 1786438823,
"background": "opaque",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSU..."
}
],
"output_format": "jpeg",
"quality": "medium",
"size": "2048x1152",
"usage": {
"input_tokens": 1048,
"input_tokens_details": {
"image_tokens": 1024,
"text_tokens": 24
},
"output_tokens": 1413,
"output_tokens_details": {
"image_tokens": 1413,
"text_tokens": 0
},
"total_tokens": 2461
}
}
{
"created": 1786439615,
"background": "opaque",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAACAAAAASACAIA..."
}
],
"output_format": "jpeg",
"quality": "medium",
"size": "2048x1152",
"usage": {
"input_tokens": 2064,
"input_tokens_details": {
"image_tokens": 2048,
"text_tokens": 16
},
"output_tokens": 1413,
"output_tokens_details": {
"image_tokens": 1413,
"text_tokens": 0
},
"total_tokens": 3477
}
}
Image-to-image: POST /v1/images/edits
The standard OpenAI image editing endpoint: re-create, restyle, inpaint or blend multiple references on top of an input image. Accepts both JSON and multipart/form-data.
Option 1: multipart/form-data
Use this to upload local image files directly.Images are passed via
image[] โ use image[] even for a single file.- Single image
- Multiple images
curl -X POST "https://api.gravitex.ai/v1/images/edits" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-F "model=gpt-image-2" \
-F "prompt=Three-view reference sheet of a commercial fashion model, pure white background" \
-F "image[]=@your-local-file.png" \
-F "n=1" \
-F "size=2048x1152" \
-F "quality=medium" \
-F "background=opaque" \
-F "output_format=png" \
-F "output_compression=100" \
-F "moderation=low" \
-F "user=biz_test_001"
curl -X POST "https://api.gravitex.ai/v1/images/edits" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-F "model=gpt-image-2" \
-F "prompt=Three-view reference sheet of a commercial fashion model, pure white background" \
-F "image[]=@your-local-file-1.png" \
-F "image[]=@your-local-file-2.png" \
-F "n=1" \
-F "size=2048x1152" \
-F "quality=medium" \
-F "background=opaque" \
-F "output_format=png" \
-F "output_compression=100" \
-F "moderation=low" \
-F "user=biz_test_001"
Option 2: JSON
Use this to pass image URLs or base64-encoded images. Parameters are identical to image-to-image on the generations endpoint.- Single image
- Multiple images
- base64 input
curl -X POST "https://api.gravitex.ai/v1/images/edits" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Add some tulips to this picture",
"image": "https://example.com/input.png",
"n": 1,
"size": "2048x1152",
"quality": "medium",
"background": "opaque",
"output_format": "jpeg",
"output_compression": 95,
"moderation": "low",
"user": "biz_test_001"
}'
curl -X POST "https://api.gravitex.ai/v1/images/edits" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Blend the style of the two images",
"image": [
"https://example.com/input1.png",
"https://example.com/input2.jpeg"
],
"n": 2,
"size": "2048x1152",
"quality": "medium",
"background": "opaque",
"output_format": "jpeg",
"output_compression": 95,
"moderation": "low",
"user": "biz_test_001"
}'
curl -X POST "https://api.gravitex.ai/v1/images/edits" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Change background to beach sunset",
"image": "data:image/png;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2...",
"n": 1,
"size": "1024x1024",
"quality": "high"
}'
This endpoint also supports text-to-image. Omit the
image field and send only model and prompt: the request is handled as pure text-to-image and returns the same result as /v1/images/generations, so apps already wired to edits can keep a single endpoint.curl -X POST "https://api.gravitex.ai/v1/images/edits" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A white cat running under the stars, cyberpunk style",
"size": "1024x1536",
"quality": "high",
"n": 1
}'
Response fields
Both endpoints return the same structure:| Field | Type | Description |
|---|---|---|
created | integer | Creation timestamp |
background | string | Background type (opaque / auto) |
data | array | Generated images |
data[].b64_json | string | Base64-encoded image data |
output_format | string | Output format (png / jpeg) |
quality | string | Quality actually used |
size | string | Size actually used |
usage | object | Token usage stats |
usage fields
| Field | Description |
|---|---|
input_tokens | Total input tokens (text + image) |
output_tokens | Total output tokens (image output) |
total_tokens | Total tokens |
input_tokens_details.text_tokens | Text input tokens |
input_tokens_details.image_tokens | Image input tokens (0 for T2I, > 0 for I2I) |
- GPT-Image-2 always returns base64-encoded image data (
b64_json);response_format=urlis not supported. output_tokensis entirely image output โ this model produces no text output.- Billing is token-based, with separate unit prices for text input, image input and image output.
Pricing
All prices are in USD per 1M tokens, billed on the usage tokens returned upstream.| Type | Price ($/1M tokens) |
|---|---|
| Text Input Tokens | $5.00 |
| Image Input Tokens | $8.00 |
| Cached Text Input Tokens | $1.25 |
| Cached Image Input Tokens | $2.00 |
| Image Output Tokens | $30.00 |
Notes
- Image generation usually takes 10โ30 seconds, depending on size and quality
- Image data is always returned base64-encoded
- Supported input formats: PNG, JPEG, WebP; output formats: PNG, JPEG
- 4K generation takes noticeably longer โ prefer standard sizes when possible
- Setting
qualitytolowspeeds up generation significantly gpt-image-2always processes input images at high fidelity; theinput_fidelityparameter is neither needed nor supported- Each uploaded image may be up to 50MB
n(number of output images) ranges from 1 to 10- There is no hard cap on input image count โ it is bounded by the upstream total token limit
- The model has no text output;
output_tokensis entirely image output tokens backgroundsupports onlyauto(default) andopaqueโtransparentreturns an error
Related resources
Image generation
Overview of the multi-model image generation API
Image edits
More usage and examples for the edits endpoint
