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
Génération d'images GPT-Image-2 (canal officiel)
- Modèle officiel OpenAI
gpt-image-2, basé sur le protocole compatible/v1/images/generations - Traitement asynchrone, renvoie un
task_idpour les requêtes ultérieures - Texte-vers-image / image-vers-image / inpainting (mask) — tout-en-un
- Prise en charge des arrière-plans transparents PNG / WebP (canal alpha)
- Nouveau champ de niveau
resolution— sélection 1K / 2K / 4K - 15 ratios d’aspect pris en charge sur les niveaux 1K / 2K / 4K
- Jusqu’à 4 images par requête, jusqu’à 16 images de référence
- Alignement de paramètres à 95 % avec
gpt-image-1.5-official— la migration ne nécessite qu’un changement de nom de modèle
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"
}
}
Autorisations
string
requis
Tous les points de terminaison nécessitent une authentification Bearer TokenObtenir votre clé API :Rendez-vous sur la page de gestion des clés API pour obtenir votre clé APIIncluez-la dans l’en-tête de la requête :
Authorization: Bearer YOUR_API_KEY
Body
string
défaut:"gpt-image-2-official"
requis
Nom du modèle de génération d’imagesFixé à
gpt-image-2-official (modèle officiel OpenAI gpt-image-2)boolean
défaut:"false"
Indique s’il faut modérer le contenu avant d’envoyer la tâche d’image.
true: vérifier les prompts et les images d’entrée avecomni-moderation-latestfalseou omis : ne pas envoyer de requête de modération, sans coût ni latence de modération supplémentaires (par défaut)
string
requis
Description textuelle pour la génération d’images
- Prend en charge l’anglais et le chinois, des descriptions détaillées sont recommandées
- Modération de contenu / examen de sécurité avant soumission — les violations sont rejetées immédiatement
string
défaut:"1:1"
Ratio d’aspect de l’imageÀ l’extérieur, des valeurs de ratio sont utilisées ; en interne, elles sont automatiquement associées aux pixels réels selon
resolution.Ratios pris en charge, plus auto pour laisser le serveur choisir automatiquement un ratio adapté :auto— Automatique (le serveur choisit un ratio selon le prompt / les images de référence)1:1— Carré (par défaut, avatars sociaux / logos)3:2— Paysage (ratio courant de reflex numérique)2:3— Portrait (affiches verticales)4:3— Paysage (moniteur classique / diaporama)3:4— Portrait5:4— Paysage4:5— Portrait (publication Instagram verticale)16:9— Paysage (miniature vidéo grand écran)9:16— Portrait (plein écran téléphone / couverture de vidéo courte)2:1— Paysage (bannière Web)1:2— Portrait3:1— Paysage (bannière ultra-large)1:3— Portrait (affiche extra-haute)21:9— Paysage (ultra-large cinématographique)9:21— Portrait
1881x836 / 887x1774.Lorsque
size est défini sur auto, le ratio par défaut est 1:1.string
défaut:"1k"
Niveau de résolution (nouveau champ)Contrôle la netteté réelle de la sortie.
1k— Base 1024, économique pour une utilisation quotidienne (par défaut)2k— Base 2048, adapté aux affiches / besoins en haute définition4k— Base 3840, prend en charge les 15 ratios du tableau de correspondance ci-dessous
La 4K prend en charge les 15 ratios du tableau de correspondance ci-dessous ; vous pouvez également transmettre les dimensions en pixels du tableau directement via
size.string
défaut:"auto"
Qualité de l’image
auto— Automatique (par défaut, généralement équivalent àlow)low— Rapide et économique, suffisant pour des contours grossiersmedium— Équilibréhigh— Précision maximale (4K + high peut prendre plus de 120 s)
string
défaut:"auto"
Mode d’arrière-plan
auto— Automatique (par défaut)opaque— Opaquetransparent— Demande un arrière-plan transparent ; la sortie contient un canal alpha
string
défaut:"auto"
Force de modération
auto— Force de modération par défautlow— Modération plus permissive
string
défaut:"png"
Format de sortie
png— Format par défaut, prend en charge les arrière-plans transparentsjpeg— Fichiers plus petits, ne prend pas en charge le canal alphawebp— Prend en charge les arrière-plans transparents, adapté aux navigateurs modernes
Lorsque
background vaut transparent, seuls png ou webp peuvent être sélectionnés.integer
Niveau de compression de sortie, plage
0-100- N’est effectif que pour
jpeg/webp
integer
défaut:"1"
Nombre d’images à générerPlage :
1 ~ 4Doit être un nombre brut (par exemple
1), ne pas mettre entre guillemetsarray
Tableau d’URL d’images de référence
Afficher Détails
Afficher Détails
- 20 Mo maximum par image, plafond total de 256 Mo
- Jusqu’à 16 images de référence ; au-delà, sera rejeté
- Doivent être des URL d’images publiquement accessibles et stables
string
URL de l’image de masque, utilisée pour l’inpainting
- Doit être utilisé conjointement avec
image_urls
- Assurez-vous que l’image de masque possède un canal Alpha avant de la téléverser.
- Les dimensions de l’image de masque doivent correspondre à la première image de référence.
Correspondance Size × Resolution
size × resolution → pixels réels OpenAI (15 ratios × 3 niveaux) :
| 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 |
Note : Certaines dimensions sont approximées à des multiples de 16 et à des limites de pixels, comme3:2/2:3@ 2K qui est 2048×1360 et21:9@ 4K qui est 3840×1648. Référez-vous aux pixels réels du tableau comme source de vérité.
Exemples d’utilisation
Texte-vers-image (requête minimale){
"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"
}
Response
integer
Code de statut de la réponse
array
Interrogation des résultats de tâche
Après une soumission réussie, untask_id est renvoyé. Interrogez l’état de la tâche via GET /v1/tasks/{task_id}, voir API d’interrogation des tâches pour plus de détails.
Exemple de réponse en cas de succès
{
"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 indique la consommation de tokens facturée pour cette requête :
| Champ | Description |
|---|---|
input_tokens | Nombre total de tokens d’entrée consommés |
input_tokens_details.cached_tokens | Tokens d’entrée servis depuis le cache |
input_tokens_details.image_tokens | Tokens utilisés par les images d’entrée |
input_tokens_details.text_tokens | Tokens utilisés par le texte d’entrée (prompt) |
output_tokens | Nombre total de tokens de sortie consommés |
output_tokens_details.image_tokens | Tokens utilisés par l’image générée |
output_tokens_details.text_tokens | Tokens utilisés par le texte de sortie |
total_tokens | Nombre total de tokens, égal à input_tokens + output_tokens |
output_tokens_details.image_tokens est généralement égal à output_tokens. Dans l’exemple ci-dessus, total_tokens = 22 + 196 = 218.
Flux de statuts de la tâche : submitted → in_progress → completed / failed.
Accès à l’image : data.result.images[0].url[0].