Run Stable Diffusion 3 with an API
📰 Replicate Blog
Run Stable Diffusion 3 with an API using Replicate's JavaScript or Python client libraries
Action Steps
- Try Stable Diffusion 3 in Replicate's API playground
- Install Replicate's Node.js or Python client library
- Set up the API token and import the client library
- Run Stable Diffusion 3 using the client library and provide a prompt to generate an image
Who Needs to Know This
Developers and data scientists on a team can benefit from using Stable Diffusion 3 with an API to generate high-quality images from text prompts, and product managers can utilize this technology to enhance their products
Key Insight
💡 Stable Diffusion 3 can be easily integrated into applications using Replicate's API and client libraries
Share This
🖼️ Run Stable Diffusion 3 with an API and generate high-quality images from text prompts! 💻
Key Takeaways
Run Stable Diffusion 3 with an API using Replicate's JavaScript or Python client libraries
Full Article
# Run Stable Diffusion 3 with an API – Replicate blog
[Replicate has joined Cloudflare](https://replicate.com/blog/replicate-cloudflare)
[](https://replicate.com/)
cmd+k
[Explore](https://replicate.com/explore)[Pricing](https://replicate.com/pricing)[Enterprise](https://replicate.com/enterprise)[Docs](https://replicate.com/docs)[Blog](https://replicate.com/blog)[Sign in](https://replicate.com/signin)[Try for free](https://replicate.com/signin)
Menu
[Explore](https://replicate.com/explore)[Pricing](https://replicate.com/pricing)[Enterprise](https://replicate.com/enterprise)[Docs](https://replicate.com/docs)[Blog](https://replicate.com/blog)[Sign in](https://replicate.com/signin)[Try for free](https://replicate.com/signin)
* * *
[Compare models in the Playground](https://replicate.com/playground)
* Replicate
* [Blog](https://replicate.com/blog)
# Run Stable Diffusion 3 with an API
Posted June 12, 2024 by
* [cbh123](https://replicate.com/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.
* * *
## [](https://replicate.com/blog/run-stable-diffusion-3-with-an-api#try-stable-diffusion-3-in-our-api-playground)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](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.
## [](https://replicate.com/blog/run-stable-diffusion-3-with-an-api#running-stable-diffusion-3-with-javascript)Running Stable Diffusion 3 with JavaScript
You can run Stable Diffusion 3 with our [official JavaScript client](https://github.com/replicate/replicate-javascript):
Install [Replicate’s Node.js client library](https://github.com/replicate/replicate-javascript)
Copy
`npm install replicate`
Set the `REPLICATE_API_TOKEN` environment variable
Copy
`export REPLICATE_API_TOKEN=r8_9wm**********************************`
(You can generate an [API token](https://replicate.com/account/api-tokens) 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](https://replicate.com/stability-ai/stable-diffusion-3/api/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](https://replicate.com/docs/get-started/nodejs).
## [](https://replicate.com/blog/run-stable-diffusion-3-with-an-api#running-stable-diffusion-3-with-python)Running Stable Diffusion 3 with Python
You can run Stable Diffusion 3 with our [official Python client](https://github.com/replicate/replicate-python):
Install [Replicate’s Python client library](https://github.com/replicate/replicate-python)
Copy
`pip install replicate`
Set the `REPLICATE_API_TOKEN` environment variable
Copy
`export REPLICATE_API_TOKEN=r8_9wm**********************************`
(You can generate an [API token](https://replicate.com/account/api-tokens) 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 th
[Replicate has joined Cloudflare](https://replicate.com/blog/replicate-cloudflare)
[](https://replicate.com/)
cmd+k
[Explore](https://replicate.com/explore)[Pricing](https://replicate.com/pricing)[Enterprise](https://replicate.com/enterprise)[Docs](https://replicate.com/docs)[Blog](https://replicate.com/blog)[Sign in](https://replicate.com/signin)[Try for free](https://replicate.com/signin)
Menu
[Explore](https://replicate.com/explore)[Pricing](https://replicate.com/pricing)[Enterprise](https://replicate.com/enterprise)[Docs](https://replicate.com/docs)[Blog](https://replicate.com/blog)[Sign in](https://replicate.com/signin)[Try for free](https://replicate.com/signin)
* * *
[Compare models in the Playground](https://replicate.com/playground)
* Replicate
* [Blog](https://replicate.com/blog)
# Run Stable Diffusion 3 with an API
Posted June 12, 2024 by
* [cbh123](https://replicate.com/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.
* * *
## [](https://replicate.com/blog/run-stable-diffusion-3-with-an-api#try-stable-diffusion-3-in-our-api-playground)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](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.
## [](https://replicate.com/blog/run-stable-diffusion-3-with-an-api#running-stable-diffusion-3-with-javascript)Running Stable Diffusion 3 with JavaScript
You can run Stable Diffusion 3 with our [official JavaScript client](https://github.com/replicate/replicate-javascript):
Install [Replicate’s Node.js client library](https://github.com/replicate/replicate-javascript)
Copy
`npm install replicate`
Set the `REPLICATE_API_TOKEN` environment variable
Copy
`export REPLICATE_API_TOKEN=r8_9wm**********************************`
(You can generate an [API token](https://replicate.com/account/api-tokens) 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](https://replicate.com/stability-ai/stable-diffusion-3/api/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](https://replicate.com/docs/get-started/nodejs).
## [](https://replicate.com/blog/run-stable-diffusion-3-with-an-api#running-stable-diffusion-3-with-python)Running Stable Diffusion 3 with Python
You can run Stable Diffusion 3 with our [official Python client](https://github.com/replicate/replicate-python):
Install [Replicate’s Python client library](https://github.com/replicate/replicate-python)
Copy
`pip install replicate`
Set the `REPLICATE_API_TOKEN` environment variable
Copy
`export REPLICATE_API_TOKEN=r8_9wm**********************************`
(You can generate an [API token](https://replicate.com/account/api-tokens) 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 th
DeepCamp AI