Overview

The DALL·E class provides a simple and convenient way to interact with the DALL·E 3 API. It allows you to generate images based on a prompt and receive the generated image as a texture.

Sample Scene

The best way to get started with the DALL·E API is to open the [Demo] DALL-E (Image Generation) scene in the Assets/AiToolbox/Samples/Runtime Usage/[Demo] DALL-E (Image Generation) folder. This scene demonstrates how to use the DALL·E class to send requests to the DALL·E API and receive the response.

The [Demo] DALL·E Image Generation scene

The API Key, Model, and other settings are exposed in the Inspector panel. More info, please scroll down to the Parameters Class section.

The settings for DALL·E Image Generation demo scene, Inspector panel

Quick Start

To generate images in code instead of the component above, you can use the static methods of the Dalle class.

Request

Sends a request to DALL·E and receives the response. The response is provided in the completeCallback function. If the request fails, the failureCallback function is called.

public static Action Request(string prompt,
                             DalleParameters parameters,
                             Action<Texture2D> completeCallback,
                             Action<long, string> failureCallback)

Parameters

  • prompt: Description of the image to generate, e.g., “A cat sitting on a table”.
  • parameters: Settings of the request, represented by a Parameters object.
  • completeCallback: The function to be called on successful completion. The generated texture is provided as a parameter.
  • failureCallback: The function to be called on failure. Error code and message are provided as parameters. See Error Handling for more information.

Returns

  • A function that can be called to cancel the request.

CancelAllRequests

Cancels all pending requests to the DALL·E API.

public static void CancelAllRequests()

Parameters Class

Represents the settings for the AI Toolbox DALL·E requests.

The best way to use the Parameters class is to expose it as a public field in a MonoBehaviour class. This way you can set the parameters in the Unity Inspector.

using AiToolbox;
using UnityEngine;

public class DalleExample : MonoBehaviour {
    public Parameters parameters;
    <...>
}

You can also create a Parameters instance is to use one of the constructors. The Parameters class also provides a copy constructor that can be used to create a copy of an existing Parameters instance.

Properties

  • apiKey: The API key for DALL·E. This property is required. You can find your API key on the API Keys page.
  • apiKeyEncryption: The encryption method for the API key. This property is optional. The default value is ApiKeyEncryption.None.
  • apiKeyRemoteConfigKey: The remote configuration key for the API key. This property is required if apiKeyEncryption is set to ApiKeyEncryption.RemoteConfig. This value is the key of the remote configuration entry in Unity Remote Config that contains the API key.
  • apiKeyEncryptionPassword: The password used for API key encryption. This property is required if apiKeyEncryption is set to ApiKeyEncryption.Encrypted. This value is used to encrypt the API key before it is stored in the Unity scene.
  • model: The DALL·E model to use for the request.
  • size: The size of the image to generate. The default value is 1024x1024. All sizes supported by the DALL·E API are listed.
  • quality: The quality of the image to generate. The default value is standard. The quality options are standard and hd.

Pricing

The up-to-date DALL·E pricing can be found in the “Image models” section of the OpenAI Documentation.

Having Issues?

If you have any questions or need help with the Moderation functionality in AI Toolbox, please contact us.

Comments