To make the call to OpenAI you can use the OpenAI Node API Library which you can import and create a new instance of using:
import OpenAI from "openai";
const openai = new OpenAI({ apiKey: process.env['OPENAI_KEY'] });
To generate your image using DALL·E, call openai.images.generate()
passing in a value for the model
field of "dall-e-3"
. You can read more about image generation in the OpenAI docs.
OpenAI
class using the API key from process.env['OPENAI_KEY']
.openai.images.generate()
passing in a prompt asking DALLE to generate a cartoon image of your subject. Set the response_format
field to "url"
to get the result as a hosted image url.gptResponse.data[0].url
and return it in the result's body
field.