ExOpenAI.Images (ex_openai.ex v1.0.4) View Source

Modules for interacting with the images group of OpenAI APIs

API Reference: https://platform.openai.com/docs/api-reference/images

Link to this section Summary

Functions

Creates an image given a prompt.

Creates an edited or extended image given an original image and a prompt.

Creates a variation of a given image.

Link to this section Functions

Link to this function

create_image(prompt, opts \\ [])

View Source

Specs

create_image(String.t(),
  user: String.t(),
  size: :"1024x1024" | :"512x512" | :"256x256",
  response_format: :b64_json | :url,
  n: integer()
) :: {:ok, ExOpenAI.Components.ImagesResponse.t()} | {:error, any()}

Creates an image given a prompt.

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

Method: POST

Docs: https://platform.openai.com/docs/api-reference/images


Required Arguments:

  • prompt: A text description of the desired image(s). The maximum length is 1000 characters.

Example: A cute baby sea otter

Optional Arguments:

  • n: The number of images to generate. Must be between 1 and 10.

Example: 1

  • response_format: The format in which the generated images are returned. Must be one of url or b64_json.

Example: "url"

  • size: The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.

Example: "1024x1024"

  • user: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Example: "user-1234"

Link to this function

create_image_edit(image, prompt, opts \\ [])

View Source

Specs

create_image_edit(bitstring(), String.t(),
  user: String.t(),
  size: :"1024x1024" | :"512x512" | :"256x256",
  response_format: :b64_json | :url,
  n: integer(),
  mask: bitstring()
) :: {:ok, ExOpenAI.Components.ImagesResponse.t()} | {:error, any()}

Creates an edited or extended image given an original image and a prompt.

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

Method: POST

Docs: https://platform.openai.com/docs/api-reference/images


Required Arguments:

  • image: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.

  • prompt: A text description of the desired image(s). The maximum length is 1000 characters.

Example: A cute baby sea otter wearing a beret

Optional Arguments:

  • mask: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where image should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as image.

  • n: The number of images to generate. Must be between 1 and 10.

Example: 1

  • response_format: The format in which the generated images are returned. Must be one of url or b64_json.

Example: "url"

  • size: The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.

Example: "1024x1024"

  • user: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Example: "user-1234"

Link to this function

create_image_variation(image, opts \\ [])

View Source

Specs

create_image_variation(bitstring(),
  user: String.t(),
  size: :"1024x1024" | :"512x512" | :"256x256",
  response_format: :b64_json | :url,
  n: integer()
) :: {:ok, ExOpenAI.Components.ImagesResponse.t()} | {:error, any()}

Creates a variation of a given image.

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

Method: POST

Docs: https://platform.openai.com/docs/api-reference/images


Required Arguments:

  • image: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.

Optional Arguments:

  • n: The number of images to generate. Must be between 1 and 10.

Example: 1

  • response_format: The format in which the generated images are returned. Must be one of url or b64_json.

Example: "url"

  • size: The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.

Example: "1024x1024"

  • user: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Example: "user-1234"