GPT Image Series Images API
Generate images from text or edit an existing image using the endpoints below.
Generate images
Overview
Use the image generation endpoint to create images from a text prompt.
POST /v1/images/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Supported models
| Model | Description |
|---|---|
gpt-image-2 | GPT Image 2 image generation model (exclusive to the image and image-4k groups) |
gpt-image-2-5 | GPT Image 2.5 image generation model, -flare/-sunburst |
gpt-image-2-6 | GPT Image 2.6 image generation model with GIF and SVG output support, -flare/-sunburst |
Request parameters
<ParamTable params={[
{ name: "model", type: "string", required: true, description: 'Model name, such as gpt-image-2, gpt-image-2-6, gpt-image-2-vip, or gpt-image-2-official. Use a name from the current model list for your group' },
{ name: "prompt", type: "string", required: true, description: "A text description of the desired image, up to 1,000 characters" },
{ name: "n", type: "integer", required: false, description: "Number of images requested, from 1 to 10. Results for the gpt-image-2 family depend on upstream capabilities; compatible channels commonly return one image per request. Check data.length in the response" },
{ name: "size", type: "string", required: false, description: "Image size: auto (default), 1024x1024 (square), 1536x1024 (landscape), 1024x1536 (portrait), 2048x2048 (2K square), 2048x1152 (2K landscape), 3840x2160 (4K landscape), or 2160x3840 (4K portrait)" },
{ name: "quality", type: "string", required: false, description: "Image quality: auto (default), low, medium, or high" },
{ name: "response_format", type: "string", required: false, description: 'Response format: url (default) or b64_json. The GPT Image 2.6 family also supports both to return a URL and Base64 together' },
{ name: "output_format", type: "string", required: false, description: 'For the gpt-image-2-6 family (including -flare/-sunburst), use gif for animation or svg for static vectors. Omit to use the model default. Image encoding is independent of delivery through response_format' },
]} />
The longest edge must not exceed 3,840 pixels. Each edge must be a multiple of 16 pixels, the aspect ratio must not exceed 3:1, and the total pixel count must be between 655,360 and 8,294,400.
Response format and image count
response_format: "url"returns hosted image URLs indata[].url.response_format: "b64_json"returns base64 image data indata[].b64_json.- When an upstream provider returns base64 data or a
data:image/...;base64,...URL internally, the gateway normalizes the client response according toresponse_format.- Base64 image results may still be cached internally for logs and downloads, but the client response remains
b64_jsonwhenresponse_formatis set tob64_json.- The
nparameter can only be set to1.
Header parameters
<ParamTable params={[
{ name: "X-New-Api-Async-Task", type: "string", required: false, description: "Set to true or 1 to submit image generation as an async task. The API returns a task_id immediately; use async tasks to check status and results. Omit it to keep the default synchronous image response." },
]} />
Request examples
cURL
curl https://api.nbility.ai/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "X-New-Api-Async-Task: true" \
-d '{
"model": "gpt-image-2",
"prompt": "A panda riding a bicycle with a backpack that says I love China",
"n": 1,
"size": "1024x1024",
"response_format": "url"
}'
Python
import requests
response = requests.post(
"https://api.nbility.ai/v1/images/generations",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
"X-New-Api-Async-Task": "true",
},
json={
"model": "gpt-image-2",
"prompt": "A panda riding a bicycle with a backpack that says I love China",
"n": 1,
"size": "1024x1024",
"response_format": "url",
},
)
print(response.json())
Node.js
const response = await fetch('https://api.nbility.ai/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'X-New-Api-Async-Task': 'true',
},
body: JSON.stringify({
model: 'gpt-image-2',
prompt: 'A panda riding a bicycle with a backpack that says I love China',
n: 1,
size: '1024x1024',
response_format: 'url',
}),
});
console.log(await response.json());
Go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
body := []byte(`{
"model":"gpt-image-2",
"prompt":"A panda riding a bicycle with a backpack that says I love China",
"n":1,
"size":"1024x1024",
"response_format":"url"
}`)
req, _ := http.NewRequest("POST", "https://api.nbility.ai/v1/images/generations", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-New-Api-Async-Task", "true")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
var body = """
{
\"model\": \"gpt-image-2\",
\"prompt\": \"A panda riding a bicycle with a backpack that says I love China\",
\"n\": 1,
\"size\": \"1024x1024\",
\"response_format\": \"url\"
}
""";
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.nbility.ai/v1/images/generations"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.header("X-New-Api-Async-Task", "true")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
GIF output
For GPT Image 2.6, set output_format: "gif" to request GIF output, and use response_format to choose URL or Base64 delivery:
curl https://api.nbility.ai/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2-6",
"prompt": "A seamless looping animated GIF of a blue ball bouncing on a white background",
"n": 1,
"output_format": "gif",
"response_format": "url"
}'
- A GIF normally occupies one
dataitem, with its contact sheet available throughorigin_image_url. Also handle older responses that return the contact sheet separately; use the actual image results. data[].output_formatidentifies each item's encoding. Use itswidth,height, orsizefor the actual dimensions; the animation and contact sheet may have different dimensions.- GIF URLs can be previewed or downloaded directly. Save GIF
b64_jsonbytes as.gif, or embed them withdata:image/gif;base64,.... - Image caching preserves the original GIF bytes and every animation frame without converting to PNG. Image counts follow returned image results, not the number of frames inside a GIF.
SVG output
The GPT Image 2.6 family (including -flare / -sunburst) supports static vector output with output_format: "svg" on both generation and edit endpoints:
curl https://api.nbility.ai/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2-6",
"prompt": "A minimalist bakery logo, circular badge, warm line art",
"output_format": "svg",
"response_format": "b64_json",
"n": 1
}'
response_formatacceptsurl,b64_json, orboth. Decoding the Base64 yields complete UTF-8 SVG XML; save it as.svgor embed it withdata:image/svg+xml;base64,....- Streaming and multiple images are supported. Each finished image arrives in an
image_generation.completedevent with a URL, Base64, or both according toresponse_format. output_compressionhas no effect on SVG. Image caching preserves the original vector bytes without rasterizing them.- SVG is an output format and cannot be used as a reference image. Results are static vectors; the generation service removes scripts, external resources, embedded bitmaps, and animation.
- For multipart edits, pass
-F output_format=svg. Source images and masks must still meet the model-specific input requirements.
Async response example
When X-New-Api-Async-Task: true is set, the API returns task information:
{
"code": "success",
"message": "success",
"data": {
"task_id": "task_xxx",
"status": "submitted"
}
}
Async task query
Use GET /v1/images/tasks/:task_id to query an async image generation or image edit task created with X-New-Api-Async-Task: true.
GET /v1/images/tasks/{task_id}
Authorization: Bearer YOUR_API_KEY
cURL
curl https://api.nbility.ai/v1/images/tasks/task_xxx \
-H "Authorization: Bearer YOUR_API_KEY"
Python
import requests
response = requests.get(
"https://api.nbility.ai/v1/images/tasks/task_xxx",
headers={"Authorization": "Bearer YOUR_API_KEY"},
)
print(response.json())
Node.js
const response = await fetch('https://api.nbility.ai/v1/images/tasks/task_xxx', {
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
},
});
console.log(await response.json());
The response includes task status and, after completion, image result fields such as image_urls and result_url when available.
{
"code": "success",
"message": "success",
"data": {
"task_id": "task_xxx",
"status": "succeeded",
"status_raw": "SUCCESS",
"action": "generations",
"progress": "100%",
"submit_time": 1745711800,
"start_time": 1745711802,
"finish_time": 1745711868,
"result_url": "https://domain.com/cdn/20250427/uj1ojiZ9c1tR4PPbeV5Ts0pEu357py.png",
"image_urls": [
"https://domain.com/cdn/20250427/uj1ojiZ9c1tR4PPbeV5Ts0pEu357py.png"
]
}
}
If generation succeeded but the file was not saved, follow task and download recovery. Resume polling or saving; investigate an uncertain submission before generating again.
Response example
{
"created": 1745711868,
"data": [
{
"revised_prompt": "A panda riding a bicycle with a backpack that says I love China",
"url": "https://domain.com/cdn/20250427/uj1ojiZ9c1tR4PPbeV5Ts0pEu357py.png"
}
]
}
Edit images
Overview
Use the image editing endpoint with a source image, an optional mask, and a prompt.
POST /v1/images/edits
Authorization: Bearer YOUR_API_KEY
Content-Type: multipart/form-data
Supported models
| Model | Description |
|---|---|
gpt-image-2 | GPT Image 2 image generation model (exclusive to the image and image-4k groups) |
gpt-image-2-5 | GPT Image 2.5 image generation model |
gpt-image-2-6 | GPT Image 2.6 image generation model with GIF and SVG output support |
Request parameters
<ParamTable params={[
{ name: "model", type: "string", required: true, description: 'Model name, such as gpt-image-2, gpt-image-2-6, gpt-image-2-vip, or gpt-image-2-official. Use a name from the current model list for your group' },
{ name: "image", type: "file", required: true, description: "The image to edit. It must be a valid, square PNG smaller than 4 MB. If no mask is supplied, the image must contain transparency to identify the area to edit" },
{ name: "mask", type: "file", required: false, description: "An optional mask. Fully transparent areas indicate where to edit. It must be a valid PNG smaller than 4 MB with the same dimensions as the source image" },
{ name: "prompt", type: "string", required: true, description: "A text description of the desired image, up to 1,000 characters" },
{ name: "n", type: "string", required: false, description: "Number of images requested, from 1 to 10" },
{ name: "size", type: "string", required: false, description: 'Image size: auto (default), 1024x1024 (square), 1536x1024 (landscape), 1024x1536 (portrait), 2048x2048 (2K square), 2048x1152 (2K landscape), 3840x2160 (4K landscape), or 2160x3840 (4K portrait)' },
{ name: "quality", type: "string", required: false, description: "Image quality: auto (default), low, medium, or high" },
{ name: "response_format", type: "string", required: false, description: 'Response format: url (default) or b64_json. The GPT Image 2.6 family also supports both' },
{ name: "output_format", type: "string", required: false, description: 'For the gpt-image-2-6 family, use gif or svg, for example -F output_format=svg. SVG is output-only; source images and masks must still meet the model-specific input requirements' },
{ name: "user", type: "string", required: false, description: "A unique end-user identifier that can help monitor and detect abuse" },
]} />
The longest edge must not exceed 3,840 pixels. Each edge must be a multiple of 16 pixels, the aspect ratio must not exceed 3:1, and the total pixel count must be between 655,360 and 8,294,400.
Request examples
cURL
curl https://api.nbility.ai/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F 'model="gpt-image-2"' \
-F 'image=@"input.png"' \
-F 'prompt="Merge the two images naturally into one composition"' \
-F 'n="1"' \
-F 'size="1024x1024"' \
-F 'response_format="url"'
Python
import requests
with open("input.png", "rb") as image_file:
response = requests.post(
"https://api.nbility.ai/v1/images/edits",
headers={"Authorization": "Bearer YOUR_API_KEY"},
data={
"model": "gpt-image-2",
"prompt": "Merge the two images naturally into one composition",
"n": "1",
"size": "1024x1024",
"response_format": "url",
},
files={"image": image_file},
)
print(response.json())
Node.js
import fs from 'node:fs';
import FormData from 'form-data';
const form = new FormData();
form.append('model', 'gpt-image-2');
form.append('image', fs.createReadStream('input.png'));
form.append('prompt', 'Merge the two images naturally into one composition');
form.append('n', '1');
form.append('size', '1024x1024');
form.append('response_format', 'url');
const response = await fetch('https://api.nbility.ai/v1/images/edits', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
...form.getHeaders(),
},
body: form,
});
console.log(await response.json());
Go
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
w.WriteField("model", "gpt-image-2")
w.WriteField("prompt", "Merge the two images naturally into one composition")
w.WriteField("n", "1")
w.WriteField("size", "1024x1024")
w.WriteField("response_format", "url")
fw, _ := w.CreateFormFile("image", "input.png")
f, _ := os.Open("input.png")
io.Copy(fw, f)
f.Close()
w.Close()
req, _ := http.NewRequest("POST", "https://api.nbility.ai/v1/images/edits", &buf)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", w.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}
Response example
{
"created": 1589478378,
"data": [
{
"url": "https://domain.com/cdn/20250427/uj1ojiZ9c1tR4PPbeV5Ts0pEu357py.png"
}
]
}