Transform Your Images with the FLUX.1 Fill Action in Cognitive Actions

21 Apr 2025
Transform Your Images with the FLUX.1 Fill Action in Cognitive Actions

Cognitive Actions from the black-forest-labs/flux-fill-dev specification provides developers with powerful tools to manipulate and enhance images using advanced inpainting techniques. Among the various actions available, the FLUX.1 Fill action stands out for its ability to edit and extend images in a professional-quality manner. By utilizing this action, developers can seamlessly paint over parts of an image, specify what should appear in those areas, and achieve natural-looking results that retain the original context.

Prerequisites

Before integrating the FLUX.1 Fill action into your application, ensure you have the following prerequisites:

  • An API key for the Cognitive Actions platform, which you will use for authentication.
  • Basic familiarity with making HTTP requests and handling JSON data.

Authentication typically involves passing your API key in the headers of your requests.

Cognitive Actions Overview

Edit and Extend Image with FLUX.1 Fill

The Edit and Extend Image with FLUX.1 Fill action allows users to perform professional-quality inpainting on images. This action is especially useful for modifying images by filling in specific areas based on textual prompts.

  • Category: Image Processing

Input

The input for this action requires specific fields to guide the inpainting process. Below is a detailed schema along with an example input.

Required Fields:
  • image (string): The image that needs to be inpainted. It can include an alpha mask.
  • prompt (string): A textual description that guides the generation of the image.
Optional Fields:
  • mask (string): A black-and-white image specifying the area for inpainting (black areas preserved, white areas inpainted).
  • seed (integer): A seed for reproducibly generating images.
  • guidance (number): Controls adherence to the prompt (0 to 100).
  • megapixels (string): Specifies the approximate number of megapixels for the output image.
  • imageFormat (string): The output image format (webp, jpg, png).
  • outputCount (integer): The number of outputs to generate (1 to 4).
  • imageQuality (integer): The quality of the output image (0 to 100).
  • inferenceStepCount (integer): Number of denoising steps for generation (1 to 50).
  • additionalWeights (string): Allows loading of LoRA weights.
  • omitSafetyChecker (boolean): Enables or disables the safety checker during generation.
Example Input:
{
  "mask": "https://replicate.delivery/pbxt/M0hxLu8a1YBcybWuumSsfoEec8ooer6JZ2fR28vuM1U0CN9m/74b40bb1-364a-461a-bec5-200a38c7bc87.png",
  "image": "https://replicate.delivery/pbxt/M0hxMJeO7wFCMr7QYNZsjRxzHhz6ntlLllMteRQNsRD7f3Nf/flux-fill-dev.webp",
  "prompt": "a spaceship",
  "guidance": 30,
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 80,
  "inferenceStepCount": 28
}

Output

The action typically returns an array of URLs pointing to the generated images. Each URL corresponds to one of the output images based on the specified parameters.

Example Output:
[
  "https://assets.cognitiveactions.com/invocations/d8f44c03-0649-4d6a-83f5-a8870257115c/5cc5fe92-7e53-48b4-80a0-a47cc4d5786e.webp"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how developers can invoke the FLUX.1 Fill 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 = "6507e255-27bd-4542-a366-185e2f41cbb0"  # Action ID for Edit and Extend Image with FLUX.1 Fill

# Construct the input payload based on the action's requirements
payload = {
    "mask": "https://replicate.delivery/pbxt/M0hxLu8a1YBcybWuumSsfoEec8ooer6JZ2fR28vuM1U0CN9m/74b40bb1-364a-461a-bec5-200a38c7bc87.png",
    "image": "https://replicate.delivery/pbxt/M0hxMJeO7wFCMr7QYNZsjRxzHhz6ntlLllMteRQNsRD7f3Nf/flux-fill-dev.webp",
    "prompt": "a spaceship",
    "guidance": 30,
    "imageFormat": "webp",
    "outputCount": 1,
    "imageQuality": 80,
    "inferenceStepCount": 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:

  • The action_id is set to the identifier for the FLUX.1 Fill action.
  • The payload is constructed using the required and optional fields as specified.
  • The API request is made with proper headers, and the response is handled to display the result or any errors encountered.

Conclusion

The FLUX.1 Fill action within the black-forest-labs/flux-fill-dev specification provides developers with a powerful tool for image editing and enhancement. By leveraging this action, you can create high-quality inpainted images that meet your application's needs. Consider exploring additional use cases such as creative content generation, digital art enhancements, or automated image editing to take full advantage of this capability. Happy coding!