Skip to main content

Stable Diffusion 2

Navigate through the Stochastic Platform in the Model API side tab and select Stable Diffusion 2 model card.

Model card

You can now choose to use the model either by our Playground or API. You can choose the method by selecting the corresponding tab.

Use the Playground

In this page you can find a text box in which you can insert any prompt you would like the model to generate a image from. On the right side panel you can personalize supported hyperparameter values based on your preference. Finally press the Generate button to trigger a request. The output image will be shown in the central panel.

  • Inference steps: Results are better the more steps you use, however the more steps, the longer the generation takes.
  • Guidance scale: Recommended between 7 - 8.5, forces the generation to better match the prompt potentially at the cost of image quality or diversity (classifier-free guidance)
  • Seed: Can be set for reproducible sampling

Std1 Playground

Stochastic-x model API usage

To use the model API in your application there are two main steps


To use the model API you have to have a Stochastic account. Sign up for a free account.

In this step we have to submit a inference request to the ApiUrl to get the responseUrl and the queuePosition. Specification of request and response are mentioned below.

  • Request

    • Method : POST

    • Header : In the request header add a property called apiKey . (Get the apiKey form the Stochastic Platform)

    Use tab

    • Body : The request body can contain the following properties:

      • prompt: Required, the prompt for text generation or can be an Array of Strings
      • params: Required, Params for generation

      Here is an example for the request body:

      "prompt": "A step by step recipe to make bolognese pasta:",
      "params": {
      "max_length": 256,
      "min_length": 32,
      "top_k": 4,
      "penalty_alpha": 0.6
  • Response

    If the request is successful you will receive the responseUrl and the queuePosition

    "success": true,
    "data": {
    "id": "6389ce23460c900d80fa2290",
    "responseUrl": "",
    "queuePosition": "0"

Python example

Below you can find an example request with Python to get the generated images. Don't forget to add your API key in the example.

import requests
import time

response_step1 =
"apiKey": "your API key"
"prompt": "A turtle – swimming underwater, – expressionist painting.",
"params": {
"img_height": 512,
"img_width": 512,
"num_inference_steps": 50,
"guidance_scale": 7.5,
"seed": None

data_step1 = response_step1.json()["data"]

img_generated = False

while not img_generated:
response_step2 = requests.get(
"apiKey": "your API key"

data_step2 = response_step2.json()["data"]

generated_images = data_step2.get("generatedImages")

img_generated = generated_images is not None