Run Stable Diffusion 3 with an API
Captured source
source ↗Run Stable Diffusion 3 with an API – Replicate blog
Replicate Blog
Run Stable Diffusion 3 with an API
Posted June 12, 2024 by cbh123
Stable Diffusion 3 is the latest text-to-image model from Stability . It has greatly improved performance in image quality, typography, complex prompt understanding, and resource-efficiency. With Replicate, you can run Stable Diffusion 3 with one line of code.
Try Stable Diffusion 3 in our API playground
Before you dive in, try Stable Diffusion 3 in our API playground.
Try tweaking the prompt and see how Stable Diffusion 3 responds. Most models on Replicate have an interactive API playground like this, available on the model page: https://replicate.com/stability-ai/stable-diffusion-3
The API playground is a great way to get a feel for what a model can do, and provides copyable code snippets in a variety of languages to help you get started.
Running Stable Diffusion 3 with JavaScript
You can run Stable Diffusion 3 with our official JavaScript client :
Install Replicate’s Node.js client library
Copy
npm install replicate
Set the REPLICATE_API_TOKEN environment variable
Copy
export REPLICATE_API_TOKEN = r8_9wm **********************************
(You can generate an API token in your account. Keep it to yourself.)
Import and set up the client
Copy
import Replicate from "replicate" ;
const replicate = new Replicate ({ auth: process.env. REPLICATE_API_TOKEN , });
Run stability-ai/stable-diffusion-3 using Replicate’s API. Check out the model’s schema for an overview of inputs and outputs.
Copy
const input = { prompt: "a photo of vibrant artistic graffiti on a wall saying 'SD3 medium'" };
const output = await replicate. run ( "stability-ai/stable-diffusion-3" , { input }); console. log (output);
To learn more, take a look at the guide on getting started with Node.js .
Running Stable Diffusion 3 with Python
You can run Stable Diffusion 3 with our official Python client :
Install Replicate’s Python client library
Copy
pip install replicate
Set the REPLICATE_API_TOKEN environment variable
Copy
export REPLICATE_API_TOKEN = r8_9wm **********************************
(You can generate an API token in your account. Keep it to yourself.)
Import the client
Copy
import replicate
Run stability-ai/stable-diffusion-3 using Replicate’s API. Check out the model’s schema for an overview of inputs and outputs.
Copy
output = replicate.run( "stability-ai/stable-diffusion-3" , input = { "prompt" : "a photo of vibrant artistic graffiti on a wall saying 'SD3 medium'" } ) print (output)
To learn more, take a look at the guide on getting started with Python .
Running Stable Diffusion 3 with cURL
Your can call the HTTP API directly with tools like cURL:
Set the REPLICATE_API_TOKEN environment variable
Copy
export REPLICATE_API_TOKEN = r8_9wm **********************************
(You can generate an API token in your account. Keep it to yourself.)
Run stability-ai/stable-diffusion-3 using Replicate’s API. Check out the model’s schema for an overview of inputs and outputs.
Copy
curl -s -X POST \ -H "Authorization: Bearer $REPLICATE_API_TOKEN " \ -H "Content-Type: application/json" \ -H "Prefer: wait" \ -d $'{ "input": { "prompt": "a photo of vibrant artistic graffiti on a wall saying \' SD3 medium \' " } }' \ https://api.replicate.com/v1/models/stability-ai/stable-diffusion-3/predictions
To learn more, take a look at Replicate’s HTTP API reference docs .
You can also run Stable Diffusion 3 using other Replicate client libraries for Go, Swift, and others .
Keep up to speed
Follow us on Twitter X.
Hop in our Discord to talk SD3.
Happy hacking! 🦙
Next: Replicate Intelligence #3