DALL-E 3 QuickStart API

Test this app for free
463
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
import os
from openai import OpenAI
from pydantic import BaseModel

app = FastAPI()
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])

class ImagePrompt(BaseModel):
    prompt: str

@app.post('/generate-image')
async def generate_image(request: ImagePrompt):
    response = client.images.generate(
      model="dall-e-3",
      prompt=request.prompt,
      size="1024x1024",
      quality="standard",
      n=1,
    )
    image_url = response.data[0].url
    return JSONResponse(content={'image_url': image_url})
Get full code

DALL-E 3 QuickStart API

Created: | Last Updated:

Do you want to integrate with DALL-E 3 quickly? Well, all you need for this API to work is your OpenAI API key and you have a usable DALL-E 3 server in minutes! It takes in a prompt and responds with a URL to your new image.

Introduction to the DALL-E 3 QuickStart API Template

Welcome to the DALL-E 3 QuickStart API template! This template is designed to help you quickly integrate the power of DALL-E 3 into your applications. With just a few simple steps, you can set up a server that takes in a text prompt and responds with a URL to a newly generated image. This is perfect for builders looking to add image generation capabilities to their software without the hassle of complex setup processes.

Getting Started

To begin using this template, click on "Start with this Template" in the Lazy Builder interface. This will pre-populate the code in the Lazy Builder, so you won't need to copy, paste, or delete any code manually.

Initial Setup

Before you can start using the API, you need to set up an environment secret for your OpenAI API key. Here's how to do it:

  • Go to the Environment Secrets tab within the Lazy Builder.
  • Create a new secret with the key OPENAI_API_KEY.
  • Enter your OpenAI API key as the value for this secret. You can obtain this key from the OpenAI website after signing up for an account.

Test: Pressing the Test Button

Once you have set up your environment secret, press the "Test" button in the Lazy Builder. This will deploy your app and launch the Lazy CLI. The CLI will handle the deployment process, so you don't need to worry about installing libraries or setting up your environment.

Using the App

After pressing the "Test" button, Lazy will provide you with a dedicated server link to use the API. If you're using FastAPI, you will also receive a link to the API documentation. Here's how to interact with your new DALL-E 3 server:

  • Send a POST request to the /generate-image endpoint with a JSON body containing the image prompt. For example:

{   "prompt": "A futuristic city skyline at sunset" } * The server will respond with a JSON containing the URL to the generated image. Here's a sample response:

{   "image_url": "https://example.com/generated-image.png" } Use the provided image URL to view or integrate the generated image into your application or service.

Integrating the App

If you want to integrate this API into an external tool or service, you may need to add the API's server link provided by Lazy. Depending on the external tool, you might need to configure certain settings or permissions to allow the tool to send requests to your API. Follow the specific integration steps for the external tool you are using.

That's it! You now have a fully functional DALL-E 3 image generation server ready to be integrated into your applications. Enjoy creating with the power of AI!

Technologies

OpenAI OpenAI