创建图片生成并等待结果
curl --request POST \
--url https://apiany.ai/v1/images/generations/sync \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-image-2",
"prompt": "<string>",
"size": "<string>",
"quality": "auto",
"n": 1,
"aspect_ratio": "<string>",
"input_images": [
"<string>"
],
"callback_url": "<string>"
}
'import requests
url = "https://apiany.ai/v1/images/generations/sync"
payload = {
"model": "gpt-image-2",
"prompt": "<string>",
"size": "<string>",
"quality": "auto",
"n": 1,
"aspect_ratio": "<string>",
"input_images": ["<string>"],
"callback_url": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-image-2',
prompt: '<string>',
size: '<string>',
quality: 'auto',
n: 1,
aspect_ratio: '<string>',
input_images: ['<string>'],
callback_url: '<string>'
})
};
fetch('https://apiany.ai/v1/images/generations/sync', 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://apiany.ai/v1/images/generations/sync",
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' => 'gpt-image-2',
'prompt' => '<string>',
'size' => '<string>',
'quality' => 'auto',
'n' => 1,
'aspect_ratio' => '<string>',
'input_images' => [
'<string>'
],
'callback_url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://apiany.ai/v1/images/generations/sync"
payload := strings.NewReader("{\n \"model\": \"gpt-image-2\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"quality\": \"auto\",\n \"n\": 1,\n \"aspect_ratio\": \"<string>\",\n \"input_images\": [\n \"<string>\"\n ],\n \"callback_url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://apiany.ai/v1/images/generations/sync")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-image-2\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"quality\": \"auto\",\n \"n\": 1,\n \"aspect_ratio\": \"<string>\",\n \"input_images\": [\n \"<string>\"\n ],\n \"callback_url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiany.ai/v1/images/generations/sync")
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 = "{\n \"model\": \"gpt-image-2\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"quality\": \"auto\",\n \"n\": 1,\n \"aspect_ratio\": \"<string>\",\n \"input_images\": [\n \"<string>\"\n ],\n \"callback_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"data": [
{
"url": "<string>",
"b64_json": "<string>",
"revised_prompt": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"input_tokens": 123,
"output_tokens": 123,
"cached_input_tokens": 123
}
}{
"task_id": "task_123",
"poll_url": "/v1/tasks/task_123",
"model": "<string>"
}{
"error": {
"message": "<string>",
"param": "<string>",
"code": "<string>"
}
}Images
创建图片生成并等待结果
创建图片任务,并在配置的最大等待时间内等待任务完成。
POST
/
v1
/
images
/
generations
/
sync
创建图片生成并等待结果
curl --request POST \
--url https://apiany.ai/v1/images/generations/sync \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-image-2",
"prompt": "<string>",
"size": "<string>",
"quality": "auto",
"n": 1,
"aspect_ratio": "<string>",
"input_images": [
"<string>"
],
"callback_url": "<string>"
}
'import requests
url = "https://apiany.ai/v1/images/generations/sync"
payload = {
"model": "gpt-image-2",
"prompt": "<string>",
"size": "<string>",
"quality": "auto",
"n": 1,
"aspect_ratio": "<string>",
"input_images": ["<string>"],
"callback_url": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-image-2',
prompt: '<string>',
size: '<string>',
quality: 'auto',
n: 1,
aspect_ratio: '<string>',
input_images: ['<string>'],
callback_url: '<string>'
})
};
fetch('https://apiany.ai/v1/images/generations/sync', 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://apiany.ai/v1/images/generations/sync",
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' => 'gpt-image-2',
'prompt' => '<string>',
'size' => '<string>',
'quality' => 'auto',
'n' => 1,
'aspect_ratio' => '<string>',
'input_images' => [
'<string>'
],
'callback_url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://apiany.ai/v1/images/generations/sync"
payload := strings.NewReader("{\n \"model\": \"gpt-image-2\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"quality\": \"auto\",\n \"n\": 1,\n \"aspect_ratio\": \"<string>\",\n \"input_images\": [\n \"<string>\"\n ],\n \"callback_url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://apiany.ai/v1/images/generations/sync")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"gpt-image-2\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"quality\": \"auto\",\n \"n\": 1,\n \"aspect_ratio\": \"<string>\",\n \"input_images\": [\n \"<string>\"\n ],\n \"callback_url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://apiany.ai/v1/images/generations/sync")
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 = "{\n \"model\": \"gpt-image-2\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"quality\": \"auto\",\n \"n\": 1,\n \"aspect_ratio\": \"<string>\",\n \"input_images\": [\n \"<string>\"\n ],\n \"callback_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"data": [
{
"url": "<string>",
"b64_json": "<string>",
"revised_prompt": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"input_tokens": 123,
"output_tokens": 123,
"cached_input_tokens": 123
}
}{
"task_id": "task_123",
"poll_url": "/v1/tasks/task_123",
"model": "<string>"
}{
"error": {
"message": "<string>",
"param": "<string>",
"code": "<string>"
}
}授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
请求体
application/json
- Option 1
- Option 2
Allowed value:
"gpt-image-2"Accepts auto, a positive WIDTHxHEIGHT target, or ratio shorthand such as 16:9. Every non-auto target is mapped to the nearest official popular size: 1024x1024, 1536x1024, 1024x1536, 2048x2048, 2048x1152, 3840x2160, or 2160x3840.
示例:
"auto"
"1024x1024"
"1280x720"
"16:9"
GPT-Image 2 rendering quality.
可用选项:
auto, low, medium, high Number of images to generate. Billing scales with the image count.
必填范围:
1 <= x <= 10Deprecated ratio shorthand. The ratio and compatibility tier are mapped to the nearest official popular size.
Deprecated compatibility tier used to form the target size before nearest-official-size mapping.
可用选项:
1K, 2K, 4K ⌘I