In this recipe we'll step through the process to add AI image generation to Rock RMS using a workflow. This is a fairly simple workflow that sends an API call to Stability AI which is the same system used in DreamStudio.

This recipe is a starting point to show how AI image generation is possible. In the future the recipe will be updated to improve the interface and add functionality to allow upscaling and image variation. Images are currently stored as base64 in the database as a workflow attribute, but updates could be made to store the images in a cloud storage provider.

Step 1 : Set Up Stability AI Account

Step 2: Import The Workflow Into Rock

Head over to [YourAdminSite]/admin/power-tools/workflow-import and import the attached workflow. The workflow can also be accessed and downloaded from Github here. Or download the workflow using the button at the bottom of this page. You can find more details about importing a workflow into Rock here.

Step 3: Secure your Workflow

Since the workflow will allow access to using your API key I would recommend securing the workflow to only be accessible to a specific group of people that you are comfortable spending tokens.

Navigate to the imported workflow and click the padlock to set security.

Step 3: Add API Key to Workflow

  • Navigate to the imported workflow and click "Edit".

  • Find the Action named Send Request to Stability and add your API Key into the first line, replacing the text PLACEAPIKEYHERE and then save your workflow.

  • Save the workflow.

Step 4: Run The Workflow

Run the workflow and create your first image!

At the time that this recipe was published Stability provides new accounts with 25 free credits which is enough to create about 10 images. Further credits can be purchased at and the overall cost of creating images works out to about 2.5 cents per image.

Step 5: Securing Your API Key (Optional)

If you would prefer to not store your API Key in the workflow is it possible to store this key in a secured Global attribute instead. I'll detail the method of configuring that attribute and then adding the code to the shortcode to access the attribute value. Special thanks Leah Jennings, Kevin Rutledge and Michael Allen in the RocketChat #API channel for the insights on how to best implement this.

  1. Navigate to [YourInternalApplicationRoot]/admin/general/global-attributes

  2. Click the "+" Sign at the top right of the list to add a new attribute

  3. Configure the attribute as shown below and click Save. Critical field are listed below.

    • Field Type: Encrypted Text

    • Password Field: True

  1. Secure the attribute by clicking the Padlock next to the new attribute and setting the View permissions to Rock Admins only.

  1. Click on the attribute and enter your OpenAI Key into the password protected field.

  2. Copy the Attribute Id shown on the far left (Highlighted above)

  3. Return to your shortcode and replace the {%- assign key = 'YOURAPIKEYPLACEAPIKEYHERE' %} code with:

{%- attributevalue where:'AttributeId == YOURATTRIBUTEID' limit:'1' securityenabled:'false' -%}
    {%- assign key = attributevalue.Value | Decrypt  -%}
{%- endattributevalue -%}
  1. Ensure that 'Rock Entity' is checked in your Enabled Lava Commands in the Lava Run action.

The attribute is now stored in an encrypted attribute that can only be accessed by Rock Admins or those with the ability to run entity calls.