Skip to content
English
  • There are no suggestions because the search field is empty.

Integrating Stability AI with n8n

This guide outlines how to integrate Stability AI’s image generation capabilities into your n8n workflows. While community nodes exist, the most reliable and flexible method is using n8n's native HTTP Request node. This ensures you can access the latest models (like Stable Image Core and Ultra) immediately upon release without waiting for node updates.


Prerequisites

Before configuring n8n, you must generate an API key from Stability AI.

  1. Create an Account: Log in to the Stability AI Platform.

  2. Get API Key: Navigate to the API Keys section in your account settings

  3. Copy Key: Create a new key and copy it immediately. You will need this for the n8n credentials.

    Note: Ensure your Stability AI Platform API account has sufficient credits. New accounts are granted 25 credits for testing.


Method: Using the HTTP Request Node (Recommended)

This method uses the standard REST API to interact with Stability AI. It is the preferred approach for production workflows.

Step 1: Add the HTTP Request Node

In your n8n canvas, add a new HTTP Request node.

Step 2: Configure Authentication

You should save your API Key securely rather than pasting it directly into the node.

  1. In the HTTP Request node, find Authentication.

  2. Select Generic Credential Type -> Header Auth.

  3. Create a new Credential:

    • Name: Header Auth - Stability AI (or similar).

    • Name: Authorization

    • Value: Bearer YOUR_API_KEY

    • Important: You must type the word "Bearer " followed by a space before pasting your key.

Step 3: Configure the Request

The configuration below uses the Stable Image Core endpoint (Text-to-Image) as an example.

  • Method: POST

  • URL: https://api.stability.ai/v2beta/stable-image/generate/core

  • Send Body: Toggle to On.

  • Body Content Type: Multipart-form-data 

  • Body Parameters:

    • Parameter 1:

      • Name: prompt

      • Value: (Enter your prompt, e.g., "A futuristic city with flying cars, cinematic lighting")

    • Parameter 2:

      • Name: output_format

      • Value: png (or jpeg, webp)

    • Parameter 3 (Optional):

      • Name: aspect_ratio

      • Value: 16:9

Step 4: Handle the Response (Important)

Stability AI can return the image directly as binary data, which is perfect for n8n.

  1. Scroll down to the Headers section in the HTTP Request node.

  2. Add a new Header:

    • Name: Accept

    • Value: image/*

  3. At the bottom of the node settings, look for Response Format.

  4. Change it from JSON to File.

  5. Put Output File in Field: data (or your preferred binary property name).

When you execute this node, it will output a binary file that you can immediately pass to other nodes (e.g., "Upload to Google Drive," "Send to Slack," or "AWS S3").


Advanced: Using JSON & Base64

If you prefer to receive JSON (for example, to get seed information along with the image), change the Accept header to application/json.

  • Response Format: Leave as JSON.

  • Result: The API will return a JSON object containing a base64 string.

  • Next Step: You will need to use a Code Node or Edit Image node to convert that base64 string back into a binary file for use in other nodes.


Common API Endpoints

Feature HTTP Method Endpoint URL Description
Generate (Core) POST .../v2beta/stable-image/generate/core Best for general text-to-image.
Generate (Ultra) POST .../v2beta/stable-image/generate/ultra High-fidelity, slower, more pricey.
Upscale POST .../v2beta/stable-image/upscale/conservative Increases resolution of existing images.
Erase POST .../v2beta/stable-image/edit/erase Removes objects from images.

Troubleshooting

1. Error: 401 Unauthorized

  • Cause: Invalid API Key or incorrect header format.

  • Fix: Check your Credential. Ensure the value is exactly Bearer sk-abcdefg... (don't forget the space).

2. Error: 400 Bad Request (Invalid Parameter)

  • Cause: You sent a parameter that doesn't exist or is formatted wrong (e.g., wrong aspect ratio string).

  • Fix: Check the Stability AI API Reference to ensure your field names (like aspect_ratio) match exactly.

3. Error: 402 Payment Required

4. "No Binary Data" in Output

  • Cause: You requested image/* but didn't set the n8n node Response Format to "File".

  • Fix: Set Response Format to File inside the HTTP Request node options.