Open API中文文档
  • 介绍
  • Quick Start
  • Reference
    • OpenAI API 参考文档
      • ChatGpt注册方法
      • 介绍
      • 认证
      • 请求组织
      • 发出请求
      • 模型
      • 问答
      • 对话
      • 编辑
      • 图片
      • 嵌入向量
      • 音频
      • 文件
      • 优化模型
      • 内容审核
      • 引擎
      • 参数详情
  • ChatGpt插件开发
  • ChatGpt注册方法
由 GitBook 提供支持
在本页
  • 生成图片
  • 图片编辑
  • 创建图片变体

这有帮助吗?

  1. Reference
  2. OpenAI API 参考文档

图片

给定提示和/或输入图片,模型将生成一个新图片。

生成图片

POST https://api.openai.com/v1/images/generations

给定提示创建图片。

请求示例

curl https://api.openai.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "prompt": "A cute baby sea otter",
    "n": 2,
    "size": "1024x1024"
  }'
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Edit.create(
  model="text-davinci-edit-001",
  input="What day of the wek is it?",
  instruction="Fix the spelling mistakes"
)
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createEdit({
  model: "text-davinci-edit-001",
  input: "What day of the wek is it?",
  instruction: "Fix the spelling mistakes",
});
请求参数
{
  "prompt": "A cute baby sea otter",
  "n": 2,
  "size": "1024x1024"
}
返回结果
{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

请求主体

  • prompt:字符串 必需 所需图像的文本描述。最大长度为1000个字符。

  • n:整数 可选的 默认为1 要生成的图像数量。必须介于1和10之间。

  • size:字符串 可选的 默认为1024x1024 生成的图像大小。必须是256x256、512x512或1024x1024之一。

  • response_format: 字符串 可选的 默认为url 返回生成图像的格式。必须是url或b64_json之一。

  • user: 字符串 可选的 代表您的终端用户的唯一标识符,可帮助OpenAI监视和检测滥用。了解更多。

图片编辑

POST https://api.openai.com/v1/images/edits

给定原始图像和提示,创建编辑或扩展的图像。

请求主体

  • image: 字符串 必需 要编辑的图像。必须是有效的PNG文件,小于4MB且为正方形。如果未提供mask,则图像必须具有透明度,该透明度将用作mask。

  • mask: 字符串 可选的 另一个图像,其中完全透明的区域(例如alpha为零的区域)表明应该在哪里编辑图片。必须是有效的PNG文件,大小不超过4MB,且尺寸与图片相同。

  • prompt: 字符串 必需 最多1000个字符的图像描述文本。

  • n:整数 可选的 默认为1 要生成的图像数量。必须在1和10之间。

  • size:字符串 可选的 默认为1024x1024 生成的图像大小。必须为256x256、512x512或1024x1024之一。

  • response_format:字符串 可选的 默认为url 生成的图像返回的格式。必须是url或b64_json之一。

  • user:字符串 可选的 表示您的最终用户的唯一标识符,可以帮助OpenAI监视和检测滥用。了解更多信息。

请求示例

curl https://api.openai.com/v1/images/edits \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F image="@otter.png" \
  -F mask="@mask.png" \
  -F prompt="A cute baby sea otter wearing a beret" \
  -F n=2 \
  -F size="1024x1024"
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Image.create_edit(
  image=open("otter.png", "rb"),
  mask=open("mask.png", "rb"),
  prompt="A cute baby sea otter wearing a beret",
  n=2,
  size="1024x1024"
)
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createImageEdit(
  fs.createReadStream("otter.png"),
  fs.createReadStream("mask.png"),
  "A cute baby sea otter wearing a beret",
  2,
  "1024x1024"
);
返回结果
{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

创建图片变体

POST https://api.openai.com/v1/images/variations

生成一个给定图像的变体。

请求体

  • image 字符串 必需的 作为变化基础的图像。必须是有效的PNG文件,小于4MB,且为正方形。

  • n 整数 可选的 默认为1 生成图像的数量。必须介于1和10之间。

  • size 字符串 可选的 默认为1024x1024 生成图像的尺寸。必须是256x256、512x512或1024x1024之一。

  • response_format 字符串 可选的 默认为url 生成的图像返回的格式。必须是url或b64_json之一。

  • user 字符串 可选的 表示您的最终用户的唯一标识符,可帮助OpenAI监测和检测滥用。了解更多。

请求示例

curl https://api.openai.com/v1/images/variations \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F image="@otter.png" \
  -F n=2 \
  -F size="1024x1024"
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Image.create_variation(
  image=open("otter.png", "rb"),
  n=2,
  size="1024x1024"
)
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createImageVariation(
  fs.createReadStream("otter.png"),
  2,
  "1024x1024"
);
返回结果
{
  "created": 1589478378,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}
上一页编辑下一页嵌入向量

最后更新于2年前

这有帮助吗?