Generate Stunning Images with the asiryan/flux-dev Cognitive Actions

21 Apr 2025
Generate Stunning Images with the asiryan/flux-dev Cognitive Actions

Integrating advanced image generation capabilities into applications has never been easier with the asiryan/flux-dev Cognitive Actions. These pre-built actions allow developers to harness the power of the FLUX Dev Model, enabling the creation of images from text prompts and modifications of existing images. Whether you're building an art application, a marketing tool, or a creative project, these actions offer the flexibility and quality needed to deliver impressive results.

Prerequisites

Before you start using the Cognitive Actions from the asiryan/flux-dev spec, you'll need a few things:

  • An API key to authenticate your requests to the Cognitive Actions platform.
  • Basic knowledge of JSON structure to construct requests and handle responses.

For authentication, you will typically pass your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image with FLUX Dev Model

The Generate Image with FLUX Dev Model action allows you to create images based on text prompts (Text2Img) or modify existing images (Img2Img). This action provides extensive control over various parameters like output dimensions, format, quality, and adherence to guidance prompts to ensure high-quality outcomes.

Input

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

{
  "seed": 15454,
  "width": 1024,
  "height": 1024,
  "prompt": "A woman in a black spider-man costume, white hair, light brown eyes almost yellow",
  "outputFormat": "png",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 28
}
  • seed: integer (Optional) - A random seed for reproducible results (Example: 15454).
  • image: string (Optional) - URI of the input image for Img2Img mode.
  • width: integer (Default: 1024) - Width of the output image in pixels.
  • height: integer (Default: 1024) - Height of the output image in pixels.
  • prompt: string (Default: "a tiny astronaut hatching from an egg on the moon") - Descriptive text guiding image generation.
  • strength: number (Default: 0.8) - Strength of the prompt in Img2Img mode (0 to 1).
  • outputFormat: string (Default: "png") - Format of the output image (webp, jpg, png).
  • guidanceScale: number (Default: 3.5) - Adherence to the guidance prompt (0 to 10).
  • outputQuality: integer (Default: 100) - Quality of the output image (0 to 100 for jpg and webp).
  • numberOfOutputs: integer (Default: 1) - Number of images to generate (1 to 4).
  • numberOfInferenceSteps: integer (Default: 28) - Steps in the inference process (1 to 100).

Output

The output of this action typically returns a JSON array with URLs of the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/061c7acf-4b6d-40ef-9802-cfa164bf2429/c5380bdd-e274-4196-80cb-f19e42cfd62d.png"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with FLUX Dev 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 = "b5aee633-d57e-41aa-bf29-c0bd56eb5897"  # Action ID for Generate Image with FLUX Dev Model

# Construct the input payload based on the action's requirements
payload = {
    "seed": 15454,
    "width": 1024,
    "height": 1024,
    "prompt": "A woman in a black spider-man costume, white hair, light brown eyes almost yellow",
    "outputFormat": "png",
    "guidanceScale": 3.5,
    "outputQuality": 100,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 28
}

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 code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id variable holds the ID for the image generation action, and the payload variable is structured according to the required input schema. This example showcases how to send a request and handle the response effectively.

Conclusion

The asiryan/flux-dev Cognitive Actions empower developers to create and manipulate images with remarkable ease and quality. By leveraging the robust capabilities of the FLUX Dev Model, your applications can generate stunning visuals based on user input, enhancing user engagement and creativity. Explore the possibilities and start integrating these actions into your projects today!