The stablediffusionapi.com offers API as a service for image generation using various image generation models. Several image generation models are hosted on the servers and they are offered as API so that the users need not take the pain of deploying their models on costly server infrastructure for image generation.
The API allows customers to generate images using state-0f-the art diffusion models like stable diffusion, and several other fine-tuned diffusion models for custom image generation. You can find all the models that are available as API here: Stable Diffusion API models
Currently, the Stable Diffusion API, Dreambooth API, Dreambooth finetuning API, Dreambooth API v4(Beta), and Dreambooth Sandbox APIs are available with different models to choose from. Find more about how to use these APIs in the documentation.
Introducing V5 API
With V5 API you can edit an image with just a prompt. V5 API offers two endpoints pix2pix and depth2img. We can edit the images by passing appropriate parameters to the API. Let's see how each endpoint works below.
Pix2Pix Endpoint
Pix2Pix endpoint lets you edit your image with a prompt. The python code for its implementation is as follows:
import requests
url = "https://stablediffusionapi.com/api/v5/pix2pix"
payload = {"key": "your API key", "init_image": "link to your image", "prompt": "your prompt to edit the image"}
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
In the above code, the requests module in python is used to send a request to the API. We gave the parameters key which is the API key, init_image which is the link to your input image, and finally the prompt parameter which is the instruction for the model to edit the image.
In a similar way, we can use the http.client method to interact with the API. The python code for it is as follows:
import http.client
conn = http.client.HTTPSConnection("stablediffusionapi.com")
payload = {"key": "your API key", "init_image": "link to your image", "prompt": "your prompt to edit the image"}
headers = {}
conn.request("POST", "/api/v5/pix2pix", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Depth2img Endpoint
Depth2img endpoint lets you edit your image with a prompt and also this endpoint preserves the composition of the original image. In this method, a depth map is created which preserves the composition of the original image. The Python implementation of the endpoint using the requests module is as follows:
import requests
url = "https://stablediffusionapi.com/api/v5/depth2img"
payload = {"key": "your API key", "init_image": "link to your image", "prompt": "your prompt to edit the image"}
headers = {}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
We can implement the same with the http.client method as follows:
import http.client
conn = http.client.HTTPSConnection("stablediffusionapi.com")
payload = {"key": "your API key", "init_image": "link to your image", "prompt": "your prompt to edit the image"}
headers = {}
conn.request("POST", "/api/v5/depth2img", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
In this way, we can use the V5 API to edit images.
If you're interested in learning more about the V5 API and how it can be used to edit images, you may also want to explore our guide on "How to edit Images with the V5 API?". This API provides a powerful platform for editing images, including the ability to use prompts to achieve highly specific and creative results. By understanding how to effectively use the V5 API, you can expand your image editing capabilities and achieve the perfect image for your needs. So, if you're looking to take your image editing skills to the next level, be sure to check out our guide on editing images with the V5 API.
Conclusion
Stablediffusionapi offers a lot of models as APIs that are hosted on GPU-based servers. V5 API enables us to edit images using an API.
- The Pix2pix endpoint helps us to edit the image as per the given prompt.
- The Depth2img endpoint helps us to edit the image and also preserves the composition of the original image.
With the latest release of V5 API, AI image editing becomes available for everyone at an affordable price. Check the pricing for different plans on the official website.