Enhance Your Images with SDXL Inpainting Cognitive Actions

24 Apr 2025
Enhance Your Images with SDXL Inpainting Cognitive Actions

In the realm of image processing, the ability to modify and enhance images based on contextual prompts is invaluable. The subscriptions10x/sdxl-inpainting API offers a powerful Cognitive Action called Perform Image Inpainting. This action allows developers to fill in specified areas of an image using a mask and a guiding text prompt, leveraging the advanced capabilities of the SDXL model to create precise and context-aware enhancements.

Prerequisites

Before you can use the Cognitive Actions, you'll need to ensure you have the following:

  • API Key: You'll need an API key to authenticate your requests to the Cognitive Actions platform.
  • Basic Setup: Familiarity with sending HTTP requests in your programming language of choice.

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

Cognitive Actions Overview

Perform Image Inpainting

The Perform Image Inpainting action enables you to execute an image inpainting operation. By providing an input image, a mask image, and a descriptive text prompt, the action predicts and fills in the specified areas, resulting in a modified image that aligns with your specifications.

  • Category: Image Processing
  • Purpose: To enhance images by filling specific areas based on user-defined prompts.

Input

The action requires the following parameters in a JSON format:

  • image: (string) The URI of the input image. This image serves as the base for processing.
  • maskImage: (string) The URI of the mask image, representing the areas to be filled in white (RGB format).
  • prompt: (string) A text prompt that guides the model's output.
  • seed: (integer, optional) An integer value used to initialize the random number generator for reproducibility.
  • negativePrompt: (string, optional) A prompt that instructs the model on aspects to avoid in its output.

Example Input:

{
  "image": "https://replicate.delivery/pbxt/JTvN42RZrXZYc1ud4J1cCD1VQMJnENdRz4AGZ3XjiK4Lxpsg/9a0a1b126a676fb498f81da99c8dffe894ebfe28.png",
  "maskImage": "https://replicate.delivery/pbxt/JTvN4KptGqnSDtv3vaeiuMrNoODjUbgSbymY2wK7RFvcXxM1/465174ce5fa1120c42d2885789ebba0a2386d14d.png",
  "prompt": "modern bed with beige sheet and pillows"
}

Output

Upon successful execution, the action returns a URI to the modified image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/1a3397ad-ed09-4807-9f8d-8fedcf3d2285/d5c62dcc-fe3a-4db7-b3e0-4419bc2b6334.png"
]

Conceptual Usage Example (Python)

Here’s how you might structure your code to invoke the Perform Image Inpainting 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 = "7e26668a-f57f-4f11-b3c9-7741eb50576c"  # Action ID for Perform Image Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/JTvN42RZrXZYc1ud4J1cCD1VQMJnENdRz4AGZ3XjiK4Lxpsg/9a0a1b126a676fb498f81da99c8dffe894ebfe28.png",
    "maskImage": "https://replicate.delivery/pbxt/JTvN4KptGqnSDtv3vaeiuMrNoODjUbgSbymY2wK7RFvcXxM1/465174ce5fa1120c42d2885789ebba0a2386d14d.png",
    "prompt": "modern bed with beige sheet and pillows"
}

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 Perform Image Inpainting action, while the payload is constructed using the required input fields.

Conclusion

The Perform Image Inpainting action from the subscriptions10x/sdxl-inpainting API provides a powerful way to enhance images by filling specified areas based on contextual prompts. By leveraging this Cognitive Action, developers can create more engaging and visually appealing content in their applications. Start experimenting with inpainting today and unlock new creative possibilities for your images!