生成图像

在给定提示的情况下创建图像。了解更多。

POST/v1/images/generations/

生成图像

在给定提示的情况下创建图像。[了解更多](https://platform.openai.com/docs/guides/images)。

鉴权: Bearer

请求体

Content-Type: application/json

字段类型必填说明
modelstring用于图像生成的模型。`dall-e-2`、`dall-e-3` 或 `gpt-image-1` 之一。默认为 `dall-e-2`,除非使用特定于 `gpt-image-1` 的参数。
promptstring是所需图像的文本描述。`gpt-image-1` 的最大长度为 32000 个字符,`dall-e-2` 的最大长度为 1000 个字符,`dall-e-3` 的最大长度为 4000 个字符。
ninteger要生成的图像数量。必须介于 1 到 10 之间。对于 `dall-e-3`,仅支持 `n=1`。
sizestring生成的图像的大小。`对于 gpt-image-1`,必须是 `1024x1024`、`1536x1024`(横向)、`1024x1536`(纵向)或`自动`(默认值)之一,`对于 dall-e-2`,必须是 `256x256、``512x512` 或 `1024x1024` 之一,对于 `dall-e-3`,必须是 `1024x1024`、`1792x1024` 或 `1024x1792` 之一。
backgroundstring允许为生成的图像的背景设置透明度。此参数仅支持 `gpt-image-1`。必须是以下之一 `透明`、`不透明`或`自动`(默认值)。使用`自动`时,模型将自动确定图像的最佳背景。 如果`是透明`的,则输出格式需要支持透明度,因此应将其设置为 `png`(默认值)或 `webp`。
moderationstring控制 `gpt-image-1` 生成的图像的内容审核级别。必须为`低,` 以进行限制较少的筛选或`自动`(默认值)。
qualitystring将生成的图像的质量。
streamstring
stylestring
userstring

示例代码

curl -X POST "https://api.nodeprice.com/v1/images/generations/" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
  "model": "string",
  "prompt": "string",
  "n": 0,
  "size": "string",
  "background": "string",
  "moderation": "string",
  "quality": "string",
  "stream": "string",
  "style": "string",
  "user": "string"
}'
const url = "https://api.nodeprice.com/v1/images/generations/";
const body = {
  "model": "string",
  "prompt": "string",
  "n": 0,
  "size": "string",
  "background": "string",
  "moderation": "string",
  "quality": "string",
  "stream": "string",
  "style": "string",
  "user": "string"
};

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
  },
  body: JSON.stringify(body)
});

console.log(await response.text());
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	url := "https://api.nodeprice.com/v1/images/generations/"
	body := strings.NewReader(`{
  "model": "string",
  "prompt": "string",
  "n": 0,
  "size": "string",
  "background": "string",
  "moderation": "string",
  "quality": "string",
  "stream": "string",
  "style": "string",
  "user": "string"
}`)
	req, err := http.NewRequest("POST", url, body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer <token>")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(data))
}
import requests

url = "https://api.nodeprice.com/v1/images/generations/"

body = """{
  "model": "string",
  "prompt": "string",
  "n": 0,
  "size": "string",
  "background": "string",
  "moderation": "string",
  "quality": "string",
  "stream": "string",
  "style": "string",
  "user": "string"
}"""

response = requests.request("POST", url, data=body, headers={
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
})

print(response.text)
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n"
    + "  \"model\": \"string\",\n"
    + "  \"prompt\": \"string\",\n"
    + "  \"n\": 0,\n"
    + "  \"size\": \"string\",\n"
    + "  \"background\": \"string\",\n"
    + "  \"moderation\": \"string\",\n"
    + "  \"quality\": \"string\",\n"
    + "  \"stream\": \"string\",\n"
    + "  \"style\": \"string\",\n"
    + "  \"user\": \"string\"\n"
    + "}");
Request request = new Request.Builder()
    .url("https://api.nodeprice.com/v1/images/generations/")
    .method("POST", body)
    .addHeader("Content-Type", "application/json")
    .addHeader("Authorization", "Bearer <token>")
    .build();

Response response = client.newCall(request).execute();
System.out.println(response.body().string());
#include <stdio.h>
#include <curl/curl.h>

int main(void) {
    CURL *curl = curl_easy_init();
    if (curl == NULL) {
        return 1;
    }

    struct curl_slist *headers = NULL;
    headers = curl_slist_append(headers, "Content-Type: application/json");
    headers = curl_slist_append(headers, "Authorization: Bearer <token>");

    curl_easy_setopt(curl, CURLOPT_URL, "https://api.nodeprice.com/v1/images/generations/");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\n"
        + "  \"model\": \"string\",\n"
        + "  \"prompt\": \"string\",\n"
        + "  \"n\": 0,\n"
        + "  \"size\": \"string\",\n"
        + "  \"background\": \"string\",\n"
        + "  \"moderation\": \"string\",\n"
        + "  \"quality\": \"string\",\n"
        + "  \"stream\": \"string\",\n"
        + "  \"style\": \"string\",\n"
        + "  \"user\": \"string\"\n"
        + "}");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

    CURLcode code = curl_easy_perform(curl);
    if (code != CURLE_OK) {
        fprintf(stderr, "%s\n", curl_easy_strerror(code));
    }

    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
    return 0;
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var client = new HttpClient();
        var request = new HttpRequestMessage(HttpMethod.Post, "https://api.nodeprice.com/v1/images/generations/");
        request.Headers.Add("Authorization", "Bearer <token>");
        request.Content = new StringContent("{\n"
            + "  \"model\": \"string\",\n"
            + "  \"prompt\": \"string\",\n"
            + "  \"n\": 0,\n"
            + "  \"size\": \"string\",\n"
            + "  \"background\": \"string\",\n"
            + "  \"moderation\": \"string\",\n"
            + "  \"quality\": \"string\",\n"
            + "  \"stream\": \"string\",\n"
            + "  \"style\": \"string\",\n"
            + "  \"user\": \"string\"\n"
            + "}", Encoding.UTF8, "application/json");

        var response = await client.SendAsync(request);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}

响应

200 Response

Content-Type: application/json

字段类型必填说明
createdinteger是
dataarray<object>是
[]object
b64_jsonstring
urlstring是
usageobject是
total_tokensinteger是
input_tokensinteger是
output_tokensinteger是
input_tokens_detailsobject是
text_tokensinteger是
image_tokensinteger是