Elevate Your Image Creation with andreasjansson/flux-me Cognitive Actions

21 Apr 2025
Elevate Your Image Creation with andreasjansson/flux-me Cognitive Actions

In the rapidly evolving world of digital content creation, the ability to generate high-quality images on demand is a game-changer. The andreasjansson/flux-me API provides a powerful set of Cognitive Actions designed for developers looking to harness advanced image generation capabilities. With features such as customizable prompts, aspect ratios, and image quality settings, these actions enable you to automate and enhance your creative workflows.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key to access the Cognitive Actions platform.
  • Basic knowledge of JSON and RESTful APIs.
  • A development environment set up for making HTTP requests (e.g., Python with requests library).

Authentication typically involves passing your API key in the headers of your requests, allowing you to securely access the available actions.

Cognitive Actions Overview

Generate Enhanced Images

The Generate Enhanced Images action allows you to create high-quality, customizable images using advanced models. It supports various settings, including inpainting, aspect ratios, and guidance scaling, allowing developers to optimize for speed or quality based on specific project needs.

Input

The input schema for this action includes several properties:

  • prompt (required): A textual description guiding image generation.
  • mask: URI of the image mask for inpainting mode.
  • seed: Random seed value for reproducible generation.
  • image: URI for image-to-image conversion.
  • model: Model to use for inference (options are "dev" and "schnell").
  • width and height: Dimensions of the generated image, applicable if aspect ratio is set to 'custom'.
  • aspectRatio: Determines the aspect ratio of the generated image.
  • numberOfOutputs: Specifies how many images to generate (maximum of 4).
  • imageOutputFormat: Output formats supported are 'webp', 'jpg', and 'png'.
  • imageOutputQuality: Quality level for saved output images.
  • guidanceScale: Influences the realism of the generated image.
  • enableFastMode: Optimizes for speed with accelerated predictions.
  • Other optional fields include loraWeights, promptStrength, disableSafetyChecker, among others.
Example Input
{
  "model": "dev",
  "prompt": "ANDRS, A selfie photo of a man ANDRS on Mars",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "guidanceScale": 3.5,
  "numberOfOutputs": 1,
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "additionalLoraScale": 0.8,
  "numberOfInferenceSteps": 28
}

Output

Upon successful execution, the action returns an array of URLs pointing to the generated images.

Example Output
[
  "https://assets.cognitiveactions.com/invocations/1edfac28-c78a-4a09-8a67-1cd6881ac630/34893d57-a376-4f1d-ba09-13b7cb0b692a.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to invoke the Generate Enhanced Images action:

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 = "733995cd-379e-4599-a3ea-590d7bf9bd18"  # Action ID for Generate Enhanced Images

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "ANDRS, A selfie photo of a man ANDRS on Mars",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "guidanceScale": 3.5,
    "numberOfOutputs": 1,
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "additionalLoraScale": 0.8,
    "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 snippet, you fill in your API key and target the appropriate action ID. The payload is structured according to the input schema, ensuring that all required fields are included. The response will contain URLs to the generated images.

Conclusion

The andreasjansson/flux-me Cognitive Actions offer developers an exceptional opportunity to enhance image generation capabilities within their applications. By leveraging the Generate Enhanced Images action, you can create customized and high-quality images suited for a variety of use cases. Explore the possibilities and integrate these powerful tools into your projects to elevate your content creation process!