Enhance Your Images with FLUX Fill Pro: A Developer's Guide to Cognitive Actions

25 Apr 2025
Enhance Your Images with FLUX Fill Pro: A Developer's Guide to Cognitive Actions

In the world of digital content creation, the ability to manipulate images seamlessly is invaluable. The black-forest-labs/flux-fill-pro API offers a powerful toolset for developers through its Cognitive Actions, particularly focused on image inpainting and outpainting. These pre-built actions simplify complex image editing tasks, allowing you to remove unwanted elements, add new features, or expand images while maintaining their original context.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which you will use for authentication.
  • Familiarity with JSON structure, as the input and output of these actions are formatted in JSON.

Authentication typically involves passing your API key in the request headers, ensuring that your application can securely access the Cognitive Actions services.

Cognitive Actions Overview

Perform Image Inpainting and Outpainting with FLUX.1

This action utilizes the FLUX.1 Fill pro model, enabling advanced image editing capabilities. With this action, you can achieve seamless object removal, addition of new elements, or canvas expansion while keeping the lighting and perspective intact.

Input

The input for this action is structured as follows:

  • image (required): The input image to be inpainted (accepted formats: jpeg, png, gif, webp).
  • prompt (required): A descriptive text prompt to guide the image generation process.
  • mask (optional): A black-and-white mask image indicating which areas to inpaint.
  • steps (optional): The number of diffusion steps to apply (default: 50, range: 15 to 50).
  • guidance (optional): A number that adjusts the balance between prompt adherence and image quality/diversity (default: 60, range: 1.5 to 100).
  • outpaintOption (optional): Specifies how to outpaint the image (default: "None").
  • outputImageFormat (optional): The format of the output image (default: "jpg").
  • imageSafetyTolerance (optional): Controls the strictness of safety measures (default: 2, range: 1 to 6).
  • modifyPromptForCreativity (optional): Enables automatic modifications to the prompt for creative generation (default: false).

Here’s an example of the JSON payload you would send to this action:

{
  "mask": "https://replicate.delivery/pbxt/M0gpLCYdCLbnhcz95Poy66q30XW9VSCN65DoDQ8IzdzlQonw/kill-bill-mask.png",
  "image": "https://replicate.delivery/pbxt/M0gpKVE9wmEtOQFNDOpwz1uGs0u6nK2NcE85IihwlN0ZEnMF/kill-bill-poster.jpg",
  "steps": 50,
  "prompt": "movie poster says \"FLUX FILL\"",
  "guidance": 60,
  "outpaintOption": "None",
  "outputImageFormat": "jpg",
  "imageSafetyTolerance": 2,
  "modifyPromptForCreativity": false
}

Output

The action returns a URL to the generated output image, which may look something like this:

https://assets.cognitiveactions.com/invocations/e18dcd2c-4e28-4340-879a-6f82d717fd2f/812c0a6b-5663-4d08-8e52-ac61fd8d4eef.jpg

Conceptual Usage Example (Python)

Here’s how you might structure your call to this action using Python. This code snippet demonstrates sending a request to the Cognitive Actions execution endpoint with the appropriate input payload.

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 = "a5e2c16e-8a06-42ce-b4df-caf9ef10c856" # Action ID for Perform Image Inpainting and Outpainting with FLUX.1

# Construct the input payload based on the action's requirements
payload = {
    "mask": "https://replicate.delivery/pbxt/M0gpLCYdCLbnhcz95Poy66q30XW9VSCN65DoDQ8IzdzlQonw/kill-bill-mask.png",
    "image": "https://replicate.delivery/pbxt/M0gpKVE9wmEtOQFNDOpwz1uGs0u6nK2NcE85IihwlN0ZEnMF/kill-bill-poster.jpg",
    "steps": 50,
    "prompt": "movie poster says \"FLUX FILL\"",
    "guidance": 60,
    "outpaintOption": "None",
    "outputImageFormat": "jpg",
    "imageSafetyTolerance": 2,
    "modifyPromptForCreativity": False
}

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, you replace the COGNITIVE_ACTIONS_API_KEY with your actual API key and structure the input payload as shown. The code sends a POST request to the hypothetical execution endpoint, and upon success, prints the resulting image URL or an error message if the request fails.

Conclusion

The FLUX Fill Pro Cognitive Action provides developers with powerful tools for advanced image manipulation. By integrating this functionality into your applications, you can enhance user experience through seamless image editing capabilities. Consider exploring further use cases, such as automated graphic design or content generation, to fully leverage the potential of these Cognitive Actions. Happy coding!