Generating Images At Scale With OpenAI’s DALL-E via Data Fetcher and Airtable
Some links on this page are affiliate links that will earn us a commission if you decide to purchase their product. If you purchase via one of these links be sure to comment below. We love being able to share the tools we love and hearing about their impact.
On November 3rd, OpenAI released the public beta for their DALL-E image generation model. Image generation from text input has been a significantly evolving use of AI and there are myriad public models on the market today. These tools can do some incredible things, primarily, generating brand-new imagery at scale for a variety of applications.
[su_image_carousel source=”media: 1181,1182,1183″ limit=”3″ slides_style=”minimal” columns=”1″ adaptive=”no” spacing=”yes” align=”center” max_width=”256″ captions=”yes” arrows=”no” dots=”yes” link=”lightbox” target=”blank” autoplay=”3″ speed=”fast” image_size=”medium” class=””]
By the end of this post, you will be able to generate images like those above based on your own inputs at a rate of 10 images per minute or 25 every 5 minutes (OpenAI’s current limitations).
In a previous post detailing how to generate GPT-3 text responses with OpenAI, I gave some details on how to register with OpenAI and get started in their playground. In this post, I will show you how to refine your image inputs and subsequently generate images at scale with OpenAI via their API using Airtable.
Step 1 – Fire up the Image Playground and Refine Inputs
As with the text generation models, generating images requires testing your inputs first as results can be varied by an order of magnitude with images compared to text. Luckily, OpenAI provides a playground for this:
Input prompts significantly impact what you get back. I’ll list out some of the most impactful here:
Prompt | Response |
“An illustration…” | Cartoon image |
“Has the word ‘dall-e’ written on it” | The word ‘dall-e’ will be written on your image |
“Digital art…” | Including this will process image results in a contemporary digital art format |
“3D render” | Will output a 3D render of whatever you describe |
“Vaporwave” | Outputs your images in a vaporwave format |
“Pencil” | Pencil art response |
“Watercolor” | Watercolor art response |
“Oil painting” | Oil painting response |
“Pixel art” | Pixel art response |
The potential for what we can generate is incredible.
I always loved the artwork on old Hedkandi records and so for the purpose of this demonstration, I will try to yield a series of sunset beach images in the Hedkandi style, at scale, using the DALL-E API.
Step 2 – Create a New Table in Airtable
SIGN UP to Airtable via this referral link.
Next, I am going to create a new table in Airtable and input my prompt variations. The first column will contain my prompt. In my example, I have also included a second column denoting the preferred image dimensions. It’s important to note that the only sizes you can generate for images are as follows: ‘256×256’, ‘512×512’, ‘1024×1024’.
You can find documentation for OpenAI’s image generation API here. As the tool is still in beta the docs are a little bit limited but there are code snippets for cURL, JS, and Python. We need to send a POST request with bearer authentication, headers, and a body, so I will provide all the syntax to manage this simply for our input values in the next step.
Step 3 – Launch Data Fetcher and Build POST API Call
Now that we have our prompts, we can launch the data fetcher extension within Airtable and build our call. We will build the call with the following prompts:
- Application = Custom
- Method = POST
- URL = https://api.openai.com/v1/images/generations
- Authorization = Bearer Token (the value of your bearer token will be your API key which can be found/generated here)
- Headers –> Add
- Header = Content-Type
- Value = application/json
- Body (JSON) = {
“n”: 1,
“size”: “***Table 1*Size***”,
“prompt”: “***Table 1*Name***”
}
The last section here defines the parameters required for the images we’re creating. We’re going to be using our predefined dynamic references for the “prompt” and “size” parameters, hence why those references begin with three asterisks ***. Be sure to amend your dynamic references to the table name and column names you have created (if different from mine).
We’re using the “/v1/images/generations” endpoint for this exercise but there are additional endpoints available:
- Generations (what we’re using)
- Edits (for amending existing images from a source) – POST https://api.openai.com/v1/images/edits
- Variations (for providing varieties of existing images from a source) – POST https://api.openai.com/v1/images/variations
Here’s a demo of building the API call:
Step 4 – Run the API Call
And finally, click run and watch the magic happen:
Images at scale. For the purpose of this exercise, I set “n” to 1 whereas if I wanted multiple variations output I could have expanded that value. When working with APIs you’ll often find that any date/time response will be in UNIX format. To convert that to a friendly date use a formula in a new column that looks something like this: (((A1/60)/60)/24)+DATE(1970,1,1).
Here’s a preview of the images we got back (compressed). Some of them are definitely better than others but by expanding variations and refining inputs we can get what we need.
[su_image_carousel source=”media: 1221,1222,1219,1220″ limit=”4″ slides_style=”minimal” columns=”1″ adaptive=”no” spacing=”yes” align=”center” max_width=”256″ captions=”yes” arrows=”no” dots=”yes” link=”lightbox” target=”blank” autoplay=”3″ speed=”fast” image_size=”medium” class=””]
Pricing
Size (resolution) | Cost |
---|---|
1024×1024 | $0.020 per image |
512×512 | $0.018 per image |
256×256 | $0.016 per image |
OpenAI has a fantastic product. If you need more API credits it’s a pay-by-use model and you can set team access and spending limits with ease.
Let me know if there are any questions in the comments below and tell me how you plan to use this in your projects!