OpenAI -> Generate an image
Action summary
OpenAI -> Generate an image
Function Documentation: OpenAI → Generate an image (Simple)
Overview
This function generates an image using the OpenAI API based on a text prompt, with options for size and model. It is designed to take user input, validate it, and return an image URL if the request is successful.
Inputs
openai_api_key
(registry | text)- Purpose: API key required to authenticate with OpenAI's image generation endpoint.
- Example:
"sk-...your-key-here"
prompt
(text)- Purpose: The text description for the image to generate.
- Example:
"A futuristic city with flying cars"
img_size
(enum)- Purpose: The size of the generated image.
- Options:
"1024x1024"
"1024x1792"
"1792x1024"
model
(enum)- Purpose: The OpenAI model to use for generating the image.
- Options:
"dall-e-3"
"dall-e-2"
Function Stack
1. OpenAI API Request
- Endpoint:
https://api.openai.com/v1/images/generations
- Purpose: Sends a POST request to the OpenAI API with the prompt and image size parameters.
2. Preconditions
- Condition:
openai_api.response.status == 200
- Purpose: Ensures that the request was successful (HTTP 200 status code).
3. OpenAI API Response
- Create Variable:
response
- Purpose: Stores the response from OpenAI API, which contains the URL of the generated image.
Response
- The function returns the generated image URL or image content.
Success response
{
"image_url": "https://api.openai.com/v1/images/abcd1234"
}
Error response
{
"message": "Incorrect API key provided: ssk-None*********************************************GQPD. You can find your API key at https://platform.openai.com/account/api-keys."
}
Example
Input
- Headers:
- Authorization: Bearer
openai_api_key
- Authorization: Bearer
- Body:
{ "prompt": "A futuristic city with flying cars", "size": "1024x1024", "model": "DALL-E" }
Output
{
"image_url": "https://api.openai.com/v1/images/abcd1234"
}
Version notes
2024-10-08 17:55:30
Current