Elevate Your Applications with domashnixa/flux Image Generation Actions

24 Apr 2025
Elevate Your Applications with domashnixa/flux Image Generation Actions

In today's digital landscape, the ability to generate and manipulate images programmatically can unlock a plethora of creative possibilities for developers. The domashnixa/flux API offers a powerful set of Cognitive Actions designed for image generation and manipulation. Among these, the action "Generate Image with Mask and Inpainting" allows you to create stunning images based on text prompts, with options for inpainting and various inference models. By leveraging these pre-built actions, developers can enhance their applications with rich visual content effortlessly.

Prerequisites

Before you begin integrating the Cognitive Actions from the domashnixa/flux API, ensure you have the following:

  • An API key for the Cognitive Actions platform, which you will use for authentication.
  • Basic knowledge of handling HTTP requests in your programming language of choice.

Authentication typically involves passing your API key in the headers of your requests, ensuring secure access to the available actions.

Cognitive Actions Overview

Generate Image with Mask and Inpainting

The Generate Image with Mask and Inpainting action is designed to generate images based on a text prompt and can utilize an optional image mask for inpainting. This action supports reproducible results through the use of a seed and offers different models for inference, allowing you to choose between default and fast processing modes.

Input

The action accepts a variety of input parameters, detailed in the schema below:

{
  "prompt": "ultra realistic photo of man in army uniform",
  "mask": "uri_to_mask_image",
  "seed": 123456,
  "image": "uri_to_input_image",
  "width": 512,
  "height": 512,
  "goFast": false,
  "loraScale": 1,
  "guidanceScale": 3,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28,
  "safetyCheckerDisabled": false
}

Here’s a practical example of a JSON payload to invoke this action:

{
  "goFast": false,
  "prompt": "ultra realistic photo of man in army uniform",
  "loraScale": 1,
  "guidanceScale": 3,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "inferenceStepsCount": 28
}

Output

Upon successful execution, the action returns a URL pointing to the generated image. An example of this output is shown below:

[
  "https://assets.cognitiveactions.com/invocations/ddc9ed0f-8153-4345-a76d-151209b1bad6/09d4b967-df17-4cb2-b89c-1f66fa41e77d.webp"
]

This URL can be used to access the generated image directly.

Conceptual Usage Example (Python)

To integrate this action into your application, use the following conceptual Python code snippet:

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 = "45c4fcda-c5f2-45f2-bd87-1f66c981a7c3"  # Action ID for Generate Image with Mask and Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "ultra realistic photo of man in army uniform",
    "loraScale": 1,
    "guidanceScale": 3,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "numberOfOutputs": 1,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "additionalLoraScale": 1,
    "inferenceStepsCount": 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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Generate Image with Mask and Inpainting action. The input payload is structured according to the action's requirements and sent as part of the request.

Conclusion

By utilizing the domashnixa/flux Cognitive Actions, particularly the image generation capabilities, developers can create engaging visual content dynamically. Whether you are looking to generate images from text prompts or inpaint existing images, these actions provide a robust foundation for your applications. Explore different input configurations to find optimal settings for your needs, and consider how these powerful tools can enhance user experiences in your projects. Happy coding!