Generate Stunning Images with Flux Redux Layers Cognitive Actions

22 Apr 2025
Generate Stunning Images with Flux Redux Layers Cognitive Actions

In today's world, the ability to generate high-quality images from textual prompts has become increasingly valuable for developers and creatives alike. The andreasjansson/flux-schnell-redux-layers API provides a powerful Cognitive Action called "Generate Image with Flux Redux Model". This action allows you to create visually appealing images based on user-defined prompts or existing images, offering extensive customization options, including quality, aspect ratio, and more.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of making API calls using tools like Python.
  • Familiarity with JSON format for structuring input and output data.

Authentication typically involves passing your API key in the request headers.

Cognitive Actions Overview

Generate Image with Flux Redux Model

Description: This action generates high-quality images based on a textual prompt or a redux input image using the FLUX.1 Redux model. It allows for customization of various image properties, ensuring reproducibility and control over output layers.

Category: Image Generation

Input

The input schema for this action requires a JSON object with the following fields:

  • prompt (required): A string that guides the image generation. For example, "A watercolor painting".
  • seed (optional): An integer for reproducibility.
  • aspectRatio (optional): Aspect ratio for the generated image, defaulting to "1:1".
  • outputFormat (optional): The file format for output images, defaulting to "webp".
  • outputQuality (optional): An integer from 0 to 100 representing the quality of the output images, defaulting to 80.
  • numberOfOutputs (optional): Specifies the number of images to generate, defaulting to 1, with a maximum of 4.
  • conditionInputImage (optional): A URL for an input image to condition the output.
  • disableSafetyChecker (optional): A boolean to disable the safety checker (default is false).
  • approximateMegapixels (optional): Approximate resolution in megapixels, defaulting to "1".
  • numberOfDenoisingSteps (optional): Integer indicating the steps for refining image quality, default is 4.
  • doubleStreamBlockLayers (optional): Array of integers specifying indexes for double stream block layers.
  • singleStreamBlockLayers (optional): Array of integers specifying indexes for single stream block layers.

Example Input:

{
  "prompt": "A watercolor painting",
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "outputQuality": 80,
  "numberOfOutputs": 4,
  "conditionInputImage": "https://replicate.delivery/pbxt/M1lKeCcsHPvzb5wNNsajPvKD4l87ESgJv0a6EmEWzHl9QUdk/0_1.webp",
  "approximateMegapixels": "1",
  "numberOfDenoisingSteps": 4,
  "doubleStreamBlockLayers": [18],
  "singleStreamBlockLayers": [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37]
}

Output

The action returns an array of URLs pointing to the generated images. Here is an example output:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/06a44a8a-7fe3-4dc5-b7c9-60a6ebfa4f82/de4e6aea-0019-4c92-8940-aa1e600a5128.webp",
  "https://assets.cognitiveactions.com/invocations/06a44a8a-7fe3-4dc5-b7c9-60a6ebfa4f82/710566ea-0649-4089-94d9-aeddb27e059b.webp",
  "https://assets.cognitiveactions.com/invocations/06a44a8a-7fe3-4dc5-b7c9-60a6ebfa4f82/fd3302db-685a-4039-aa1e-724b3ce2b942.webp",
  "https://assets.cognitiveactions.com/invocations/06a44a8a-7fe3-4dc5-b7c9-60a6ebfa4f82/1268e4d1-6f53-4537-b2d5-19b1bfabefe6.webp"
]

Conceptual Usage Example (Python)

Here’s how you can invoke the "Generate Image with Flux Redux Model" action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "13513a78-1ac6-44da-8c81-d99b19c68ea3"  # Action ID for Generate Image with Flux Redux Model

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "A watercolor painting",
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "outputQuality": 80,
    "numberOfOutputs": 4,
    "conditionInputImage": "https://replicate.delivery/pbxt/M1lKeCcsHPvzb5wNNsajPvKD4l87ESgJv0a6EmEWzHl9QUdk/0_1.webp",
    "approximateMegapixels": "1",
    "numberOfDenoisingSteps": 4,
    "doubleStreamBlockLayers": [18],
    "singleStreamBlockLayers": [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37]
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this Python code snippet, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action ID is set to the ID of the "Generate Image with Flux Redux Model" action, and the payload is constructed according to the required input schema. The endpoint URL and request structure are illustrative and should be adjusted to match the actual implementation details.

Conclusion

The Generate Image with Flux Redux Model Cognitive Action empowers developers to create high-quality images programmatically. With extensive customization options and the ability to condition outputs with input images, this action opens up new avenues for creativity and automation in image generation. Start integrating this action into your applications to enhance user experience and explore innovative use cases in graphics and design!