图像生成
curl --request POST \
--url https://openp.ai/v1/images/generationsimport requests
url = "https://openp.ai/v1/images/generations"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://openp.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://openp.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",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openp.ai/v1/images/generations"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openp.ai/v1/images/generations")
.asString();require 'uri'
require 'net/http'
url = URI("https://openp.ai/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyOpenAI 兼容
图像生成
POST /v1/images/generations —— 文生图
POST
/
v1
/
images
/
generations
图像生成
curl --request POST \
--url https://openp.ai/v1/images/generationsimport requests
url = "https://openp.ai/v1/images/generations"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://openp.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://openp.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",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://openp.ai/v1/images/generations"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://openp.ai/v1/images/generations")
.asString();require 'uri'
require 'net/http'
url = URI("https://openp.ai/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_body根据自然语言描述生成图片。
请求
curl https://openp.ai/v1/images/generations \
-H "Authorization: Bearer $OPENPAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A black-and-white pencil sketch of a Shiba Inu wearing glasses",
"size": "1024x1024",
"n": 1,
"quality": "high"
}'
参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | gpt-image-2 / gpt-image-1 / dall-e-3 / dall-e-2 |
prompt | string | ✅ | 文本提示词,最长 4000 字符 |
n | integer | 张数(dall-e-3 仅支持 1) | |
size | string | 1024x1024 / 1792x1024 / 1024x1792(DALL·E 3);gpt-image-1 支持更多 | |
quality | string | standard / hd(dall-e-3) low / medium / high(gpt-image-1) | |
style | string | vivid / natural(dall-e-3) | |
response_format | string | url(默认)或 b64_json | |
background | string | transparent / opaque(gpt-image-1) | |
output_format | string | png / jpeg / webp(gpt-image-1) |
响应
{
"created": 1715750400,
"data": [
{
"url": "https://...",
"revised_prompt": "A pencil sketch in black and white of a Shiba Inu..."
}
]
}
url 链接通常仅在 1 小时内有效,请下载或转存到自有存储。
response_format: "b64_json" 时返回 base64:
{
"data": [{"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."}]
}
DALL·E 3 注意
- 只能
n=1,生成多张请多次调用。 prompt会被模型自动改写,返回的revised_prompt是实际使用的提示词。- 不支持
mask编辑(请使用 images/edits)。
gpt-image-1 注意
- 支持
n > 1,可一次生成多图。 - 支持
quality三档,价格差异明显。 - 支持透明背景(
background: "transparent")。