Create an app using Automatic1111 API mode
Learn from Thierry Moreau, Co-Founder at OctoML, how to go from a concept to the implementation of a web app using SDXL with Automatic1111 in API mode. Key learnings are using Automatic1111 in API mode, navigating the FastAPI documentation, and using the correct SDXL inputs to get consistently high quality results.
Automatic1111 API mode
Previously, we learned how to create a prototype for an app using Automatic1111 and Stable Diffusion WebUI in GUI mode, and now we are going to move from prototype to implementation using Automatic1111 Stable Diffusion WebUI in API mode.
Accessing the Automatic1111 WebUI Fast API documentation
We launched the WebUI GUI from an OctoAI endpoint that was running an Automatic1111 WebUI container.
To recap here’s how we did this:
Sign up for an OctoAI account.
Once you’re logged in, go to Compute Service -> My Endpoints -> Create a Custom Endpoint.
Name your endpoint
Use the following container image:
258175030240.dkr.ecr.us-east-1.amazonaws.com/template-images:sdwebui-tools-v0.1.2
Enable public access
Select the medium hardware tier
Under “configure autoscaling” set min and max replicas to 1
Leave the rest of the fields to their default values and launch your endpoint hy hitting Create!
We could then access the tool by taking the OctoAI endpoint URL and pasting it in our browser. Now to use Automatic1111 WebUI in API mode, simply append /docs to the OctoAI endpoint URL. This gives us access to the FastAPI documentation for setting up your text to image generation web app.
Test out the API with a quick test
Once you’re on the FastAPI documentation page, scroll down to access the /sdapi/v1/txt2img
documentation for posting text to image inference requests. We’ll rely on this Automatic1111 WebUI feature to build your web app.
Click to open the parameters of the API, inspect the payload schema
Click “Try it out” to access the JSON
Optional, but a bit of clean up on the JSON object
Keep fields
“Prompt”: “”
“Negative_prompt”: “”
“Styles”: [
“String” ],
“Seed”: -1
“Steps”: 50
“Width”: 512
“Height”: 512
Remove fields all other fields. Automatic1111 will leave them to their default settings.
Your new JSON object should look like this:
Now start adding in your attributes, as we did in the last video when we were using Automatic1111 in GUI mode. You may need to still access the Automatic1111 web UI to properly copy over the styles strings. We are trying to reproduce the image output from the last video:
After clicking on execute it posts to our endpoint, you should see the cURL usage example below. This is handy in case you want to test the API from a terminal.
Go back to the OctoAI endpoint logs you can see all the request information sent. Go back to the FastAPI tab, and note the 200 response, copy the Response body image field into the Base64 to Image tool so you can see a visual of the payload. Tip: don’t forget to remove the quotation marks!
You will also see extra parameters returned to the user which provides us with generation information to recreate the exact same image (e.g. the seed that Automatic1111 used to generate that exact image).
Building a Next.JS app that uses Auatomatic1111 in API mode
Access the octoai-apps github repo to follow simple instructions for launching your own A1111-powered web app! Follow the README noting you will need to run a Docker container on your development machine/laptop that is hosting your next.js app in it. Pass the Automatic1111 endpoint URL you launched using OctoAI. Open the app > api > predictions > route.ts file, to see the JSON payload matches the example we tested above. You can modify that payload as you wish to customize your very own SDXL powered webapp!
Coming up next
OctoAI has accelerated SDXL, so you get fast image generations. But, what if there was a way to make your app even faster? Check out the next demo in the series to learn how to accelerate your SDXL app.
Share what you build
We are excited to see what you build — feel free to show us in our Discord, and see what other community members are creating.
Your choice of models on our SaaS or in your environment
Run any model or checkpoint on our efficient, reliable, and customizable API endpoints. Sign up and start building in minutes.