Transform Your Images with the brettimus/sdxl-lkl Cognitive Actions

23 Apr 2025
Transform Your Images with the brettimus/sdxl-lkl Cognitive Actions

In the realm of artificial intelligence, image generation techniques have evolved rapidly, allowing developers to create stunning visuals from simple textual prompts. The brettimus/sdxl-lkl Cognitive Actions API provides powerful tools for generating images, particularly through inpainting techniques. These pre-built actions allow you to seamlessly integrate sophisticated image generation capabilities into your applications, enhancing creative workflows and automating content creation.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic understanding of how to make HTTP requests.
  • A Python environment set up to test the provided code snippets.

For authentication, you will generally pass your API key within the headers of your requests.

Cognitive Actions Overview

Generate Image with Inpainting

Description:
This action allows you to generate an image using inpainting techniques guided by textual prompts. It supports img2img transformations, enabling you to manipulate existing images with configurable dimensions, prompt strength, and refinement styles.

Category: image-generation

Input

The input for this action is structured as follows:

{
  "mask": "uri_to_mask_image",
  "seed": 12345,
  "image": "uri_to_input_image",
  "width": 512,
  "height": 512,
  "prompt": "A beautiful sunset over a mountain range",
  "loraScale": 0.6,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "imageScheduler": "K_EULER",
  "negativePrompt": "people, cars",
  "promptStrength": 0.8,
  "outputImageCount": 1,
  "watermarkApplied": true,
  "highNoiseFraction": 0.8,
  "inferenceStepCount": 50
}

Key Fields:

  • mask: A URI to the mask image for inpainting. Black areas stay unchanged while white areas are modified.
  • seed: An optional integer for random seed variations.
  • image: A URI to the base image for img2img transformations.
  • width/height: Dimensions of the output image in pixels (default is 1024x1024).
  • prompt: The guiding text for the image generation.
  • outputImageCount: Number of images to generate (1 to 4).

Example Input

Here’s an example of the input JSON payload:

{
  "width": 512,
  "height": 512,
  "prompt": "a oil painting portrait of an old wet chubby short hair TOK dog golden retriever in a scenic environment at night by mary beale and rembrandt, royal, noble, baroque art, dark background, candlelight",
  "loraScale": 0.78,
  "refineStyle": "expert_ensemble_refiner",
  "guidanceScale": 7.5,
  "imageScheduler": "K_EULER",
  "negativePrompt": "human, overexposed",
  "promptStrength": 0.8,
  "outputImageCount": 4,
  "watermarkApplied": true,
  "highNoiseFraction": 0.9,
  "inferenceStepCount": 53
}

Output

The action typically returns an array of URLs pointing to the generated images, as demonstrated below:

[
  "https://assets.cognitiveactions.com/invocations/07643fc1-be0e-4166-b723-47d344dc8fec/909a87ea-f822-49d0-9093-e35a2d5673c4.png",
  "https://assets.cognitiveactions.com/invocations/07643fc1-be0e-4166-b723-47d344dc8fec/5b374e1f-d717-450d-b2e0-7a4102c29fb0.png",
  "https://assets.cognitiveactions.com/invocations/07643fc1-be0e-4166-b723-47d344dc8fec/89f15e97-c4ad-4c7d-82af-b24d7685db60.png",
  "https://assets.cognitiveactions.com/invocations/07643fc1-be0e-4166-b723-47d344dc8fec/d33d2455-2086-4817-aa15-235d23cb67b9.png"
]

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet that demonstrates how to call this 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 = "78ef9213-8c58-4cc5-82cc-ea54e584d05d"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 512,
    "height": 512,
    "prompt": "a oil painting portrait of an old wet chubby short hair TOK dog golden retriever in a scenic environment at night by mary beale and rembrandt, royal, noble, baroque art, dark background, candlelight",
    "loraScale": 0.78,
    "refineStyle": "expert_ensemble_refiner",
    "guidanceScale": 7.5,
    "imageScheduler": "K_EULER",
    "negativePrompt": "human, overexposed",
    "promptStrength": 0.8,
    "outputImageCount": 4,
    "watermarkApplied": true,
    "highNoiseFraction": 0.9,
    "inferenceStepCount": 53
}

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, replace the placeholders with your API key and adjust the input payload as needed. The action_id corresponds to the specific action you wish to execute. The response will include URLs to the generated images based on the specified parameters.

Conclusion

The brettimus/sdxl-lkl Cognitive Actions empower developers with the ability to generate unique images through intelligent inpainting techniques. By utilizing the provided action, you can create visually compelling content tailored to your needs, whether for artistic projects, marketing materials, or other creative applications. Start experimenting with these actions today to unlock a new dimension of image generation in your applications!