Using Consistent Styles (--sref) with Midjourney API?

Posted on 2024/2/5 by GoAPI

Hi everyone!

As you might already know Midjourney has recently released the 'Style References' feature in an effort to achieve consistent styles across the generated images. This is a very useful feature for designers as they are often required to create images and picture assets with a particular set of style (for brand or a theme). As the Midjourney API from GoAPI already supports this feature, let's take a look how it would and the type of images we could achieve with Consistent Styles!

screenshot of David Holz's Discord message talking about the release for 'Consistent Style'
screenshot of the Discord message on 'Consistent Style'
Like always, we will use Postman to test out the API as it is free to use and requires no coding experience!

First, we will send a simple imagine API call with 'mountain scenery' as the prompt. Below is the cURL code snippet taken from Postman


  curl --location 'https://api.midjourneyapi.xyz/mj/v2/imagine' 
  --header 'X-API-Key: YOUR API KEY' 
  --header 'Content-Type: application/json' 
  --data '{
      "prompt": "mountain scenery",
      "skip_prompt_check": false,
      "process_mode": "fast",
      "aspect_ratio": "",
      "webhook_endpoint": "",
      "webhook_secret": ""
  }'
  

And below is the result that I get from Midjourney.

4 images of mountains in a 2x2 grid generated by Midjourney
Midjourney generated mountain images

And let's say I really like the acrylic style of the fourth image so I will do an upscale API call on it (below is the Postman cURL code snippet)


  curl --location 'https://api.midjourneyapi.xyz/mj/v2/upscale' 
  --header 'X-API-Key: YOUR API KEY' 
  --header 'Content-Type: application/json' 
  --data '{
      "origin_task_id": "enter the taskID of the previous mountain imagine task",
      "index": "4",
      "webhook_endpoint": "",
      "webhook_secret": ""
  }'
  
an enlarge image of the previously generated mountain image
an upcaled Midjourney mountain image

Now, let's say we want to create an image of a forest with a pond, with the similar acrylic style as the previous mountain image. We will use the '--sref' parameter for Style References in our new imagine prompt and append the previously obtained image url after the parameter as shown below. Also note that I am using a '--v 6' at the end of the prompt as currently the '--sref' parameter does not work with V5.2. Of course, this might change later.


  curl --location 'https://api.midjourneyapi.xyz/mj/v2/imagine' 
  --header 'X-API-Key: YOUR API KEY' 
  --header 'Content-Type: application/json' 
  --data '{
      "prompt": "a forest with a pond --sref https://img.midjourneyapi.xyz/mj/taskid.png --v 6",
      "skip_prompt_check": false,
      "process_mode": "fast",
      "aspect_ratio": "",
      "webhook_endpoint": "",
      "webhook_secret": ""
  }'
  

And when we fetch for the taskID of the imagine API call, we get the following images. As you can see, the acrylic style from the previous mountain image is kept with for this set of images as well. Style References is particularly useful when users want to create a new image following the theme of the previously generated images.

4 images of a forest with a pondin 2x2 grid generated by Midjourney with the same acrylic style as the previously generated mountain image
a forest with a pond image with style transfered from the previous mountain image

Now we can try multiple styles blended together in one prompt. Let's say I want to create a new paint with the following classic styles of

a classic expressionist painting of a man holding his head in surprise
a expressionism painint of a man
 a classic abstract art painting with geometric lines, shapes and vivid color
an Abstract Art style painting
a classic Mughal style painting drawing inspirations from Indian and Persian Styles
an Mughal Style Painting

Then I will use imgbb as the free service to upload these three images and to get a link to each of them.

Note that I will not be using link types not ending with jpg or png file format (Imgbb provides multiple types of links), I will only be using links ending with a jpg or png file format in my next imagine API call.

And now for my imagine API call, I will use a simple prompt 'a forest with a warrior riding away' with these three styles, each with a different weight. I have set the Mughal style with the highest weight of 20 as it is the most prevalent, and I have set the expressionist image style with 10 since we want to be able to see its effect in the output.


  curl --location 'https://api.midjourneyapi.xyz/mj/v2/imagine' 
  --header 'X-API-Key: YOUR API KEY' 
  --header 'Content-Type: application/json' 
  --data '{
      "prompt": "a forest with a warrior riding away --sref expressionist_image_url::10 
      abstract_art_url::5 Mughal_style_painting_url::20 --v 6",
      "skip_prompt_check": false,
      "process_mode": "fast",
      "aspect_ratio": "",
      "webhook_endpoint": "",
      "webhook_secret": ""
  }
  
4 images of a warrior riding in a forest in a 2x2 grid with Mughal Style, Expressionist style and Abstract Art style transferred
the generated image of a warrior riding in a forest

And voila! In the outputs we can see bits and pieces of the reddish color from the expressionims painting, the human warrior are painting with a slight Mughal style, and the lines and geometric shapes from the Abstract Art Painting. It is not perfect nor an exact science, but with trials and errors I am sure we will all get a better hang of it!

And that is it for our tutorial on how to use the Style Reference parameter to achieve Consistent Styles with Midjourney API!

Happy tinkering guys!