curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "gpt-image-2-official",
prompt: "An ancient castle beneath a starry sky",
size: "16:9",
resolution: "2k",
quality: "high",
n: 1,
};
const headers = {
Authorization: "Bearer <token>",
"Content-Type": "application/json",
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error("Error:", error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.apimart.ai/v1/images/generations"
payload := map[string]interface{}{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer <token>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.apimart.ai/v1/images/generations";
String payload = """
{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = "https://api.apimart.ai/v1/images/generations";
$payload = [
"model" => "gpt-image-2-official",
"prompt" => "An ancient castle beneath a starry sky",
"size" => "16:9",
"resolution" => "2k",
"quality" => "high",
"n" => 1
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer <token>",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'json'
require 'uri'
url = URI("https://api.apimart.ai/v1/images/generations")
payload = {
model: "gpt-image-2-official",
prompt: "An ancient castle beneath a starry sky",
size: "16:9",
resolution: "2k",
quality: "high",
n: 1
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json
response = http.request(request)
puts response.body
import Foundation
let url = URL(string: "https://api.apimart.ai/v1/images/generations")!
let payload: [String: Any] = [
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
]
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: payload)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
if let data = data, let responseString = String(data: data, encoding: .utf8) {
print(responseString)
}
}
task.resume()
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var url = "https://api.apimart.ai/v1/images/generations";
var payload = @"{
""model"": ""gpt-image-2-official"",
""prompt"": ""An ancient castle beneath a starry sky"",
""size"": ""16:9"",
""resolution"": ""2k"",
""quality"": ""high"",
""n"": 1
}";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");
var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() async {
final url = Uri.parse('https://api.apimart.ai/v1/images/generations');
final payload = {
'model': 'gpt-image-2-official',
'prompt': 'An ancient castle beneath a starry sky',
'size': '16:9',
'resolution': '2k',
'quality': 'high',
'n': 1,
};
final response = await http.post(
url,
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
},
body: jsonEncode(payload),
);
print(response.body);
}
library(httr)
library(jsonlite)
url <- "https://api.apimart.ai/v1/images/generations"
payload <- list(
model = "gpt-image-2-official",
prompt = "An ancient castle beneath a starry sky",
size = "16:9",
resolution = "2k",
quality = "high",
n = 1
)
response <- POST(
url,
add_headers(
Authorization = "Bearer <token>",
`Content-Type` = "application/json"
),
body = toJSON(payload, auto_unbox = TRUE),
encode = "raw"
)
cat(content(response, "text"))
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KPTXXXXXXXXXXXXXXX"
}
]
}
{
"error": {
"code": 400,
"message": "Invalid parameters: size not allowed / resolution not supported / pixel violation, etc.",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "Insufficient account balance, please top up and try again",
"type": "payment_required"
}
}
{
"error": {
"code": 403,
"message": "Access forbidden, you do not have permission to access this resource",
"type": "permission_error"
}
}
{
"error": {
"code": 429,
"message": "Too many requests, please try again later",
"type": "rate_limit_error"
}
}
{
"error": {
"code": 500,
"message": "Internal server error, please try again later",
"type": "server_error"
}
}
{
"error": {
"code": 502,
"message": "Bad gateway, the server is temporarily unavailable",
"type": "bad_gateway"
}
}
GPT-Image-2
GPT-Image-2 Official Channel Pembuatan Gambar
- Model resmi OpenAI
gpt-image-2, berbasis protokol kompatibel/v1/images/generations - Pemrosesan asinkron, mengembalikan
task_iduntuk kueri berikutnya - Text-to-image / image-to-image / inpainting (mask) dalam satu API
- Mendukung latar belakang transparan PNG / WebP (kanal alfa)
- Bidang tier
resolutionbaru — pilihan 1K / 2K / 4K - 15 rasio aspek didukung di seluruh tier 1K / 2K / 4K
- Hingga 4 gambar per permintaan, hingga 16 gambar referensi
- Keselarasan parameter 95% dengan
gpt-image-1.5-official— migrasi hanya perlu mengubah nama model
POST
/
v1
/
images
/
generations
curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "gpt-image-2-official",
prompt: "An ancient castle beneath a starry sky",
size: "16:9",
resolution: "2k",
quality: "high",
n: 1,
};
const headers = {
Authorization: "Bearer <token>",
"Content-Type": "application/json",
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error("Error:", error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.apimart.ai/v1/images/generations"
payload := map[string]interface{}{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer <token>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.apimart.ai/v1/images/generations";
String payload = """
{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = "https://api.apimart.ai/v1/images/generations";
$payload = [
"model" => "gpt-image-2-official",
"prompt" => "An ancient castle beneath a starry sky",
"size" => "16:9",
"resolution" => "2k",
"quality" => "high",
"n" => 1
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer <token>",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'json'
require 'uri'
url = URI("https://api.apimart.ai/v1/images/generations")
payload = {
model: "gpt-image-2-official",
prompt: "An ancient castle beneath a starry sky",
size: "16:9",
resolution: "2k",
quality: "high",
n: 1
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json
response = http.request(request)
puts response.body
import Foundation
let url = URL(string: "https://api.apimart.ai/v1/images/generations")!
let payload: [String: Any] = [
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
]
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: payload)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
if let data = data, let responseString = String(data: data, encoding: .utf8) {
print(responseString)
}
}
task.resume()
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var url = "https://api.apimart.ai/v1/images/generations";
var payload = @"{
""model"": ""gpt-image-2-official"",
""prompt"": ""An ancient castle beneath a starry sky"",
""size"": ""16:9"",
""resolution"": ""2k"",
""quality"": ""high"",
""n"": 1
}";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");
var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() async {
final url = Uri.parse('https://api.apimart.ai/v1/images/generations');
final payload = {
'model': 'gpt-image-2-official',
'prompt': 'An ancient castle beneath a starry sky',
'size': '16:9',
'resolution': '2k',
'quality': 'high',
'n': 1,
};
final response = await http.post(
url,
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
},
body: jsonEncode(payload),
);
print(response.body);
}
library(httr)
library(jsonlite)
url <- "https://api.apimart.ai/v1/images/generations"
payload <- list(
model = "gpt-image-2-official",
prompt = "An ancient castle beneath a starry sky",
size = "16:9",
resolution = "2k",
quality = "high",
n = 1
)
response <- POST(
url,
add_headers(
Authorization = "Bearer <token>",
`Content-Type` = "application/json"
),
body = toJSON(payload, auto_unbox = TRUE),
encode = "raw"
)
cat(content(response, "text"))
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KPTXXXXXXXXXXXXXXX"
}
]
}
{
"error": {
"code": 400,
"message": "Invalid parameters: size not allowed / resolution not supported / pixel violation, etc.",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "Insufficient account balance, please top up and try again",
"type": "payment_required"
}
}
{
"error": {
"code": 403,
"message": "Access forbidden, you do not have permission to access this resource",
"type": "permission_error"
}
}
{
"error": {
"code": 429,
"message": "Too many requests, please try again later",
"type": "rate_limit_error"
}
}
{
"error": {
"code": 500,
"message": "Internal server error, please try again later",
"type": "server_error"
}
}
{
"error": {
"code": 502,
"message": "Bad gateway, the server is temporarily unavailable",
"type": "bad_gateway"
}
}
curl --request POST \
--url https://api.apimart.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}'
import requests
url = "https://api.apimart.ai/v1/images/generations"
payload = {
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1/images/generations";
const payload = {
model: "gpt-image-2-official",
prompt: "An ancient castle beneath a starry sky",
size: "16:9",
resolution: "2k",
quality: "high",
n: 1,
};
const headers = {
Authorization: "Bearer <token>",
"Content-Type": "application/json",
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error("Error:", error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.apimart.ai/v1/images/generations"
payload := map[string]interface{}{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer <token>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.apimart.ai/v1/images/generations";
String payload = """
{
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = "https://api.apimart.ai/v1/images/generations";
$payload = [
"model" => "gpt-image-2-official",
"prompt" => "An ancient castle beneath a starry sky",
"size" => "16:9",
"resolution" => "2k",
"quality" => "high",
"n" => 1
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer <token>",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'json'
require 'uri'
url = URI("https://api.apimart.ai/v1/images/generations")
payload = {
model: "gpt-image-2-official",
prompt: "An ancient castle beneath a starry sky",
size: "16:9",
resolution: "2k",
quality: "high",
n: 1
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json
response = http.request(request)
puts response.body
import Foundation
let url = URL(string: "https://api.apimart.ai/v1/images/generations")!
let payload: [String: Any] = [
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"n": 1
]
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: payload)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
if let data = data, let responseString = String(data: data, encoding: .utf8) {
print(responseString)
}
}
task.resume()
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var url = "https://api.apimart.ai/v1/images/generations";
var payload = @"{
""model"": ""gpt-image-2-official"",
""prompt"": ""An ancient castle beneath a starry sky"",
""size"": ""16:9"",
""resolution"": ""2k"",
""quality"": ""high"",
""n"": 1
}";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");
var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() async {
final url = Uri.parse('https://api.apimart.ai/v1/images/generations');
final payload = {
'model': 'gpt-image-2-official',
'prompt': 'An ancient castle beneath a starry sky',
'size': '16:9',
'resolution': '2k',
'quality': 'high',
'n': 1,
};
final response = await http.post(
url,
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json',
},
body: jsonEncode(payload),
);
print(response.body);
}
library(httr)
library(jsonlite)
url <- "https://api.apimart.ai/v1/images/generations"
payload <- list(
model = "gpt-image-2-official",
prompt = "An ancient castle beneath a starry sky",
size = "16:9",
resolution = "2k",
quality = "high",
n = 1
)
response <- POST(
url,
add_headers(
Authorization = "Bearer <token>",
`Content-Type` = "application/json"
),
body = toJSON(payload, auto_unbox = TRUE),
encode = "raw"
)
cat(content(response, "text"))
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KPTXXXXXXXXXXXXXXX"
}
]
}
{
"error": {
"code": 400,
"message": "Invalid parameters: size not allowed / resolution not supported / pixel violation, etc.",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 402,
"message": "Insufficient account balance, please top up and try again",
"type": "payment_required"
}
}
{
"error": {
"code": 403,
"message": "Access forbidden, you do not have permission to access this resource",
"type": "permission_error"
}
}
{
"error": {
"code": 429,
"message": "Too many requests, please try again later",
"type": "rate_limit_error"
}
}
{
"error": {
"code": 500,
"message": "Internal server error, please try again later",
"type": "server_error"
}
}
{
"error": {
"code": 502,
"message": "Bad gateway, the server is temporarily unavailable",
"type": "bad_gateway"
}
}
Otorisasi
string
wajib
Semua endpoint memerlukan autentikasi Bearer TokenDapatkan API Key Anda:Kunjungi halaman manajemen API Key untuk mendapatkan API Key AndaSertakan di header permintaan:
Authorization: Bearer YOUR_API_KEY
Body
string
default:"gpt-image-2-official"
wajib
Nama model pembuatan gambarTetap sebagai
gpt-image-2-official (model resmi OpenAI gpt-image-2)boolean
default:"false"
Menentukan apakah moderasi konten dijalankan sebelum tugas gambar dikirim.
true: periksa prompt dan gambar input denganomni-moderation-latestfalseatau dihilangkan: tidak mengirim permintaan moderasi, tanpa biaya atau latensi moderasi tambahan (default)
string
wajib
Deskripsi teks untuk pembuatan gambar
- Mendukung bahasa Inggris dan Mandarin; deskripsi yang terperinci direkomendasikan
- Moderasi konten / tinjauan keamanan sebelum pengiriman — pelanggaran langsung ditolak
string
default:"1:1"
Rasio aspek gambarSecara eksternal menggunakan nilai rasio; secara internal dipetakan ke piksel aktual sesuai
resolution.Rasio yang didukung, ditambah auto agar server memilih rasio yang sesuai secara otomatis:auto- Otomatis (server memilih rasio berdasarkan prompt / gambar referensi)1:1- Persegi (default, avatar sosial / logo)3:2- Lanskap (rasio DSLR umum)2:3- Potret (poster vertikal)4:3- Lanskap (monitor klasik / slideshow)3:4- Potret5:4- Lanskap4:5- Potret (post vertikal Instagram)16:9- Lanskap (thumbnail video layar lebar)9:16- Potret (layar penuh ponsel / sampul video pendek)2:1- Lanskap (banner web)1:2- Potret3:1- Lanskap (banner ultra-lebar)1:3- Potret (poster ekstra tinggi)21:9- Lanskap (ultra-lebar sinematik)9:21- Potret
1881x836 / 887x1774.Saat
size diatur ke auto, rasio default adalah 1:1.string
default:"1k"
Tier resolusi (bidang baru)Mengontrol kejernihan output aktual.
1k- Baseline 1024, hemat biaya untuk penggunaan harian (default)2k- Baseline 2048, cocok untuk poster / kebutuhan definisi tinggi4k- Baseline 3840, mendukung 15 rasio pada tabel pemetaan di bawah
4K mendukung 15 rasio dalam tabel pemetaan di bawah; Anda juga dapat meneruskan dimensi piksel dari tabel langsung melalui
size.string
default:"auto"
Kualitas gambar
auto- Otomatis (default, biasanya setara denganlow)low- Cepat dan ekonomis, cukup untuk garis besar kasarmedium- Seimbanghigh- Presisi maksimum (4K + high can take >120s)
string
default:"auto"
Mode latar belakang
auto- Otomatis (default)opaque- Opaquetransparent- Meminta latar belakang transparan; output menyertakan kanal alfa
string
default:"auto"
Kekuatan moderasi
auto- Kekuatan moderasi defaultlow- Moderasi lebih longgar
string
default:"png"
Format output
png- Format default, mendukung latar belakang transparanjpeg- File lebih kecil, tidak mendukung kanal alfawebp- Mendukung latar belakang transparan, cocok untuk browser modern
Jika
background bernilai transparent, hanya png atau webp yang dapat dipilih.integer
Level kompresi output, rentang
0-100- Hanya efektif untuk
jpeg/webp
integer
default:"1"
Jumlah gambar yang akan dibuatRentang:
1 ~ 4Harus berupa angka murni (misalnya
1), jangan bungkus dengan tanda kutiparray
Array URL gambar referensi
Tampilkan Detail
Tampilkan Detail
- Maksimal 20 MB per gambar, batas total 256 MB
- Hingga 16 gambar referensi; lebih dari itu akan ditolak
- Harus berupa URL gambar yang dapat diakses publik dan stabil
string
URL gambar mask, digunakan untuk inpainting
- Harus digunakan bersama
image_urls
- Pastikan gambar mask memiliki kanal Alpha sebelum mengunggah.
- Dimensi gambar mask harus cocok dengan gambar referensi pertama.
Pemetaan Ukuran × Resolusi
size × resolution → piksel aktual OpenAI (15 ratios × 3 tiers):
| size | 1k | 2k | 4k |
|---|---|---|---|
1:1 | 1024×1024 | 2048×2048 | 2880×2880 |
3:2 | 1536×1024 | 2048×1360 | 3520×2336 |
2:3 | 1024×1536 | 1360×2048 | 2336×3520 |
4:3 | 1024×768 | 2048×1536 | 3312×2480 |
3:4 | 768×1024 | 1536×2048 | 2480×3312 |
5:4 | 1280×1024 | 2560×2048 | 3216×2576 |
4:5 | 1024×1280 | 2048×2560 | 2576×3216 |
16:9 | 1536×864 | 2048×1152 | 3840×2160 |
9:16 | 864×1536 | 1152×2048 | 2160×3840 |
2:1 | 2048×1024 | 2688×1344 | 3840×1920 |
1:2 | 1024×2048 | 1344×2688 | 1920×3840 |
3:1 | 1881×836 / 1536×512 | 3072×1024 | 3840×1280 |
1:3 | 887×1774 / 512×1536 | 1024×3072 | 1280×3840 |
21:9 | 2016×864 | 2688×1152 | 3840×1648 |
9:21 | 864×2016 | 1152×2688 | 1648×3840 |
Catatan: Beberapa dimensi diperkirakan berdasarkan kelipatan 16 dan batas piksel, seperti3:2/2:3@ 2K sebesar 2048×1360 dan21:9@ 4K sebesar 3840×1648. Gunakan piksel aktual dalam tabel sebagai sumber kebenaran.
Contoh Penggunaan
Text-to-image (permintaan minimal){
"model": "gpt-image-2-official",
"prompt": "An ancient castle beneath a starry sky"
}
{
"model": "gpt-image-2-official",
"prompt": "A cute cartoon orange cat sticker, full body, thick white outline, flat vector style, isolated on a fully transparent background",
"size": "1:1",
"resolution": "1k",
"quality": "medium",
"background": "transparent",
"output_format": "png",
"n": 1
}
{
"model": "gpt-image-2-official",
"prompt": "Remove the background, keep only the product, isolated on a fully transparent background",
"image_urls": ["https://your-cdn.com/product.jpg"],
"size": "1:1",
"resolution": "1k",
"background": "transparent",
"output_format": "png"
}
{
"model": "gpt-image-2-official",
"prompt": "Cyberpunk night scene",
"size": "16:9",
"resolution": "2k",
"quality": "high",
"output_format": "jpeg",
"output_compression": 90
}
{
"model": "gpt-image-2-official",
"prompt": "Snow mountain sunrise panorama",
"size": "16:9",
"resolution": "4k",
"quality": "high",
"n": 1
}
{
"model": "gpt-image-2-official",
"prompt": "Fuse the two reference images into a single illustration poster, preserving the main silhouettes",
"size": "1:1",
"quality": "high",
"image_urls": [
"https://your-cdn.com/input-a.png",
"https://your-cdn.com/input-b.png"
]
}
{
"model": "gpt-image-2-official",
"prompt": "Replace the background with a desert sunset",
"size": "1:1",
"quality": "medium",
"image_urls": ["https://your-cdn.com/photo.png"],
"mask_url": "https://your-cdn.com/mask.png"
}
{
"model": "gpt-image-2-official",
"prompt": "Four minimalist poster variations of a red fox",
"size": "1:1",
"quality": "low",
"n": 4
}
{
"model": "gpt-image-2-official",
"prompt": "wide cinematic shot",
"size": "3840x2160",
"quality": "high"
}
Respons
integer
Kode status respons
array
Mengueri Hasil Tugas
Setelah pengiriman berhasil,task_id dikembalikan. Polling status tugas melalui GET /v1/tasks/{task_id}; lihat API Kueri Tugas untuk detail.
Contoh Respons Berhasil
{
"code": 200,
"data": {
"actual_time": 14,
"completed": 1784607890,
"cost": 0.004792,
"created": 1784607876,
"credits_cost": 0.047920000000000004,
"estimated_time": 60,
"id": "task_01KPTXXXXXXXXXXXXXXX",
"progress": 100,
"result": {
"images": [
{
"expires_at": 1784694290,
"url": [
"https://upload.apimart.ai/f/image/xxxxxxxx-gpt_image_2_official_task_xxx_0.png"
]
}
]
},
"status": "completed",
"usage": {
"input_tokens": 22,
"input_tokens_details": {
"cached_tokens": 0,
"image_tokens": 0,
"text_tokens": 22
},
"output_tokens": 196,
"output_tokens_details": {
"image_tokens": 196,
"text_tokens": 0
},
"total_tokens": 218
}
}
}
usage menunjukkan penggunaan token yang ditagih untuk permintaan ini:
| Field | Deskripsi |
|---|---|
input_tokens | Total token input yang digunakan |
input_tokens_details.cached_tokens | Token input yang dilayani dari cache |
input_tokens_details.image_tokens | Token yang digunakan oleh gambar input |
input_tokens_details.text_tokens | Token yang digunakan oleh teks input (prompt) |
output_tokens | Total token output yang digunakan |
output_tokens_details.image_tokens | Token yang digunakan oleh gambar yang dihasilkan |
output_tokens_details.text_tokens | Token yang digunakan oleh teks output |
total_tokens | Total token, sama dengan input_tokens + output_tokens |
output_tokens_details.image_tokens biasanya sama dengan output_tokens. Pada contoh di atas, total_tokens = 22 + 196 = 218.
Alur status tugas: submitted → in_progress → completed / failed.
Akses gambar: data.result.images[0].url[0].⌘I