Run your first serverless endpoint with Stable Diffusion
Before we begin, ensure you have a RunPod API key, available under your user settings. This key is crucial for identification and billing purposes. Keep it secure! Also, remember to retrieve your results via the status endpoint within 30 minutes, as your inputs and outputs are not stored longer than this for privacy protection.
Overview
In this section, we’ll explore how RunPod’s API works. It’s asynchronous, meaning that when you send a request, you get a job ID back almost instantly. Next, we’ll show you how to use this job ID to check the status and retrieve your results.
Let’s dive into an example using the Stable Diffusion v1 inference endpoint.
Create a serverless worker
First, let’s set up your serverless worker. Begin by selecting Quick Deploy on the RunPod interface. Then choose Start from the Stable Diffusion v1.5 options. Pick a GPU, say a 24 GB GPU, and click Deploy. Here’s an example endpoint you might use: https://api.runpod.ai/v2/{ID}/runsync
Start Your Job
Now, to initiate a job, you’ll make a request like the one shown below. This sends your parameters to the API and starts the process.
Upon doing this, you’ll receive a response like this, containing your unique job ID:
Check the Status of Your Job
Since your initial response doesn’t include the output, a subsequent call is necessary. Use your job ID to check the job’s status as follows:
If your job is still processing, the response will indicate that. Here’s an example:
Get Completed Job Status
Once your job is complete, you’ll receive a final response like this:
To save the output, use the following command:
Remember, you have up to 1 hour to retrieve your results via the status endpoint for privacy reasons.
Get Your Results
Finally, to view your results, decode the base64 image from the output. Here’s how you can do it in Python:
Congratulations! You’ve now successfully used RunPod’s Stable Diffusion API to generate images.